public class LineSegment extends Objectimplements Comparable , Serializable
Coordinates. Provides methods to compute various geometric properties and relationships of line segments.
This class is designed to be easily mutable (to the extent of having its contained points public). This supports a common pattern of reusing a single LineSegment object as a way of computing segment properties on the segments defined by arrays or lists of Coordinates.
| Modifier and Type | Field and Description |
|---|---|
Coordinate |
p0
|
Coordinate |
p1
|
| Constructor and Description |
|---|
LineSegment()
|
LineSegment(Coordinate
|
LineSegment(double x0, double y0, double x1, double y1)
|
LineSegment(LineSegment
|
| Modifier and Type | Method and Description |
|---|---|
double |
angle()
Computes the angle that the vector defined by this segment makes with the X-axis.
|
Coordinate |
closestPoint(Coordinate
Computes the closest point on this line segment to another point.
|
Coordinate |
closestPoints(LineSegment
Computes the closest points on two line segments.
|
int |
compareTo(Object
Compares this object with the specified object for order.
|
double |
distance(Coordinate
Computes the distance between this line segment and a given point.
|
double |
distance(LineSegment
Computes the distance between this line segment and another segment.
|
double |
distancePerpendicular(Coordinate
Computes the perpendicular distance between the (infinite) line defined by this line segment and a point.
|
boolean |
equals(Object
Returns
true if
other has the same values for its points.
|
boolean |
equalsTopo(LineSegment
Returns
true if
other is topologically equal to this LineSegment (e.g.
|
Coordinate |
getCoordinate(int i)
|
double |
getLength()
Computes the length of the line segment.
|
int |
hashCode()
Gets a hashcode for this object.
|
Coordinate |
intersection(LineSegment
Computes an intersection point between two line segments, if there is one.
|
boolean |
isHorizontal()
Tests whether the segment is horizontal.
|
boolean |
isVertical()
Tests whether the segment is vertical.
|
Coordinate |
lineIntersection(LineSegment
Computes the intersection point of the lines of infinite extent defined by two line segments (if there is one).
|
Coordinate |
midPoint()
Computes the midpoint of the segment
|
static Coordinate |
midPoint(Coordinate
Computes the midpoint of a segment
|
void |
normalize()
Puts the line segment into a normalized form.
|
int |
orientationIndex(Coordinate
Determines the orientation index of a
Coordinate relative to this segment.
|
int |
orientationIndex(LineSegment
Determines the orientation of a LineSegment relative to this segment.
|
Coordinate |
pointAlong(double segmentLengthFraction)
Computes the
Coordinate that lies a given fraction along the line defined by this segment.
|
Coordinate |
pointAlongOffset(double segmentLengthFraction, double offsetDistance)
Computes the
Coordinate that lies a given fraction along the line defined by this segment and offset from the segment by a given distance.
|
Coordinate |
project(Coordinate
Compute the projection of a point onto the line determined by this line segment.
|
LineSegment |
project(LineSegment
Project a line segment onto this line segment and return the resulting line segment.
|
double |
projectionFactor(Coordinate
Computes the Projection Factor for the projection of the point p onto this LineSegment.
|
void |
reverse()
Reverses the direction of the line segment.
|
double |
segmentFraction(Coordinate
Computes the fraction of distance (in
[0.0, 1.0]) that the projection of a point occurs along this line segment.
|
void |
setCoordinates(Coordinate
|
void |
setCoordinates(LineSegment
|
LineString |
toGeometry(GeometryFactory
Creates a LineString with the same coordinates as this segment
|
String |
toString()
|
public Coordinatep0
public Coordinatep1
public LineSegment(Coordinatep0, Coordinate p1)
public LineSegment(double x0,
double y0,
double x1,
double y1)public LineSegment(LineSegmentls)
public LineSegment()
public CoordinategetCoordinate(int i)
public void setCoordinates(LineSegmentls)
public void setCoordinates(Coordinatep0, Coordinate p1)
public double getLength()
public boolean isHorizontal()
true if the segment is horizontal
public boolean isVertical()
true if the segment is vertical
public int orientationIndex(LineSegmentseg)
seg - the LineSegment to compare
seg is to the left of this segment
public int orientationIndex(Coordinatep)
Coordinate relative to this segment. The orientation index is as defined in
CGAlgorithms.computeOrientation(com.vividsolutions.jts.geom.Coordinate, com.vividsolutions.jts.geom.Coordinate, com.vividsolutions.jts.geom.Coordinate) .
p - the coordinate to compare
p is to the left of this segment
CGAlgorithms.computeOrientation(Coordinate, Coordinate, Coordinate)
public void reverse()
public void normalize()
Coordinate).
public double angle()
public CoordinatemidPoint()
public static CoordinatemidPoint(Coordinate p0, Coordinate p1)
public double distance(LineSegmentls)
public double distance(Coordinatep)
public double distancePerpendicular(Coordinatep)
public CoordinatepointAlong(double segmentLengthFraction)
Coordinate that lies a given fraction along the line defined by this segment. A fraction of
0.0 returns the start point of the segment; a fraction of
1.0 returns the end point of the segment. If the fraction is < 0.0 or > 1.0 the point returned will lie before the start or beyond the end of the segment.
segmentLengthFraction - the fraction of the segment length along the line
public CoordinatepointAlongOffset(double segmentLengthFraction, double offsetDistance)
Coordinate that lies a given fraction along the line defined by this segment and offset from the segment by a given distance. A fraction of
0.0 offsets from the start point of the segment; a fraction of
1.0 offsets from the end point of the segment. The computed point is offset to the left of the line if the offset distance is positive, to the right if negative.
segmentLengthFraction - the fraction of the segment length along the line
offsetDistance - the distance the point is offset from the segment (positive is to the left, negative is to the right)
IllegalStateException - if the segment has zero length
public double projectionFactor(Coordinatep)
The projection factor will lie in the range (-inf, +inf), or be NaN if the line segment has zero length..
p - the point to compute the factor for
public double segmentFraction(CoordinateinputPt)
Essentially, this is the projectionFactor(com.vividsolutions.jts.geom.Coordinate) clamped to the range [0.0, 1.0]. If the segment has zero length, 1.0 is returned.
inputPt - the point
public Coordinateproject(Coordinate p)
Note that the projected point may lie outside the line segment. If this is the case, the projection factor will lie outside the range [0.0, 1.0].
public LineSegmentproject(LineSegment seg)
Note that the returned line may have zero length (i.e. the same endpoints). This can happen for instance if the lines are perpendicular to one another.
seg - the line segment to project
null if there is no overlap
public CoordinateclosestPoint(Coordinate p)
p - the point to find the closest point to
public Coordinate[] closestPoints(LineSegment line)
line - the segment to find the closest point to
public Coordinateintersection(LineSegment line)
RobustLineIntersector class should be used.
line - a line segment
null if there is none
RobustLineIntersector
public CoordinatelineIntersection(LineSegment line)
RobustLineIntersector class should be used.
line - a line segment defining an straight line with infinite extent
null if there is no point of intersection or an infinite number of intersection points
RobustLineIntersector
public LineStringtoGeometry(GeometryFactory geomFactory)
geomFactory - the geometery factory to use
public boolean equals(Objecto)
true if
other has the same values for its points.
public int hashCode()
public int compareTo(Objecto)
compareTo in interface
Comparable
o - the
LineSegment with which this
LineSegment is being compared
LineSegment is less than, equal to, or greater than the specified
LineSegment
public boolean equalsTopo(LineSegmentother)
true if
other is topologically equal to this LineSegment (e.g. irrespective of orientation).
other - a
LineSegment with which to do the comparison.
true if
other is a
LineSegment with the same values for the x and y ordinates.
public StringtoString()