Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Vector2

Represents 2D points and vectors.

Hierarchy

  • Vector2

Index

Constructors

  • Returns Vector2

  • Parameters

    • x: number
    • y: number

    Returns Vector2

Properties

length: number

Returns the length of this vector.

The length is calculated by the square root of (x * x + y * y)

returns

length of this vector.

normalized: Vector2

Returns a copy of this vector with length 1.

sqrLength: number

Returns the squared length of this vector.

If you use vector lengths to compare distances, squared lengths are more performant and preferred to use.

returns

squared length of this vector

x: number
y: number
axisX: Vector2

Shorthand for writing new Vector2(1,0).

axisY: Vector2

Shorthand for writing new Vector2(0,1).

one: Vector2

Shorthand for writing new Vector2(1,1).

zero: Vector2

Shorthand for writing new Vector2(0,0).

Methods

  • Parameters

    Returns number

  • Parameters

    Returns number

  • Parameters

    • w: number

    Returns Vector2

  • Parameters

    Returns number

  • Returns true if this vector components equal v.

    Parameters

    • v: Vector2

      vector to compare this vector against.

    Returns boolean

  • Parameters

    • w: number

    Returns Vector2

  • Adds vector a and vector b together by their corresponding components.

    Parameters

    Returns Vector2

    combined result

  • Returns the angle in radians from vector a to vector b.

    Parameters

    Returns number

    angle in radians.

  • Returns the distance between vector a and vector b.

    Parameters

    Returns number

    distance between vectors.

  • Divides all components of vector v by divisor d.

    Parameters

    • v: Vector2

      vector components to multiply.

    • d: number

      divisor.

    Returns Vector2

    new vector of the divided result.

  • Calculates the dot product of this vector a and vector b.

    The dot product is a number equal to the length of two vectors multiplied together and then multiplied by the cosine of the angle between them.

    Parameters

    Returns number

    dot product.

  • Interpolates between vector a and b over interpolant t.

    Used to find a point between endpoints a and b.

    Example: If t = 0.5, the target point is in the middle of the path from a to b.

    Parameters

    Returns Vector2

    point between a and b.

  • Returns a new vector made from the largest components of vector a and vector b.

    Parameters

    Returns Vector2

  • Returns a new vector made from the smallest components of vector a and vector b.

    Parameters

    Returns Vector2

  • Multiplies each component of vector v by m.

    Parameters

    • v: Vector2

      vector components to multiply.

    • m: number

    Returns Vector2

    new vector of the multiplied result.

  • Subtracts each component of vector b from a.

    Parameters

    Returns Vector2

    new vector of the subtraction result.