Line class provides static functions to create and operate on lines. A line is usually represented as a Group of 2 Pts.
You can use the static functions as-is, or apply the Group.op
or Pt.op
to enable functional programming.
See Op guide for details.
Check if three Pts are collinear, ie, on the same straight path.
first Pt
second Pt
third Pt
a threshold where a smaller value means higher precision threshold for the straight line. Default is 0.01.
Crop this line by a circle or rectangle at end points. This can be useful for creating arrows that connect to an object's edge.
a Group or an Iterable
size of circle or rectangle as Pt
line's end point index, ie, 0 = start and 1 = end.
a boolean to specify whether the size
parameter should be treated as circle. Default is true
.
an intersecting point on the line that can be used for cropping.
Given a line and a point, find the shortest distance from the point to the line.
a Group of 2 Pts
a Pt
Line.perpendicularFromPt
Create a line that originates from an anchor point, given an angle and a magnitude.
an anchor Pt
an angle in radian
magnitude of the line
a Group of 2 Pts representing a line segement
Calculate the slope and xy intercepts of a line.
line's first end point
line's second end point
an object with slope
, xi
, yi
properties
Get two intersection Pts of a line segment with a 2D grid point.
a ray specified by 2 Pts
a Pt on the grid
a group of two intersecting Pts. The first one is horizontal intersection and the second one is vertical intersection.
Get two points of a ray that intersects with a point on a 2D grid.
a Group or an Iterable
a Pt on the grid
a group of two intersecting Pts. The first one is horizontal intersection and the second one is vertical intersection.
Given two line segemnts, find their intersection point if any.
a Group or an Iterable
a Group or an Iterable
an intersection Pt or undefined if no intersection
Find intersection points of 2 sets of lines. This checks all line segments in the two lists. Consider using a bounding-box check before calling this. If you are checking convex polygon intersections, using Polygon.intersectPolygon2D
will be more efficient.
an Array/Iterable of (Groups or Iterables
an Array/Iterable of (Groups or Iterables
a boolean value to treat the line as a ray (infinite line). Default is false
.
Given a line segemnt and a ray (infinite line), find their intersection point if any.
a Group of 2 Pts representing a line segment
a Group of 2 Pts representing a ray
an intersection Pt or undefined if no intersection
Given a line segemnt or a ray (infinite line), find its intersection point(s) with a polygon.
a Group or an Iterable
a Group or an Iterable
a boolean value to treat the line as a ray (infinite line). Default is false
.
Given two lines as rays (infinite lines), find their intersection point if any.
a Group or an Iterable
a Group or an Iterable
an intersection Pt or undefined if no intersection
An easy way to get rectangle-line intersection points. For more optimized implementation, store the rectangle's sides separately (eg, Rectangle.sides()
) and use Polygon.intersectPolygon2D()
.
a Group representing a line
a Group representing a rectangle
a Group of intersecting Pts
Get magnitude of a line segment.
a Group or an Iterable
Get squared magnitude of a line segment.
Create an marker arrow or line, placed at an end point of this line.
a Group or an Iterable
size of the marker as Pt
either "arrow" or "line"
a boolean, if true
, the marker will be positioned at tail of the line (ie, index = 1). Default is true
.
a Group that defines the marker's shape
Find a point on a line that is perpendicular (shortest distance) to a target point.
a Group or an Iterable
a target Pt
if true, this returns the projection vector instead. Default is false.
a Pt on the line that is perpendicular to the target Pt, or a projection vector if asProjection
is true.
Given a 2D path and a point, find whether the point is on left or right side of the line.
a Group or an Iterable
a Pt or numeric array
a negative value if on left and a positive value if on right. If collinear, then the return value is 0.
Calculate the slope of a line.
line's first end point
line's second end point
Get evenly distributed points on a line. Similar to Create.distributeLinear
but excluding end points.
a Group or an Iterable
number of points to get
Convert this line to a new rectangle representation.
a Group representing a line