Options
All
  • Public
  • Public/Protected
  • All
Menu

Representation of two dimensional vectors and points.

Hierarchy

  • Vector2

Index

Constructors

constructor

  • new Vector2(x?: number, y?: number): Vector2
  • Constructs a new 2D vector.

    example
    let v = new Vector2();     // v = [0, 0]
    let v = new Vector2(1); // v = [1, 0]
    let v = new Vector2(2, 3); // v = [2, 3]

    Parameters

    • x: number = 0

      X component.

    • y: number = 0

      Y component.

    Returns Vector2

Properties

x

x: number

X component.

y

y: number

Y component.

Static Readonly down

down: Vector2 = ...

Shorthand for typing new Vector(0, -1).

Static Readonly left

left: Vector2 = ...

Shorthand for typing new Vector(-1, 0).

Static Readonly one

one: Vector2 = ...

Shorthand for typing new Vector(1, 1).

Static Readonly right

right: Vector2 = ...

Shorthand for typing new Vector(1, 0).

Static Readonly up

up: Vector2 = ...

Shorthand for typing new Vector(0, 1).

Static Readonly zero

zero: Vector2 = ...

Shorthand for typing new Vector(0, 0).

Methods

magnitude

  • magnitude(): number

normalize

sqrMagnitude

  • sqrMagnitude(): number
  • Use of squared value is significantly faster, because the square root calculation is a expensive operation.

    example
    if (v.sqrMagnitude() > a * a) {...}
    // vs slower equivalent
    if (v.magnitude() > a) {...}

    Returns number

    Squared length of this vector.

Static add

Static div

Static dot

  • Parameters

    Returns number

    Dot product between two given vectors.

Static lerp

  • Linearly interpolate this vector to vector b by t.

    example
    let a = new Vector2(-1, -1);
    let b = new Vector2(1, 1);

    let v = Vector2.lerp(a, b, 0.5); // v = [0, 0]

    Parameters

    • a: Vector2

      Start position.

    • b: Vector2

      End position.

    • t: number

      Progress between 0 and 1.

    Returns Vector2

    Interpolated position between vectors.

Static mul

Static sub

Generated using TypeDoc