starry-math
    Preparing search index...

    Class Quaternion

    Represents a quaternion, which is a mathematical construct used to represent rotations in 3D space. Quaternions avoid gimbal lock and provide smooth interpolations between orientations. A quaternion is defined by four components: x, y, z (vector part) and w (scalar part).

    Index

    Constructors

    Properties

    w x y z

    Methods

    Constructors

    • Creates a new Quaternion instance with the specified components.

      Parameters

      • x: number = 0

        The x component of the quaternion. Default is 0.

      • y: number = 0

        The y component of the quaternion. Default is 0.

      • z: number = 0

        The z component of the quaternion. Default is 0.

      • w: number = 1

        The w component of the quaternion. Default is 1 (identity rotation).

      Returns Quaternion

    Properties

    w: number = 0

    The w component of the quaternion (scalar part).

    x: number = 0

    The x component of the quaternion (vector part).

    y: number = 0

    The y component of the quaternion (vector part).

    z: number = 0

    The z component of the quaternion (vector part).

    Methods

    • Copies the components from another quaternion to this one.

      Parameters

      Returns this

      This quaternion instance for method chaining.

    • Determines if this quaternion is equal to another quaternion.

      Parameters

      • source: Quaternion

        The quaternion to compare with.

      Returns boolean

      True if all components are equal, false otherwise.

      This is a strict equality check using ===, so it may return false for quaternions that represent the same rotation but have different component values due to floating-point precision.

    • Sets the components of this quaternion.

      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

      This quaternion instance for method chaining.

    • Sets the quaternion components based on Euler angles. Converts Euler angles (rotation around x, y, z axes) to a quaternion representation.

      Parameters

      • euler: Euler

        The Euler angles to convert from, including rotation order.

      Returns this

      This quaternion instance for method chaining.

      The conversion uses the rotation order specified in the Euler object (XYZ, YXZ, ZXY, ZYX, YZX, or XZY).