Class representing a vector

Hierarchy (view full)

Implements

Constructors

  • Vector may be constructed by two points, or by two float numbers, or by array of two numbers

    Parameters

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

      array of two numbers or two points [start,end] or two numbers

    Returns Vector

Properties

x: number = 0

x-coordinate of a vector (float number)

y: number = 0

y-coordinate of a vector (float number)

Accessors

  • get box(): Box
  • Bounding box

    Returns Box

    bounding box of a shape

  • get length(): number
  • Length of vector

    Returns number

    length of vector

  • get name(): string
  • Shape name

    Returns string

    name of the shape

  • get slope(): number
  • Slope of the vector in radians from 0 to 2PI

    Returns number

    slope in radians from 0 to 2PI

Methods

  • Return result of addition of other vector to this vector as a new vector

    Parameters

    Returns Vector

    sum of two vectors

  • Return angle between this vector and other vector.
    Angle is measured from 0 to 2*PI in the counterclockwise direction from current vector to another.

    Parameters

    Returns number

    Angle in radians between two vectors in range [0, 2*PI]

  • Method clone returns new instance of Vector

    Returns Vector

    clone of the vector

  • Returns vector product (cross product) of two vectors
    cross_product = (this x v)

    Parameters

    Returns number

    cross_product

  • Get distance to shape.

    Parameters

    Returns [number, Segment]

  • Returns scalar product (dot product) of two vectors
    dot_product = (this * v)

    Parameters

    Returns number

    dot product

  • Returns true if vectors are equal up to DP_TOL tolerance

    Parameters

    Returns boolean

    true if vectors are equal

  • Return inverted vector

    Returns Vector

    inverted vector

  • Returns new vector multiplied by scalar

    Parameters

    • scalar: number

    Returns Vector

    scaled vector

  • Returns unit vector.
    Throw error if given vector has zero length

    Returns Vector

    normalized vector

  • Return vector projection of the current vector on another vector

    Parameters

    Returns Vector

    projection of the current vector on another vector

  • Rotate vector by given angle, positive angle defines rotation in counterclockwise direction, negative - in clockwise direction Vector only can be rotated around (0,0) point!

    Parameters

    • angle: number

      Angle in radians

    • center: Point = ...

    Returns Vector

    rotated vector

  • Returns vector rotated 90 degrees counterclockwise

    Returns Vector

    rotated vector

  • Returns vector rotated 90 degrees clockwise

    Returns Vector

    rotated vector

  • Scale shape with coordinates multiplied by scaling factor

    Parameters

    • sx: number

      x-axis scaling factor

    • sy: number

      y-axis scaling factor

    Returns Vector

    new scaled shape

  • Return result of subtraction of other vector from current vector as a new vector

    Parameters

    Returns Vector

    subtraction result

  • Return new vector transformed by affine transformation matrix m

    Parameters

    • m: Matrix

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

    Returns Vector

    transformed vector

  • 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 Vector

    new translated shape