Direction Cosine Matrices

Direction cosine matrices, or DCMs, are $3 \times 3$ matrices that represent a coordinate transformation between two orthonormal reference frames. Let those frames be right-handed, then it can be shown that this transformation is always a rotation. Thus, a DCM that rotates the reference frame $a$ into alignment with the reference frame $b$ is:

\[\mathbf{D}_{ba} = \left[\begin{matrix} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{matrix}\right]\]

In ReferenceFrameRotations.jl, a DCM is a $3 \times 3$ static matrix, i.e. it is immutable.

Initialization

Usually, a DCM is initialized by converting a more "visual" rotation representation, such as the Euler angles (see Conversions). However, it can be initialized by the following methods:

  • Identity DCM.
julia> DCM(I)  # Create a Boolean DCM, this can be used to save space.DCM{Bool}:
 1  0  0
 0  1  0
 0  0  1
julia> DCM(Int64(1)I) # Create an Integer DCM.DCM{Int64}: 1 0 0 0 1 0 0 0 1
julia> DCM(1.f0I) # Create a Float32 DCM.DCM{Float32}: 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0
julia> DCM(1.0I) # Create a Float64 DCM.DCM{Float64}: 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0
  • User-defined DCM.
julia> DCM([-1 0 0; 0 -1 0; 0 0 1])DCM{Int64}:
 -1   0  0
  0  -1  0
  0   0  1
julia> DCM([-1.f0 0.f0 0.f0; 0.f0 -1.f0 0.f0; 0.f0 0.f0 1.f0])DCM{Float32}: -1.0 0.0 0.0 0.0 -1.0 0.0 0.0 0.0 1.0
julia> DCM([-1.0 0.0 0.0; 0.0 -1.0 0.0; 0.0 0.0 1.0])DCM{Float64}: -1.0 0.0 0.0 0.0 -1.0 0.0 0.0 0.0 1.0
Note

The type of the DCM will depend on the type of the input.

Warning

This initialization method will not verify if the input data is indeed a DCM.

Operations

Since a DCM is a static matrix (<: StaticMatrix), then all the operations available for general matrices in Julia are also available for DCMs.

Orthonomalization

A DCM can be orthonormalized using the Gram-Schmidt algorithm by the function:

function orthonormalize(dcm::DCM)
julia> D = DCM([2 0 0; 0 2 0; 0 0 2])DCM{Int64}:
 2  0  0
 0  2  0
 0  0  2
julia> orthonormalize(D)DCM{Float64}: 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0
julia> D = DCM(3.0f0I);
julia> orthonormalize(D)DCM{Float32}: 1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0
julia> D = DCM(1, 1, 2, 2, 3, 3, 4, 4, 5);
julia> Dn = orthonormalize(D)DCM{Float64}: 0.408248 0.123091 0.904534 0.408248 0.86164 -0.301511 0.816497 -0.492366 -0.301511
julia> Dn * Dn'DCM{Float64}: 1.0 -2.87528e-16 -9.03184e-16 -2.87528e-16 1.0 3.4516e-16 -8.47673e-16 3.4516e-16 1.0
Warning

This function does not check if the columns of the input matrix span a three-dimensional space. If not, then the returned matrix should have NaN. Notice, however, that such input matrix is not a valid direction cosine matrix.