pub fn from_euler_angles<T>(
rt: RotationType,
rs: RotationSequence,
angles: Vector3<T>,
) -> Quaternion<T>where
T: Float,Expand description
Converts a Euler Angles into a Versor.
This function requires two parameters to fully define the rotation:
RotationType: Specifies whether the rotation is Intrinsic or Extrinsic.RotationSequence: Defines the three-axis sequence (e.g., XYZ, ZYX, XZX, …).
The input angles array must contain the three angles in radians,
corresponding to the specified rotation sequence: angles[0] -> angles[1] -> angles[2].
(Each angle should be within the range: [-2*PI, 2*PI]).
§Examples
use quaternion_core::{RotationType::*, RotationSequence::XYZ};
let angles = [PI/6.0, 1.6*PI, -PI/4.0];
let v = [1.0, 0.5, -0.4];
// Quaternions representing rotation around each axis.
let x = from_axis_angle([1.0, 0.0, 0.0], angles[0]);
let y = from_axis_angle([0.0, 1.0, 0.0], angles[1]);
let z = from_axis_angle([0.0, 0.0, 1.0], angles[2]);
// ---- Intrinsic (X-Y-Z) ---- //
// These represent the same rotation.
let q_in = mul( mul(x, y), z );
let e2q_in = from_euler_angles(Intrinsic, XYZ, angles);
// Confirmation
let a_in = point_rotation(q_in, v);
let b_in = point_rotation(e2q_in, v);
assert!( (a_in[0] - b_in[0]).abs() < 1e-12 );
assert!( (a_in[1] - b_in[1]).abs() < 1e-12 );
assert!( (a_in[2] - b_in[2]).abs() < 1e-12 );
// ---- Extrinsic (X-Y-Z) ---- //
// These represent the same rotation.
let q_ex = mul( mul(z, y), x );
let e2q_ex = from_euler_angles(Extrinsic, XYZ, angles);
// Confirmation
let a_ex = point_rotation(q_ex, v);
let b_ex = point_rotation(e2q_ex, v);
assert!( (a_ex[0] - b_ex[0]).abs() < 1e-12 );
assert!( (a_ex[1] - b_ex[1]).abs() < 1e-12 );
assert!( (a_ex[2] - b_ex[2]).abs() < 1e-12 );