pub fn from_euler_angles<T>(
rt: RotationType,
rs: RotationSequence,
angles: Vector3<T>,
) -> Quaternion<T>where
T: Float + FloatConst,
Expand description
Convert euler angles to versor.
The type of rotation (Intrinsic or Extrinsic) is specified by RotationType
enum,
and the rotation sequence (XZX, XYZ, …) is specified by RotationSequence
enum.
Each element of angles
should be specified in the range: [-2π, 2π]
.
Sequences: angles[0]
—> angles[1]
—> angles[2]
§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 );