Line
A line SEGMENT - this is not an infinite line. If you want an infinite line, see LinearEquation. This class forms the basis for polygonal geometry within the Pathfinder project.
Key Concepts
- Line Segment: This class represents a finite line segment defined by a start and an end point.
- Bounding Box: The line segment implicitly defines a bounding box, which is used for quick checks of point containment.
- Underlying Equation: Each line segment has an associated
LinearEquationthat represents the infinite line passing through its start and end points.
Methods
Line(PointXY start, PointXY end)
Constructs a new Line segment given a start and an end point. Throws an IllegalArgumentException if the start and end points are identical.
Line(PointXY origin, Angle angle, double distance)
Constructs a new Line segment starting from an origin point, extending in a given angle for a specified distance.
getUnboundedIntersection(Line a, Line b)
Static method. Returns the intersection point of the infinite lines defined by two Line segments (a and b). This method does not check if the intersection point lies within the segments themselves.
areLinesParallel(Line a, Line b)
Static method. Checks if two Line segments are parallel (i.e., their underlying infinite lines have the same slope).
doLinesIntersect(Line a, Line b)
Static method. Checks if two Line segments intersect on both line segments.
getIntersection(Line a, Line b)
Static method. Returns the intersection point of two Line segments only if the intersection occurs on both segments. Otherwise, returns null.
isPointOnLine(Line line, PointXY point)
Static method. Checks if a point is collinear with the start and end points of a line (i.e., if the point lies on the infinite line defined by the segment).
isPointOnLineSegment(Line line, PointXY point)
Static method. Checks if a point lies on the line segment itself (i.e., it's collinear and within the segment's bounding box).
getClosestPoint(PointXY reference, Line line)
Static method. Returns the point on the line segment that is closest to the reference point.
getClosestEndpoint(PointXY reference, Line line)
Static method. Returns the endpoint of the line segment that is closest to the reference point.
getFurthestPoint(PointXY reference, Line line)
Static method. Returns the endpoint of the line segment that is furthest from the reference point.
midpoint(Line line)
Static method. Returns the midpoint of the line segment.
getMinX()
Returns the minimum X-coordinate of the line segment's bounding box.
getMinY()
Returns the minimum Y-coordinate of the line segment's bounding box.
getMaxX()
Returns the maximum X-coordinate of the line segment's bounding box.
getMaxY()
Returns the maximum Y-coordinate of the line segment's bounding box.
getStart()
Returns the starting PointXY of the line segment.
getEnd()
Returns the ending PointXY of the line segment.
getEquation()
Returns the LinearEquation representing the infinite line that passes through this segment.
deltaX()
Returns the difference between the maximum and minimum X-coordinates (maxX - minX).
deltaY()
Returns the difference between the maximum and minimum Y-coordinates (maxY - minY).
slope()
Returns the slope of the line segment.
angleSlope()
Returns the slope of the line segment as an Angle.
perpendicularSlope()
Returns the slope of a line perpendicular to this line segment.
anglePerpendicularSlope()
Returns the slope of a line perpendicular to this line segment as an Angle.
isPerpendicularTo(Line line)
Checks if this line segment is perpendicular to another line segment.
getUnboundedIntersectionWith(Line line)
Returns the unbounded intersection point with another line segment.
getIntersectionWith(Line line)
Returns the bounded intersection point with another line segment.
doesIntersectWith(Line line)
Checks if this line segment intersects with another line segment.
isParallelWith(Line line)
Checks if this line segment is parallel with another line segment.
midpoint()
Returns the midpoint of this line segment.
getClosestPoint(PointXY reference)
Returns the point on this line segment that is closest to the reference point.
getClosestEndpoint(PointXY reference)
Returns the endpoint of this line segment that is closest to the reference point.
getFurthestPoint(PointXY reference)
Returns the point on this line segment that is furthest from the reference point.
isPointOnLine(PointXY reference)
Checks if a reference point is on the infinite line defined by this segment.
isPointOnLineSegment(PointXY reference)
Checks if a reference point is on this line segment.
length()
Returns the length of the line segment.
shouldReturnFalse(PointXY reference)
Internal method used for specific checks related to point containment and collinearity.