Quat:normalize
methodQuat:normalize() -> QuatUnit-length quaternion. Raises if q is zero-length / non-finite; use normalize_or or try_normalize for a fallback.
handle16 methods, 4 fields, 1 operator
A rotation quaternion (radians). Construct with datumhue. etc.
datumhue.math.quat.identity, datumhue.math.quat.from_euler, datumhue.math.quat.from_axis_angle , datumhue.math.quat.from_rotation_x , datumhue.math.quat.from_rotation_y , datumhue.math.quat.from_rotation_z , datumhue.math.quat.from_rotation_arc , datumhue.math.quat.from_scaled_axis and 4 moredatumhue.physics.shapecast, datumhue.voxel.new, Scene:cube, Scene:sphere, Scene:plane, Scene:cylinder, Scene:capsule, Scene:torus and 9 moreQuat * Quat | Vec3 -> Quat | Vec3 Compose with another quaternion (q * q), or rotate a vector (q * vec3).The examples on this page start from:
local quarter = datumhue.math.quat.from_rotation_y(math.pi / 2)| Field | Type | Access | Description |
|---|---|---|---|
x | number | read-only | X component. |
y | number | read-only | Y component. |
z | number | read-only | Z component. |
w | number | read-only | W (scalar) component. |
Quat:normalize() -> QuatUnit-length quaternion. Raises if q is zero-length / non-finite; use normalize_or or try_normalize for a fallback.
Unit-length quaternion, or fallback if q is zero-length / non-finite.
Quat:try_normalize() -> Quat?Unit-length quaternion, or nil if q is zero-length / non-finite.
Quat:inverse() -> QuatInverse rotation.
Quat:conjugate() -> QuatConjugate (-x, -y, -z, w).
Quat:dot(o: Quat) -> numberDot product (cosine of the angle between the rotations).
Quat:length() -> numberMagnitude.
Quat:angle_between(o: Quat) -> numberAngle in radians between two rotations.
Spherical interpolation toward o by t.
-- Halfway from no turn to a quarter turn is an eighth turn.
local none = datumhue.math.quat.identity()
local half = none:slerp(quarter, 0.5)
print(string.format("%.4f", half:angle_between(none))) --> 0.7854Normalized linear interpolation toward o by t, along the shorter arc. t outside 0..1 extrapolates, and the result is renormalized so it stays a unit rotation.
Quat:is_normalized() -> booleanWhether the quaternion is unit length.
Quat:to_euler() -> Vec3Euler angles (radians, XYZ order) as a vec3.
-- Radians about X, Y and Z, as from_euler takes them.
local q = datumhue.math.quat.from_euler(0.1, 0.2, 0.3)
local e = q:to_euler()
print(string.format("%.2f %.2f %.2f", e.x, e.y, e.z)) --> 0.10 0.20 0.30Quat:to_scaled_axis() -> Vec3Scaled-axis form (axis * angle) — the inverse of quat.from_scaled_axis.
Quat:to_array() -> number[]Components as an {x, y, z, w} array.
Quat:to_axis_angle() -> Vec3, numberReturn the rotation axis (unit vec3) and angle (radians) as two values.
local axis, angle = quarter:to_axis_angle()
print(axis) --> vec3(0.0, 1.0, 0.0)
print(string.format("%.4f", angle)) --> 1.5708Quat:unpack() -> number, number, number, numberReturn the x, y, z and w components as four values.
-- x, y and z first, w last.
local x, y, z, w = datumhue.math.quat.identity():unpack()
print(x, y, z, w) --> 0.0 0.0 0.0 1.0