datumhue.math.quat.identity
functiondatumhue.math.quat.identity() -> QuatThe identity rotation (no rotation).
namespaceQuaternions9 functions
Construct rotation quaternions (angles in radians).
The examples on this page start from:
local x_axis = datumhue.math.vec3(1, 0, 0)datumhue.math.quat.identity() -> QuatThe identity rotation (no rotation).
datumhue.math.quat.from_euler(x: number, y: number, z: number) -> QuatRotation from XYZ Euler angles (radians).
-- Angles in radians about X, Y and Z: a quarter turn about +Y
-- takes +X to -Z.
local q = datumhue.math.quat.from_euler(0, math.pi / 2, 0)
print((q * x_axis):round()) --> vec3(0.0, 0.0, -1.0)Rotation of angle radians around axis (normalized). Raises if axis is zero-length / non-finite.
-- The axis is normalized; the angle is in radians.
local up = datumhue.math.vec3(0, 2, 0)
local q = datumhue.math.quat.from_axis_angle(up, math.pi / 2)
print((q * x_axis):round()) --> vec3(0.0, 0.0, -1.0)datumhue.math.quat.from_rotation_x(angle: number) -> QuatRotation of angle radians around the X axis.
datumhue.math.quat.from_rotation_y(angle: number) -> QuatRotation of angle radians around the Y axis.
datumhue.math.quat.from_rotation_z(angle: number) -> QuatRotation of angle radians around the Z axis.
Minimal rotation taking unit vector from to unit to. Raises if either is zero-length / non-finite.
-- The shortest turn that takes +X onto +Y.
local y_axis = datumhue.math.vec3(0, 1, 0)
local q = datumhue.math.quat.from_rotation_arc(x_axis, y_axis)
print((q * x_axis):round()) --> vec3(0.0, 1.0, 0.0)Rotation about v's direction by |v| radians (the scaled-axis form). Zero v yields the identity rotation.
-- The vector's length is the angle: pi / 2 radians about +Z.
local spin = datumhue.math.vec3(0, 0, math.pi / 2)
local q = datumhue.math.quat.from_scaled_axis(spin)
print((q * x_axis):round()) --> vec3(0.0, 1.0, 0.0)datumhue.math.quat.from_array(a: number[]) -> QuatQuat from a raw {x, y, z, w} array (not re-normalized; the inverse of quat:to_array).
-- Components in x, y, z, w order, kept as given.
local raw = datumhue.math.quat.from_array({ 0, 0, 0, 2 })
print(raw:length()) --> 2.0
print(raw:normalize()) --> quat(0.0, 0.0, 0.0, 1.0)