Direction Cosine Matrices

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:

DCM{T} = SMatrix{3,3,T,9}

which means that DCM 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:

julia> DCM(I)  # Create a Boolean DCM, this can be used to save space.
3×3 StaticArrays.SArray{Tuple{3,3},Bool,2,9}:
  true  false  false
 false   true  false
 false  false   true

julia> DCM(1I)  # Create an Integer DCM.
3×3 StaticArrays.SArray{Tuple{3,3},Int64,2,9}:
 1  0  0
 0  1  0
 0  0  1

julia> DCM(1.f0I) # Create a Float32 DCM.
3×3 StaticArrays.SArray{Tuple{3,3},Float32,2,9}:
 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.
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
 1.0  0.0  0.0
 0.0  1.0  0.0
 0.0  0.0  1.0
julia> DCM([-1 0 0; 0 -1 0; 0 0 1])
3×3 StaticArrays.SArray{Tuple{3,3},Int64,2,9}:
 -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])
3×3 StaticArrays.SArray{Tuple{3,3},Float32,2,9}:
 -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])
3×3 StaticArrays.SArray{Tuple{3,3},Float64,2,9}:
 -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 an Static Matrix (SMatrix), then all the operations available for general matrices in Julia are also available for DCMs.