quaternion
quaternion
The quaternion class represents 3D orientations (X, Y, Z, W). It provides spherical linear interpolation (slerp), Euler angle conversions in degrees, vector basis transformations, and angle measurements.
Overview
Properties (4)
| Property | Type | Summary |
|---|---|---|
w
|
number
|
The W component of the quaternion. |
x
|
number
|
The X component of the quaternion. |
y
|
number
|
The Y component of the quaternion. |
z
|
number
|
The Z component of the quaternion. |
Methods (11)
| Method Signature | Returns | Summary |
|---|---|---|
quaternion:angleTo(other)
|
number
|
Calculates the rotational angle in degrees between two quaternions. |
quaternion:basisXform(v)
|
vector3
|
Rotates a 3D vector by this quaternion. |
quaternion:dot(other)
|
number
|
Calculates the dot product with another quaternion. |
quaternion.fromEuler(euler)
|
quaternion
|
Creates a quaternion from Euler angles in degrees. |
quaternion:getEuler()
|
vector3
|
Converts the quaternion into Euler angles in degrees. |
quaternion.identity()
|
quaternion
|
Returns the identity quaternion. |
quaternion:inverse()
|
quaternion
|
Returns the inverse rotation quaternion. |
quaternion:length()
|
number
|
Calculates the length of the quaternion. |
quaternion.new(x, y, z, w)
|
quaternion
|
Constructs a quaternion from raw components. |
quaternion:normalized()
|
quaternion
|
Returns the normalized unit quaternion. |
quaternion:slerp(to, weight)
|
quaternion
|
Spherical linear interpolation between two quaternions. |
Detailed Reference
quaternion.wnumberThe W component.
Reads or writes the W component.
quaternion.xnumberThe X component.
Reads or writes the X component.
quaternion.ynumberThe Y component.
Reads or writes the Y component.
quaternion.znumberThe Z component.
Reads or writes the Z component.
quaternion:angleTo(other)| Parameter | Type | Default | Description |
|---|---|---|---|
other | quaternion | The target quaternion. |
numberAngle in degrees between orientations.
Returns the minimum rotation angle required to rotate from this to other, in degrees.
quaternion:basisXform(v)| Parameter | Type | Default | Description |
|---|---|---|---|
v | vector3 | Vector to rotate. |
vector3Rotated 3D vector.
Applies the quaternion orientation to a 3D vector.
quaternion:dot(other)| Parameter | Type | Default | Description |
|---|---|---|---|
other | quaternion | Other quaternion. |
numberDot product.
Calculates the 4D dot product between orientations.
quaternion.fromEuler(euler)| Parameter | Type | Default | Description |
|---|---|---|---|
euler | vector3 | Euler rotation angles in degrees. |
quaternionResulting quaternion.
Converts Euler rotation angles (in degrees) into a quaternion orientation.
quaternion:getEuler()vector3Euler angles in degrees.
Extracts Euler rotation angles (X, Y, Z in degrees) representing this orientation.
quaternion.identity()quaternionIdentity quaternion (0, 0, 0, 1).
Returns the neutral identity orientation with no rotation.
quaternion:inverse()quaternionInverted quaternion.
Calculates the inverted rotation.
quaternion:length()numberMagnitude of quaternion.
Calculates sqrt(x^2 + y^2 + z^2 + w^2).
quaternion.new(x, y, z, w)| Parameter | Type | Default | Description |
|---|---|---|---|
x | number | X component. | |
y | number | Y component. | |
z | number | Z component. | |
w | number | W component. |
quaternionNewly constructed quaternion.
Creates a quaternion with explicit components.
quaternion:normalized()quaternionUnit quaternion.
Normalizes the quaternion to length 1.0.
quaternion:slerp(to, weight)| Parameter | Type | Default | Description |
|---|---|---|---|
to | quaternion | Target orientation. | |
weight | number | Interpolation factor between 0.0 and 1.0. |
quaternionInterpolated orientation.
Smoothly interpolates rotation between this and to by weight.
local mid = q1:slerp(q2, 0.5)