Preparing search index...

    2D vector with x and y components, used for 2D positions, directions, and math operations.

    Index

    Constructors

    • Constructs a vec2 with the given x and y values.

      Parameters

      • x: number
      • y: number

      Returns vec2

    Properties

    g: number

    Alias for the y component.

    length: number

    Magnitude of the vector.

    lengthSquared: number

    Squared magnitude of the vector.

    r: number

    Alias for the x component.

    x: number

    Horizontal component of the vector.

    y: number

    Vertical component of the vector.

    Methods

    • Returns a new vec2 that is the sum of this and the given vector.

      Parameters

      Returns vec2

    • Adds the given vector to this vector in place.

      Parameters

      Returns void

    • Returns the angle in radians between this vector and the given vector.

      Parameters

      Returns number

    • Returns a new vec2 with its length clamped to the given maximum.

      Parameters

      • length: number

      Returns vec2

    • Clamps the length of this vector to the given maximum in place.

      Parameters

      • length: number

      Returns void

    • Returns a new vec2 with the same x and y values.

      Returns vec2

    • Copies x and y values from the given vector into this vector.

      Parameters

      Returns void

    • Returns the distance between this vector and the given vector.

      Parameters

      Returns number

    • Returns the squared distance between this vector and the given vector.

      Parameters

      Returns number

    • Returns a new vec2 that is this vector divided component-wise by the given vector.

      Parameters

      Returns vec2

    • Divides this vector component-wise by the given vector in place.

      Parameters

      Returns void

    • Returns the dot product of this vector and the given vector.

      Parameters

      Returns number

    • Static vec2 pointing in the negative y direction (0, -1).

      Returns vec2

    • Returns true if this vector and the given vector have equal x and y values.

      Parameters

      Returns boolean

    • Sets all components of this vector to the given scalar value.

      Parameters

      • scalar: number

      Returns void

    • Static vec2 pointing in the negative x direction (-1, 0).

      Returns vec2

    • Returns a new vec2 linearly interpolated between two vectors by the given factor.

      Parameters

      Returns vec2

    • Linearly interpolates this vector toward the target vector by the given factor in place.

      Parameters

      • target: vec2
      • t: number

      Returns void

    • Returns a vec2 with the component-wise maximum of two vectors.

      Parameters

      Returns vec2

    • Returns a vec2 with the component-wise minimum of two vectors.

      Parameters

      Returns vec2

    • Returns a new vec2 moved from this vector toward the target by at most the given max distance.

      Parameters

      • target: vec2
      • step: number

      Returns vec2

    • Moves this vector toward the target by at most the given max distance in place.

      Parameters

      • point: vec2
      • magnitude: number

      Returns void

    • Returns a new vec2 that is this vector multiplied component-wise by the given vector.

      Parameters

      Returns vec2

    • Multiplies this vector component-wise by the given vector in place.

      Parameters

      Returns void

    • Returns a new vec2 with the same direction but unit length.

      Returns vec2

    • Normalizes this vector to unit length in place.

      Returns void

    • Static vec2 with all components set to 1.

      Returns vec2

    • Returns the projection of this vector onto the given vector.

      Parameters

      Returns vec2

    • Projects this vector onto the given vector in place.

      Parameters

      Returns void

    • Returns this vector projected onto the plane defined by the given normal.

      Parameters

      Returns vec2

    • Projects this vector onto the plane defined by the given normal in place.

      Parameters

      Returns void

    • Returns a random unit vec2.

      Returns vec2

    • Returns the reflection of this vector off the surface defined by the given normal.

      Parameters

      Returns vec2

    • Reflects this vector off the surface defined by the given normal in place.

      Parameters

      Returns void

    • Static vec2 pointing in the positive x direction (1, 0).

      Returns vec2

    • Returns a new vec2 scaled by the given scalar.

      Parameters

      Returns vec2

    • Scales this vector by the given scalar in place.

      Parameters

      Returns void

    • Sets this vector to a random unit vector.

      Returns void

    • Sets the x and y components of this vector.

      Parameters

      • Optionalx: number
      • Optionaly: number

      Returns void

    • Returns a new vec2 that is this vector minus the given vector.

      Parameters

      Returns vec2

    • Subtracts the given vector from this vector in place.

      Parameters

      Returns void

    • Returns a string representation of this vector.

      Returns string

    • Returns a new vec2 uniformly scaled by the given scalar.

      Parameters

      • scale: number

      Returns vec2

    • Uniformly scales this vector by the given scalar in place.

      Parameters

      • scale: number

      Returns void

    • Static vec2 pointing in the positive y direction (0, 1).

      Returns vec2

    • Static vec2 with all components set to 0.

      Returns vec2