Math module

get_rotation

procedure · 1 overloadSource

Extracts a unit quaternion from the 3x3 part of a rotation matrix. The matrix must be a pure rotation (orthonormal, determinant 1); a scale or a reflection gives a meaningless result. The sign of the quaternion is not determined (q and -q are the same rotation).

ExampleOpen in playground ↗
q: Quaternion;
set_from_axis_and_angle(*q, xyz(1, 0, 0), 0.5);
back := get_rotation(rotation_matrix(Matrix3, q));
assert(abs(dot_product(q, back)) > 0.9999);
get_rotation :: (m: $T/interface AnyMatrix3) -> Quaternion

The quaternion for the rotation in the upper-left 3x3 of m. The matrix is expected to be a pure rotation.

Parameters

m: $T/interface AnyMatrix3
the matrix to read.

Returns

See also