to_axis_angle

Function to_axis_angle 

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

Extracts the rotation axis and the rotation angle around the axis from the Versor.

§Returns

The function returns a tuple (axis, angle), where:

  • axis: The rotation axis as a unit vector (Vector3).
  • angle: The rotation angle in radians. The range is (-PI, PI].

§Special Case: Identity Quaternion

If the input is the Identity Quaternion (1.0, [0.0, 0.0, 0.0]), the function returns an angle of zero and a zero axis vector.

§Singularity

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.

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);
 
let diff = sub( normalize(axis_ori), normalize(axis) );
assert!( diff[0].abs() < 1e-12 );
assert!( diff[1].abs() < 1e-12 );
assert!( diff[2].abs() < 1e-12 );
assert!( (angle_ori - angle).abs() < 1e-12 );