Quaternion
Rotation quaternion (x, y, z, w); methods return new quaternions.
Methods
Quaternion
Quaternion([x=0, y=0, z=0, w=1]) -> Quaternion| Name | Type | Description |
|---|---|---|
| xoptional | number | Default 0. |
| yoptional | number | Default 0. |
| zoptional | number | Default 0. |
| woptional | number | Scalar component. Default 1. |
Builds from raw components; Quaternion() is the identity.
Not normalised; call :normalize() on hand-built ones.
Quaternion.from_angles
Quaternion.from_angles(angles) -> Quaternion| Name | Type | Description |
|---|---|---|
| angles | Angle | Degrees; plain tables rejected. |
Converts Euler angles to a quaternion.
Returns Unit length
q.x / q.y / q.z / q.w
q.x, q.y, q.z, q.w -> numberComponent fields, read and write.
Assigning any other field raises an error.
q:length
q:length() -> numberMagnitude; 1 for a pure rotation.
Returns sqrt(xยฒ+yยฒ+zยฒ+wยฒ)
q:normalize
q:normalize() -> QuaternionCopy scaled to length 1.
A zero-length quaternion comes back unchanged.
q:conjugate
q:conjugate() -> QuaternionInverse rotation for a unit quaternion.
Returns (-x, -y, -z, w)
q:dot
q:dot(other) -> number| Name | Type |
|---|---|
| other | Quaternion |
Dot product, near ยฑ1 when rotations match.
q:mul
q:mul(other) -> Quaternion| Name | Type | Description |
|---|---|---|
| other | Quaternion | Right-hand quaternion. |
Hamilton product: applies other first, then q.
Returns q * other
a * b
a * b -> Quaternion| Name | Type |
|---|---|
| a | Quaternion |
| b | Quaternion |
Same as q:mul.
Both operands must be Quaternions; use q:rotate(v) for vectors.
q:rotate
q:rotate(v) -> Vector| Name | Type |
|---|---|
| v | Vector |
Rotates a vector; assumes q is unit length.
Returns Rotated copy
q:to_angles
q:to_angles() -> AngleConverts back to Euler angles.
Returns Pitch, yaw, roll in degrees
q:slerp
q:slerp(other, t) -> Quaternion| Name | Type | Description |
|---|---|---|
| other | Quaternion | Target rotation. |
| t | number | 0 = q, 1 = other. |
Shortest-arc spherical interpolation.
t is not clamped.
tostring(q)
tostring(q) -> stringReadable form for printing.
Returns "Quaternion(x, y, z, w)"