Class representing a line

Hierarchy (view full)

Constructors

  • Parameters

    • Rest...args:
          | []
          | [Point, Point]
          | [Point, Vector]
          | [Vector, Point]

      Line may be constructed by point and normal vector or by two points that a line passes through

    Returns Line

Properties

norm: Vector = ...

Normal vector to a line
Vector is normalized (length == 1)
Direction of the vector is chosen to satisfy inequality norm * p >= 0

pt: Point = ...

Point a line passes through

Accessors

  • get box(): Box
  • Line has infinite box

    Returns Box

    infinite box

  • get end(): undefined
  • Line has no end point

    Returns undefined

    undefined

  • get length(): number
  • Line has infinite length

    Returns number

    positive infinity number

  • get middle(): undefined
  • Line has no middle point

    Returns undefined

    undefined

  • get name(): string
  • Shape name

    Returns string

    name of the shape

  • get slope(): number
  • Slope of the line - angle in radians between line and axe x from 0 to 2PI

    Returns number

    slope of the line

  • get standard(): [number, number, number]
  • Get coefficients [A,B,C] of a standard line equation in the form Ax + By = C

    [A, B, C] = line.standard
    

    Returns [number, number, number]

    coefficients [A,B,C]

  • get start(): undefined
  • Line has no start point

    Returns undefined

    undefined

Methods

  • Return new cloned instance of line

    Returns Line

    cloned line

  • Check if point belongs to line

    Parameters

    Returns boolean

    true if point belongs to line

  • Return coordinate of the point that lies on the line in the transformed coordinate system where center is the projection of the point(0,0) to the line and axe y is collinear to the normal vector.
    This method assumes that point lies on the line and does not check it

    Parameters

    • pt: Point

      point on a line

    Returns number

  • Calculate distance and shortest segment from line to shape and returns array [distance, shortestSegment]

    Parameters

    • shape: Shape<any> | Polygon

      Shape of the one of the types Point, Circle, Segment, Arc, Polygon

    Returns [number, Segment]

  • Check if line is incident to other line

    Parameters

    • l: Line

      line to check

    Returns boolean

    Returns true if incident to other line

  • Returns array of intersection points

    Parameters

    • shape: Shape<any>

      shape to intersect with

    Returns Point[]

  • Check if line is parallel to other line

    Parameters

    • l: Line

      line to check

    Returns boolean

    true if parallel or incident to other line

  • Rotate line by angle and center point.

    Parameters

    • angle: number

      angle in radians

    • center: Point = ...

      center of rotation

    Returns Line

    rotated line

  • Scale shape with coordinates multiplied by scaling factor

    Parameters

    • sx: number

      x-axis scaling factor

    • sy: number

      y-axis scaling factor

    Returns Line

    new scaled shape

  • Sort given array of points that lay on a line with respect to coordinate on a line The method assumes that points lay on the line and does not check this

    Parameters

    • pts: Point[]

      array of points

    Returns Point[]

    new array sorted

  • Split line with a point or array of points and return array of shapes Assumed (but not checked) that all points lay on the line

    Parameters

    Returns (Ray | Segment)[]

  • Transform line with given affine transformation matrix.

    Parameters

    • m: Matrix

      affine transformation matrix (a,b,c,d,tx,ty)

    Returns Line

    transformed line

  • Translated shape by given vector. Translation vector may be also defined by a pair of numbers.

    Parameters

    • Rest...args: [number, number] | [Vector]

      Translation vector or translation by x and y or tuple of numbers

    Returns Line

    new translated shape