Creates a new Quaternion_ instance.
The typed array containing the quaternion components [x, y, z, w]
Optional_options: { type: T }
Configuration object containing the typed array constructor
Protected_Internal typed array storage for quaternion components [x, y, z, w].
Protected Static Readonly_The typed array constructor used for newly created quaternions.
Gets the class name for debugging and reflection purposes.
The string "Quaternion"
Gets the w component (scalar part) of the quaternion.
The w component value
Gets the x component (i coefficient) of the quaternion.
The x component value
Gets the y component (j coefficient) of the quaternion.
The y component value
Gets the z component (k coefficient) of the quaternion.
The z component value
StaticcompositionGets the composition type for this quaternion class.
CompositionType.Vec4 indicating this is a 4-component vector
Gets the component at the specified index.
The index (0=x, 1=y, 2=z, 3=w)
The component value at the given index
Creates a deep copy of this quaternion.
A new quaternion with the same component values
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.
The quaternion to compute the dot product with
The dot product result
Converts the quaternion to a flat array representation.
An array containing [x, y, z, w] components
Checks if this quaternion is a dummy (uninitialized) quaternion.
True if the internal array has zero length, false otherwise
Checks if this quaternion is approximately equal to another quaternion within a tolerance.
The quaternion to compare with
The tolerance value (default: Number.EPSILON)
True if all components are within the tolerance, false otherwise
Checks if this quaternion is exactly equal to another quaternion.
The quaternion to compare with
True if all components are exactly equal, false otherwise
Calculates the magnitude (length) of the quaternion.
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.
The squared Euclidean norm of the quaternion
Converts the quaternion to Euler angles. The rotation order is XYZ (roll, pitch, yaw).
A new Vector3 containing the Euler angles in radians
Converts the quaternion to Euler angles and stores the result in the output vector. The rotation order is XYZ (roll, pitch, yaw).
The output vector to store the Euler angles [x, y, z]
The output vector containing the Euler angles in radians
Converts the quaternion to a string representation.
A string in the format "(x, y, z, w)"
Converts the quaternion to an approximately formatted string using financial precision.
A formatted string with components separated by spaces and ending with newline
Transforms a 3D vector by the inverse of this quaternion rotation.
The vector to transform
A new transformed vector
Transforms a 3D vector by this quaternion rotation and stores the result in the output parameter.
The vector to transform
The output vector to store the result
The output vector containing the transformed result
StaticaddAdds two quaternions component-wise.
The left quaternion
The right quaternion
The sum of the two quaternions
StaticaddAdds two quaternions component-wise and stores the result in the output parameter.
The left quaternion
The right quaternion
The output quaternion to store the result
The output quaternion containing the sum
StaticaxisCreates 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.
The rotation axis (will be normalized internally)
The rotation angle in radians
A quaternion representing the rotation around the given axis, or the identity quaternion if the axis is degenerate
StaticclampClamps the rotation angle of a quaternion to a maximum value. If the quaternion's rotation angle exceeds thetaMax, it scales the rotation down.
The quaternion to clamp
The maximum allowed rotation angle in radians
A quaternion with rotation angle clamped to thetaMax
StaticdivideDivides a quaternion by a scalar value.
If the divisor is zero, all components are set to 0 and an error is logged
instead of producing Infinity/NaN.
The quaternion to divide
The scalar value to divide by
A new quaternion with all components divided by the scalar
StaticdivideDivides 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.
The quaternion to divide
The scalar value to divide by
The output quaternion to store the result
The output quaternion containing the divided result
StaticdummyCreates a dummy quaternion with zero-length internal array. Used as a placeholder or uninitialized quaternion.
A new dummy quaternion
StaticfromCreates a quaternion from an axis-angle representation.
The rotation axis vector
The rotation angle in radians
A new quaternion representing the rotation
StaticfromCreates a quaternion from an axis-angle representation and stores it in the output parameter.
The rotation axis vector
The rotation angle in radians
The output quaternion to store the result
The output quaternion containing the rotation
StaticfromCreates a quaternion from individual component values.
The x component
The y component
The z component
The w component
A new quaternion with the specified components
StaticfromCreates a quaternion from a variable-length array (taking first 4 elements).
The array containing quaternion components
A new quaternion with the first 4 components copied
StaticfromCreates a quaternion from a 4-element array.
The array containing [x, y, z, w] components
A new quaternion with copied components
StaticfromCreates a quaternion from a log quaternion representation.
The log quaternion to convert
A new quaternion converted from log space
StaticfromCreates a quaternion by copying from another quaternion.
The quaternion to copy from
A new quaternion with copied components
StaticfromCreates a quaternion by copying from a 4D vector.
The 4D vector to copy from
A new quaternion with components copied from the vector
StaticfromCreates 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.
The 4x4 matrix containing rotation information
A quaternion representing the same rotation as the matrix, or the identity quaternion if the rotation cannot be extracted
StaticfromCreates 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.
The 4x4 matrix containing rotation information
The output quaternion to store the result
The output quaternion containing the extracted rotation, or the identity quaternion if the rotation cannot be extracted
StaticfromCreates a quaternion from a position vector, with w component set to 0. This is useful for representing pure translations in quaternion form.
The position vector
A quaternion with xyz from the vector and w=0
StaticfromCreates a quaternion representing the rotation from one vector to another (static version).
A normalized quaternion representing the rotation
StaticfromCreates a quaternion representing the rotation from one vector to another and stores it in the output parameter.
The starting direction vector
The target direction vector
The output quaternion to store the result
The output quaternion containing the normalized rotation
StaticfromCreates a quaternion that directly uses the given typed array (no copy).
The typed array containing quaternion components
A new quaternion using the provided array
StaticgetGets the rotation angle (0 to π) represented by a quaternion.
The quaternion to analyze (assumed to be normalized)
The rotation angle in radians
StaticidentityCreates an identity quaternion representing no rotation. The identity quaternion is (0, 0, 0, 1) in (x, y, z, w) format.
A new identity quaternion
StaticinvertComputes the inverse of a quaternion. For a unit quaternion, the inverse is the conjugate divided by the squared magnitude.
The quaternion to invert
The inverted quaternion, or zero quaternion if input has zero length
StaticinvertComputes the inverse of a quaternion and stores the result in the output parameter.
The quaternion to invert
The output quaternion to store the result
The output quaternion containing the inverted result
StaticlerpPerforms linear interpolation (LERP) between two quaternions. Note: LERP does not maintain constant angular velocity like SLERP.
The starting quaternion
The ending quaternion
The interpolation parameter (0.0 = l_quat, 1.0 = r_quat)
The linearly interpolated quaternion
StaticlerpPerforms linear interpolation (LERP) and stores the result in the output parameter.
The starting quaternion
The ending quaternion
The interpolation parameter (0.0 = l_quat, 1.0 = r_quat)
The output quaternion to store the result
The output quaternion containing the interpolated result
StaticlookCreates 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.
The forward direction vector
A quaternion representing the look rotation, or the identity quaternion if the direction is degenerate
StaticlookCreates 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.
A quaternion representing the look rotation with the specified up vector, or the identity quaternion if the directions are degenerate
StaticlookCreates a quaternion that rotates from one direction to another.
A quaternion representing the rotation from fromDirection to toDirection
StaticmultiplyMultiplies two quaternions using Hamilton's quaternion multiplication. This combines the rotations represented by both quaternions. Note: Quaternion multiplication is not commutative (order matters).
The left quaternion
The right quaternion
The product of the two quaternions
StaticmultiplyMultiplies a quaternion by a scalar value.
The quaternion to multiply
The scalar value to multiply by
A new quaternion with all components multiplied by the scalar
StaticmultiplyMultiplies a quaternion by a scalar and stores the result in the output parameter.
The quaternion to multiply
The scalar value to multiply by
The output quaternion to store the result
The output quaternion containing the scaled result
StaticmultiplyMultiplies two quaternions and stores the result in the output parameter.
The left quaternion
The right quaternion
The output quaternion to store the result
The output quaternion containing the product
StaticnormalizeNormalizes a quaternion to unit length.
A zero-length quaternion is normalized to the identity quaternion (an error
is logged) instead of becoming Infinity/NaN.
The quaternion to normalize
A new normalized quaternion
StaticnormalizeNormalizes a quaternion to unit length and stores the result in the output parameter.
The quaternion to normalize
The output quaternion to store the result
The output quaternion containing the normalized result
StaticqlerpPerforms spherical linear interpolation (SLERP) between two quaternions. SLERP provides smooth rotation interpolation that maintains constant angular velocity.
The starting quaternion
The ending quaternion
The interpolation parameter (0.0 = l_quat, 1.0 = r_quat)
The interpolated quaternion
StaticqlerpPerforms spherical linear interpolation (SLERP) and stores the result in the output parameter.
The starting quaternion
The ending quaternion
The interpolation parameter (0.0 = l_quat, 1.0 = r_quat)
The output quaternion to store the result
The output quaternion containing the interpolated result
StaticsubtractSubtracts the right quaternion from the left quaternion component-wise.
The left quaternion
The right quaternion
The difference of the two quaternions
StaticsubtractSubtracts two quaternions component-wise and stores the result in the output parameter.
The left quaternion
The right quaternion
The output quaternion to store the result
The output quaternion containing the difference
StatictryAttempts 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.
The rotation axis (will be normalized internally)
The rotation angle in radians
A quaternion representing the rotation around the given axis, or null
StatictryAttempts to create a quaternion from a 4x4 rotation matrix. Extracts the rotation component from the matrix and converts it to quaternion form.
The 4x4 matrix containing rotation information
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)
StatictryAttempts 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.
The 4x4 matrix containing rotation information
The output quaternion to store the result
True if the quaternion could be extracted, false otherwise
StatictryAttempts to create a quaternion that looks in the specified forward direction using default up vector (0, 1, 0).
The forward direction vector
A quaternion representing the look rotation, or null if the direction is degenerate
StatictryAttempts 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.
A quaternion representing the look rotation, or null
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
Example