to_dcm

Function to_dcm 

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

Converts a Versor into a Direction Cosine Matrix (DCM).

By default, the output DCM represents a Point Rotation (Frame Fixed), which rotates a vector v by the quaternion operation q v q*.

If you need a DCM that represents a Frame Rotation (Point Fixed) (the rotation q* v q), you must take the conjugate of the Versor:

// This DCM represents the Frame Rotation.
let dcm = to_dcm( conj(q) );

ยงExamples

// Make these as you like.
let v = [1.0, 0.5, -8.0];
let q = from_axis_angle([0.2, 1.0, -2.0], PI/4.0);
 
// --- Point rotation --- //
{
    let m = to_dcm(q);
 
    let rm = matrix_product(m, v);
    let rq = point_rotation(q, v);
    assert!( (rm[0] - rq[0]).abs() < 1e-12 );
    assert!( (rm[1] - rq[1]).abs() < 1e-12 );
    assert!( (rm[2] - rq[2]).abs() < 1e-12 );
}
 
// --- Frame rotation --- //
{
    let m = to_dcm( conj(q) );
 
    let rm = matrix_product(m, v);
    let rq = frame_rotation(q, v);
    assert!( (rm[0] - rq[0]).abs() < 1e-12 );
    assert!( (rm[1] - rq[1]).abs() < 1e-12 );
    assert!( (rm[2] - rq[2]).abs() < 1e-12 );
}