Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Line

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 function as-is, or apply the op method in Group or Pt to many of these functions. See Op guide for details.

Hierarchy

  • Line

Index

Methods

Static collinear

  • collinear(p1: PtLike | number[], p2: PtLike | number[], p3: PtLike | number[], threshold?: number): boolean
  • Check if three Pts are collinear, ie, on the same straight path.

    Parameters

    • p1: PtLike | number[]

      first Pt

    • p2: PtLike | number[]

      second Pt

    • p3: PtLike | number[]

      third Pt

    • Default value threshold: number = 0.01

      a threshold where a smaller value means higher precision threshold for the straight line. Default is 0.01.

    Returns boolean

Static distanceFromPt

  • Given a line and a point, find the shortest distance from the point to the line

    see

    Line.perpendicularFromPt

    Parameters

    Returns number

Static fromAngle

  • fromAngle(anchor: PtLike, angle: number, magnitude: number): Group
  • Create a line by "drawing" from an anchor point, given an angle and a magnitude

    Parameters

    • anchor: PtLike

      an anchor Pt

    • angle: number

      an angle in radian

    • magnitude: number

      magnitude of the line

    Returns Group

    a Group of 2 Pts representing a line segement

Static intercept

  • intercept(p1: PtLike | number[], p2: PtLike | number[]): object
  • Calculate the slope and xy intercepts of a line

    Parameters

    • p1: PtLike | number[]

      line's first end point

    • p2: PtLike | number[]

      line's second end point

    Returns object

    an object with slope, xi, yi properties

    • slope: number
    • xi: number
    • yi: number

Static intersectGridWithLine2D

  • Get two intersection Pts of a line segment with a 2D grid point

    Parameters

    Returns Group

    a group of two intersecting Pts. The first one is horizontal intersection and the second one is vertical intersection.

Static intersectGridWithRay2D

  • Get two intersection Pts of a ray with a 2D grid point

    Parameters

    • ray: GroupLike

      a ray specified by 2 Pts

    • gridPt: PtLike | number[]

      a Pt on the grid

    Returns Group

    a group of two intersecting Pts. The first one is horizontal intersection and the second one is vertical intersection.

Static intersectLine2D

  • Given two line segemnts, find their intersection point if any.

    Parameters

    • la: GroupLike

      a Group of 2 Pts representing a line segment

    • lb: GroupLike

      a Group of 2 Pts representing a line segment

    Returns Pt

    an intersection Pt or undefined if no intersection

Static intersectLineWithRay2D

  • Given a line segemnt and a ray (infinite line), find their intersection point if any.

    Parameters

    • line: GroupLike

      a Group of 2 Pts representing a line segment

    • ray: GroupLike

      a Group of 2 Pts representing a ray

    Returns Pt

    an intersection Pt or undefined if no intersection

Static intersectPolygon2D

  • Given a line segemnt and a ray (infinite line), find its intersection point(s) with a polygon.

    Parameters

    • lineOrRay: GroupLike

      a Group of 2 Pts representing a line or ray

    • poly: GroupLike[]

      a Group of Pts representing a polygon

    • Default value sourceIsRay: boolean = false

      a boolean value to treat the line as a ray (infinite line). Default is false.

    Returns Group

Static intersectRay2D

  • Given two lines as rays (infinite lines), find their intersection point if any.

    Parameters

    • la: GroupLike

      a Group of 2 Pts representing a ray

    • lb: GroupLike

      a Group of 2 Pts representing a ray

    Returns Pt

    an intersection Pt or undefined if no intersection

Static intersectRect2D

  • Quick way to check rectangle intersection. For more optimized implementation, store the rectangle's sides separately (eg, Rectangle.sides()) and use Polygon.intersect2D().

    Parameters

    • line: GroupLike

      a Group representing a line

    • rect: GroupLike

      a Group representing a rectangle

    Returns Group

Static magnitude

  • Get magnitude of a line segment

    Parameters

    Returns number

Static magnitudeSq

  • Get squared magnitude of a line segment

    Parameters

    Returns number

Static perpendicularFromPt

  • perpendicularFromPt(line: GroupLike, pt: PtLike | number[], asProjection?: boolean): Pt
  • Find a point on a line that is perpendicular (shortest distance) to a target point

    Parameters

    • line: GroupLike
    • pt: PtLike | number[]

      a target Pt

    • Default value asProjection: boolean = false

      if true, this returns the projection vector instead. Default is false.

    Returns Pt

    a Pt on the line that is perpendicular to the target Pt, or a projection vector if asProjection is true.

Static sideOfPt2D

  • Given a 2D path and a point, find whether the point is on left or right side of the line

    Parameters

    Returns number

    a negative value if on left and a positive value if on right. If collinear, then the return value is 0.

Static slope

  • slope(p1: PtLike | number[], p2: PtLike | number[]): number
  • Calculate the slope of a line

    Parameters

    • p1: PtLike | number[]

      line's first end point

    • p2: PtLike | number[]

      line's second end point

    Returns number

Static subpoints

  • Get evenly distributed points on a line

    Parameters

    • line: GroupLike | number[][]

      a Group representing a line

    • num: number

      number of points to get

    Returns Group

Static toRect

  • Convert this line to a rectangle representation

    Parameters

    • line: GroupLike

      a Group representing a line

    Returns Group

Generated using TypeDoc