starry-math
    Preparing search index...

    Class Vector4

    Represents a 4D vector with x, y, z, and w components. Provides various vector operations for 4D mathematics and transformations.

    Index

    Constructors

    • Creates a new Vector4 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

      • z: number = 0

        The z component of the vector. Defaults to 0

      • w: number = 0

        The w component of the vector. Defaults to 0

      Returns Vector4

    Properties

    w: number

    The w component of the vector

    x: number

    The x component of the vector

    y: number

    The y component of the vector

    z: number

    The z component of the vector

    Methods

    • Adds another vector to this vector

      Parameters

      Returns this

      Returns this vector for method chaining

    • Applies a 4x4 matrix transformation to this vector

      Parameters

      • matrix: IMatrix4

        The 4x4 matrix to apply

      Returns this

      Returns this vector for method chaining

    • Copies values from another vector into this vector

      Parameters

      • source: Vector4

        The vector to copy from

      Returns this

      Returns this vector for method chaining

    • Divides this vector component-wise by another vector

      Parameters

      • vector: Vector4

        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

    • Compares this vector with another vector for equality

      Parameters

      • vector: Vector4

        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: Vector4

        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

    • Sets the components of this vector

      Parameters

      • x: number

        The new x component

      • y: number

        The new y component

      • z: number

        The new z component

      • w: number

        The new w component

      Returns this

      Returns this vector for method chaining

    • Sets the w component of this vector

      Parameters

      • w: number

        The new w 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

    • Sets the z component of this vector

      Parameters

      • z: number

        The new z component

      Returns this

      Returns this vector for method chaining

    • Subtracts another vector from this vector

      Parameters

      • vector: Vector4

        The vector to subtract

      Returns this

      Returns this vector for method chaining

    • Converts this vector to an array of its components

      Returns [number, number, number, number]

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

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

      Returns this

      Returns this vector for method chaining

      Will throw an error if the vector length is zero