rhodonite
    Preparing search index...

    Class Quaternion

    Represents an immutable quaternion that extends AbstractQuaternion. Quaternions are used to represent rotations in 3D space and offer advantages over Euler angles such as avoiding gimbal lock and providing smooth interpolation.

    A quaternion consists of four components: x, y, z (vector part) and w (scalar part). For unit quaternions representing rotations: q = w + xi + yj + zk where i² = j² = k² = ijk = -1

    // Create identity quaternion (no rotation)
    const identity = Quaternion.identity();

    // Create quaternion from axis-angle representation
    const axis = Vector3.fromCopy3(0, 1, 0); // Y-axis
    const angle = Math.PI / 4; // 45 degrees
    const rotation = Quaternion.fromAxisAngle(axis, angle);

    // Multiply quaternions to combine rotations
    const combined = Quaternion.multiply(rotation1, rotation2);

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    _v: Float32Array<ArrayBufferLike> = ...

    Internal typed array storage for quaternion components [x, y, z, w].

    Accessors

    • get compositionType(): CompositionTypeClass<"VEC4">

      Gets the composition type for this quaternion class.

      Returns CompositionTypeClass<"VEC4">

      CompositionType.Vec4 indicating this is a 4-component vector

    Methods

    • Calculates the dot product between this quaternion and another quaternion. The dot product of two quaternions gives a scalar value that represents the cosine of half the angle between them when both quaternions are unit quaternions.

      Parameters

      • quat: IQuaternion

        The quaternion to compute the dot product with

      Returns number

      The dot product result

    • Creates a quaternion from an axis-angle representation.

      Parameters

      • vec: IVector3

        The rotation axis (will be normalized internally)

      • radian: number

        The rotation angle in radians

      Returns Quaternion

      A quaternion representing the rotation around the given axis

    • Clamps the rotation angle of a quaternion to a maximum value. If the quaternion's rotation angle exceeds thetaMax, it scales the rotation down.

      Parameters

      • quat: IQuaternion

        The quaternion to clamp

      • thetaMax: number

        The maximum allowed rotation angle in radians

      Returns IQuaternion

      A quaternion with rotation angle clamped to thetaMax

    • Creates a quaternion from individual component values.

      Parameters

      • x: number

        The x component

      • y: number

        The y component

      • z: number

        The z component

      • w: number

        The w component

      Returns Quaternion

      A new quaternion with the specified components

    • Creates a quaternion from a variable-length array (taking first 4 elements).

      Parameters

      • array: number[]

        The array containing quaternion components

      Returns Quaternion

      A new quaternion with the first 4 components copied

    • Creates a quaternion from a Float32Array.

      Parameters

      • array: Float32Array

        The Float32Array containing quaternion components

      Returns Quaternion

      A new quaternion using the provided array

    • Creates a quaternion from a 4x4 rotation matrix. Extracts the rotation component from the matrix and converts it to quaternion form.

      Parameters

      • mat: IMatrix44

        The 4x4 matrix containing rotation information

      Returns Quaternion

      A quaternion representing the same rotation as the matrix