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:
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:
- Identity DCM.
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
- User-defined DCM.
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
The type of the DCM will depend on the type of the input.
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.