rhodonite
    Preparing search index...

    Class MutableQuaternion_<T>

    A mutable quaternion class that extends the immutable Quaternion class. Provides methods for quaternion operations that modify the instance in place. Quaternions are used to represent rotations in 3D space and are particularly useful for avoiding gimbal lock and providing smooth interpolations.

    Type Parameters

    Hierarchy (View Summary)

    Implements

    Index
    _v: TypedArray = ...

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

    _type: FloatTypedArrayConstructor = Float32Array

    The typed array constructor used for newly created quaternions.

    • get className(): string

      Gets the class name for identification purposes.

      Returns string

      The string 'MutableQuaternion'

    • get w(): number

      Gets the w component of the quaternion.

      Returns number

      The w component value

    • set w(w: number): void

      Sets the w component of the quaternion.

      Parameters

      • w: number

        The w component value

      Returns void

    • get x(): number

      Gets the x component of the quaternion.

      Returns number

      The x component value

    • set x(x: number): void

      Sets the x component of the quaternion.

      Parameters

      • x: number

        The x component value

      Returns void

    • get y(): number

      Gets the y component of the quaternion.

      Returns number

      The y component value

    • set y(y: number): void

      Sets the y component of the quaternion.

      Parameters

      • y: number

        The y component value

      Returns void

    • get z(): number

      Gets the z component of the quaternion.

      Returns number

      The z component value

    • set z(z: number): void

      Sets the z component of the quaternion.

      Parameters

      • z: number

        The z component value

      Returns void

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

      Gets the composition type for this quaternion class.

      Returns CompositionTypeClass<"VEC4">

      CompositionType.Vec4 indicating this is a 4-component vector

    • Adds another quaternion to this quaternion component-wise.

      Parameters

      Returns this

      This instance for method chaining

    • Gets the component at the specified index.

      Parameters

      • i: number

        The index (0=x, 1=y, 2=z, 3=w)

      Returns number

      The component value at the given index

    • Sets this quaternion from an axis and angle.

      If the axis is degenerate (zero length), this quaternion is set to the identity quaternion instead of being filled with Infinity/NaN. Use MutableQuaternion.tryAxisAngle when the caller needs to detect the failure.

      Parameters

      • vec: IVector3

        The rotation axis (will be normalized)

      • radian: number

        The rotation angle in radians

      Returns this

      This instance for method chaining

    • Creates a copy of this quaternion.

      Returns this

      A new IMutableQuaternion with the same component values

    • Copies components from another quaternion.

      Parameters

      Returns this

      This instance for method chaining

    • Divides this quaternion by a scalar value.

      Parameters

      • value: number

        The scalar value to divide by (must not be zero)

      Returns this

      This instance for method chaining

    • 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

    • Sets this quaternion from a 4x4 transformation matrix. Extracts the rotation component from the matrix, ignoring scale and translation.

      If the rotation cannot be extracted, this quaternion is set to the identity quaternion instead of being filled with Infinity/NaN. Use MutableQuaternion.tryFromMatrix when the caller needs to detect the failure.

      Parameters

      • mat: IMatrix44

        The 4x4 transformation matrix

      Returns this

      This instance for method chaining

    • Sets this quaternion from a position vector (w component set to 0).

      Parameters

      Returns this

      This instance for method chaining

    • Creates a quaternion representing the rotation from one vector to another. This is an instance method version of the static fromToRotation.

      Parameters

      • from: IVector3

        The starting direction vector

      • to: IVector3

        The target direction vector

      Returns any

      The normalized quaternion representing the rotation

    • Sets this quaternion to the identity quaternion (0, 0, 0, 1).

      Returns this

      This instance for method chaining

    • Inverts this quaternion in place (conjugate divided by magnitude squared).

      Returns this

      This instance for method chaining

    • Checks if this quaternion is a dummy (uninitialized) quaternion.

      Returns boolean

      True if the internal array has zero length, false otherwise

    • Checks if this quaternion is approximately equal to another quaternion within a tolerance.

      Parameters

      • quat: IQuaternion

        The quaternion to compare with

      • delta: number = Number.EPSILON

        The tolerance value (default: Number.EPSILON)

      Returns boolean

      True if all components are within the tolerance, false otherwise

    • Calculates the magnitude (length) of the quaternion.

      Returns number

      The Euclidean norm of the quaternion

    • Calculates the squared magnitude of the quaternion. This is more efficient than length() when you only need to compare magnitudes.

      Returns number

      The squared Euclidean norm of the quaternion

    • Performs linear interpolation and stores the result in this quaternion.

      Parameters

      • l_quat: IQuaternion

        The starting quaternion

      • r_quat: IQuaternion

        The ending quaternion

      • ratio: number

        Interpolation factor (0.0 to 1.0)

      Returns this

      This instance for method chaining

    • Multiplies this quaternion by another quaternion (quaternion composition). The result represents the combined rotation.

      Parameters

      Returns this

      This instance for method chaining

    • Multiplies this quaternion by a scalar value.

      Parameters

      • value: number

        The scalar value to multiply by

      Returns this

      This instance for method chaining

    • Normalizes this quaternion to unit length in place.

      Returns this

      This instance for method chaining

    • Performs spherical linear interpolation (SLERP) and stores the result in this quaternion.

      Parameters

      • l_quat: IQuaternion

        The starting quaternion

      • r_quat: IQuaternion

        The ending quaternion

      • ratio: number

        Interpolation factor (0.0 to 1.0)

      Returns this

      This instance for method chaining

    • Gets the raw Float32Array containing the quaternion components.

      Returns TypedArray

      The underlying Float32Array [x, y, z, w]

    • Sets a component value at the specified index.

      Parameters

      • i: number

        The component index (0=x, 1=y, 2=z, 3=w)

      • value: number

        The value to set

      Returns this

      This instance for method chaining

    • Sets all quaternion components.

      Parameters

      • x: number

        The x component

      • y: number

        The y component

      • z: number

        The z component

      • w: number

        The w component

      Returns this

      This instance for method chaining

    • Subtracts another quaternion from this quaternion component-wise.

      Parameters

      Returns this

      This instance for method chaining

    • Converts the quaternion to a string representation.

      Returns string

      A string in the format "(x, y, z, w)"

    • Converts the quaternion to an approximately formatted string using financial precision.

      Returns string

      A formatted string with components separated by spaces and ending with newline

    • Attempts to set this quaternion from an axis and angle.

      The quaternion is left unchanged when the axis is degenerate (zero length or non-finite).

      Parameters

      • vec: IVector3

        The rotation axis (will be normalized)

      • radian: number

        The rotation angle in radians

      Returns boolean

      True if the quaternion could be set, false otherwise

    • Attempts to set this quaternion from a 4x4 transformation matrix. Extracts the rotation component from the matrix, ignoring scale and translation.

      The quaternion is left unchanged when the rotation cannot be extracted.

      Parameters

      • mat: IMatrix44

        The 4x4 transformation matrix

      Returns boolean

      True if the rotation could be extracted, false otherwise

    • Creates a quaternion from an axis-angle representation.

      If the axis has zero length, an identity quaternion is returned instead of a quaternion filled with Infinity/NaN. Use Quaternion.tryAxisAngle when the caller needs to detect the failure.

      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, or the identity quaternion if the axis is degenerate

    • 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

    • Divides a quaternion by a scalar and stores the result in the output parameter. If the divisor is zero, all components are set to 0 and an error is logged instead of producing Infinity/NaN.

      Parameters

      • quat: IQuaternion

        The quaternion to divide

      • value: number

        The scalar value to divide by

      • out: IMutableQuaternion

        The output quaternion to store the result

      Returns IMutableQuaternion

      The output quaternion containing the divided result

    • 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_<FloatTypedArrayConstructor>

      A new quaternion with the specified components

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

      If the rotation cannot be extracted, an identity quaternion is returned instead of a quaternion filled with Infinity/NaN. Use Quaternion.tryFromMatrix when the caller needs to detect the failure.

      Parameters

      • mat: IMatrix44

        The 4x4 matrix containing rotation information

      Returns Quaternion

      A quaternion representing the same rotation as the matrix, or the identity quaternion if the rotation cannot be extracted

    • Creates a quaternion from a 4x4 rotation matrix and stores it in the output parameter.

      If the rotation cannot be extracted, the output quaternion is set to the identity quaternion instead of being filled with Infinity/NaN. Use Quaternion.tryFromMatrixTo when the caller needs to detect the failure.

      Parameters

      Returns IMutableQuaternion

      The output quaternion containing the extracted rotation, or the identity quaternion if the rotation cannot be extracted

    • Creates a quaternion representing the rotation from one vector to another (static version).

      Parameters

      • from: IVector3

        The starting direction vector

      • to: IVector3

        The target direction vector

      Returns Quaternion

      A normalized quaternion representing the rotation

    • Gets the rotation angle (0 to π) represented by a quaternion.

      Parameters

      • q: IQuaternion

        The quaternion to analyze (assumed to be normalized)

      Returns number

      The rotation angle in radians

    • Computes the inverse of a quaternion. For a unit quaternion, the inverse is the conjugate divided by the squared magnitude.

      Parameters

      Returns IQuaternion

      The inverted quaternion, or zero quaternion if input has zero length

    • Creates a quaternion that looks in the specified forward direction using default up vector (0, 1, 0).

      If the direction is degenerate (zero length), an identity quaternion is returned instead of a quaternion filled with Infinity/NaN. Use Quaternion.tryLookForward when the caller needs to detect the failure.

      Parameters

      • forward: IVector3

        The forward direction vector

      Returns Quaternion

      A quaternion representing the look rotation, or the identity quaternion if the direction is degenerate

    • Creates a quaternion that looks in the specified forward direction with a custom up vector.

      If the directions are degenerate (zero length, or forward parallel to up), an identity quaternion is returned instead of a quaternion filled with Infinity/NaN. Use Quaternion.tryLookForwardAccordingToThisUp when the caller needs to detect the failure.

      Parameters

      • forward: IVector3

        The forward direction vector

      • up: IVector3

        The up direction vector

      Returns IQuaternion

      A quaternion representing the look rotation with the specified up vector, or the identity quaternion if the directions are degenerate

    • Creates a quaternion that rotates from one direction to another.

      Parameters

      • fromDirection: IVector3

        The initial direction vector

      • toDirection: IVector3

        The target direction vector

      Returns IQuaternion

      A quaternion representing the rotation from fromDirection to toDirection

    • Normalizes a quaternion to unit length. A zero-length quaternion is normalized to the identity quaternion (an error is logged) instead of becoming Infinity/NaN.

      Parameters

      Returns Quaternion

      A new normalized quaternion

    • Performs spherical linear interpolation (SLERP) between two quaternions. SLERP provides smooth rotation interpolation that maintains constant angular velocity.

      Parameters

      • l_quat: IQuaternion

        The starting quaternion

      • r_quat: IQuaternion

        The ending quaternion

      • ratio: number

        The interpolation parameter (0.0 = l_quat, 1.0 = r_quat)

      Returns IQuaternion

      The interpolated quaternion

    • Attempts to create a quaternion from an axis-angle representation.

      Returns null when the axis has zero length (or contains non-finite values), because such a rotation is undefined.

      Parameters

      • vec: IVector3

        The rotation axis (will be normalized internally)

      • radian: number

        The rotation angle in radians

      Returns Quaternion | null

      A quaternion representing the rotation around the given axis, or null

    • Attempts to create 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 | null

      A quaternion representing the same rotation as the matrix, or null if the rotation cannot be extracted (zero-length basis vector, numerically singular linear part, or non-finite values)

    • Attempts to create a quaternion from a 4x4 rotation matrix and stores it in the output parameter. The output quaternion is left untouched when the rotation cannot be extracted.

      Parameters

      Returns boolean

      True if the quaternion could be extracted, false otherwise

    • Attempts to create a quaternion that looks in the specified forward direction using default up vector (0, 1, 0).

      Parameters

      • forward: IVector3

        The forward direction vector

      Returns Quaternion | null

      A quaternion representing the look rotation, or null if the direction is degenerate

    • Attempts to create a quaternion that looks in the specified forward direction with a custom up vector.

      Returns null when either direction has zero length or when the forward and up directions are parallel, because the rotation basis cannot be built.

      Parameters

      • forward: IVector3

        The forward direction vector

      • up: IVector3

        The up direction vector

      Returns Quaternion | null

      A quaternion representing the look rotation, or null