xhookLua
Game

Quaternion

Rotation quaternion (x, y, z, w); methods return new quaternions.

Methods

Quaternion

Quaternion([x=0, y=0, z=0, w=1]) -> Quaternion
NameTypeDescription
xoptionalnumberDefault 0.
yoptionalnumberDefault 0.
zoptionalnumberDefault 0.
woptionalnumberScalar 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
NameTypeDescription
anglesAngleDegrees; 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 -> number

Component fields, read and write.

Assigning any other field raises an error.

q:length

q:length() -> number

Magnitude; 1 for a pure rotation.

Returns sqrt(xยฒ+yยฒ+zยฒ+wยฒ)

q:normalize

q:normalize() -> Quaternion

Copy scaled to length 1.

A zero-length quaternion comes back unchanged.

q:conjugate

q:conjugate() -> Quaternion

Inverse rotation for a unit quaternion.

Returns (-x, -y, -z, w)

q:dot

q:dot(other) -> number
NameType
otherQuaternion

Dot product, near ยฑ1 when rotations match.

q:mul

q:mul(other) -> Quaternion
NameTypeDescription
otherQuaternionRight-hand quaternion.

Hamilton product: applies other first, then q.

Returns q * other

a * b

a * b -> Quaternion
NameType
aQuaternion
bQuaternion

Same as q:mul.

Both operands must be Quaternions; use q:rotate(v) for vectors.

q:rotate

q:rotate(v) -> Vector
NameType
vVector

Rotates a vector; assumes q is unit length.

Returns Rotated copy

q:to_angles

q:to_angles() -> Angle

Converts back to Euler angles.

Returns Pitch, yaw, roll in degrees

q:slerp

q:slerp(other, t) -> Quaternion
NameTypeDescription
otherQuaternionTarget rotation.
tnumber0 = q, 1 = other.

Shortest-arc spherical interpolation.

t is not clamped.

tostring(q)

tostring(q) -> string

Readable form for printing.

Returns "Quaternion(x, y, z, w)"

Quaternion ยท Lua API ยท xhook