starry-math
    Preparing search index...

    Class Vector2

    Represents a 2D vector with x and y components. Provides various vector operations for 2D mathematics and transformations.

    Index

    Constructors

    • Creates a new Vector2 instance

      Parameters

      • x: number = 0

        The x component of the vector. Defaults to 0

      • y: number = 0

        The y component of the vector. Defaults to 0

      Returns Vector2

    Properties

    x: number

    The x component of the vector

    y: number

    The y component of the vector

    Methods

    • Adds another vector to this vector

      Parameters

      Returns this

      Returns this vector for method chaining

    • Returns the angle between two vectors

      Parameters

      • vector: Vector2

        The vector to measure angle against

      Returns number

      The angle between the vectors in radians

    • Copies values from another vector into this vector

      Parameters

      • source: Vector2

        The vector to copy from

      Returns this

      Returns this vector for method chaining

    • Computes the cross product of this vector with another vector

      Parameters

      • vector: Vector2

        The other vector for the cross product

      Returns number

      The cross product result (scalar in 2D)

    • Computes the distance between this vector and another vector

      Parameters

      • vector: Vector2

        The other vector to measure distance to

      Returns number

      The distance between the vectors

    • Computes the squared distance between this vector and another vector (avoids sqrt for performance)

      Parameters

      • vector: Vector2

        The other vector to measure distance to

      Returns number

      The squared distance between the vectors

    • Divides this vector component-wise by another vector

      Parameters

      • vector: Vector2

        The vector to divide by

      Returns this

      Returns this vector for method chaining

    • Divides this vector by a scalar

      Parameters

      • num: number

        The scalar value to divide by

      Returns this

      Returns this vector for method chaining

    • Computes the dot product of this vector with another vector

      Parameters

      • vector: Vector2

        The other vector for the dot product

      Returns number

      The dot product result

    • Compares this vector with another vector for equality

      Parameters

      • vector: Vector2

        The vector to compare with

      Returns boolean

      True if vectors are equal, false otherwise

    • Computes the length (magnitude) of this vector

      Returns number

      The length of the vector

    • Computes the squared length of this vector (avoids sqrt for performance)

      Returns number

      The squared length of the vector

    • Multiplies this vector component-wise by another vector

      Parameters

      • vector: Vector2

        The vector to multiply by

      Returns this

      Returns this vector for method chaining

    • Multiplies this vector by a scalar

      Parameters

      • num: number

        The scalar value to multiply by

      Returns this

      Returns this vector for method chaining

    • Converts to normal vector (y, -x)

      Returns this

      This vector as a normal vector for method chaining

    • Rotates the vector by a given angle

      Parameters

      • angle: number

        The rotation angle in radians

      Returns this

      Returns this vector for method chaining

    • Sets the components of this vector

      Parameters

      • x: number

        The new x component

      • y: number

        The new y component

      Returns this

      Returns this vector for method chaining

    • Sets the x component of this vector

      Parameters

      • x: number

        The new x component

      Returns this

      Returns this vector for method chaining

    • Sets the y component of this vector

      Parameters

      • y: number

        The new y component

      Returns this

      Returns this vector for method chaining

    • Subtracts another vector from this vector

      Parameters

      • vector: Vector2

        The vector to subtract

      Returns this

      Returns this vector for method chaining

    • Converts this vector to an array of its components

      Returns [number, number]

      An array containing the vector's components [x, y]

    • Normalizes this vector to unit length (length = 1)

      Returns this

      Returns this vector for method chaining