Function to_axis_angle

Source
pub fn to_axis_angle<T>(q: Quaternion<T>) -> (Vector3<T>, T)
where T: Float,
Expand description

Calculate the rotation axis (unit vector) and the rotation angle[rad] around the axis from the Versor.

If identity quaternion is entered, angle returns zero and the axis returns a zero vector.

Range of angle: (-pi, pi]

Because this function returns a normalized rotation axis, when the norm of the vector part of Versor is zero, a singularity occurs and accuracy decreases. Therefore, if you want to use the calculated angle and axis as scale(angle, axis), it is better to use the to_rotation_vector function. The to_rotation_vector function can be calculated without singularities.

ยงExamples

let axis_ori = [0.0, 1.0, 2.0];
let angle_ori = PI / 2.0;
let q = from_axis_angle(axis_ori, angle_ori);
 
let (axis, angle) = to_axis_angle(q);
 
assert!( (axis_ori[0] - axis[0]).abs() < 1e-12 );
assert!( (axis_ori[0] - axis[0]).abs() < 1e-12 );
assert!( (axis_ori[0] - axis[0]).abs() < 1e-12 );
assert!( (angle_ori - angle).abs() < 1e-12 );