Vulcan
Aerospace Engineering Utilities Built on Janus
Loading...
Searching...
No Matches
DCMUtils.hpp
Go to the documentation of this file.
1// Vulcan DCM Utilities
2// Direction Cosine Matrix utilities: skew, composition, small-angle
3// approximation
4#pragma once
5
7
8#include <janus/math/Arithmetic.hpp>
9#include <janus/math/Linalg.hpp>
10#include <janus/math/Logic.hpp>
11#include <janus/math/Rotations.hpp>
12#include <janus/math/Trig.hpp>
13
14namespace vulcan {
15
16// =============================================================================
17// Skew-Symmetric Matrix
18// =============================================================================
19
32template <typename Scalar> Mat3<Scalar> skew(const Vec3<Scalar> &v) {
33 Mat3<Scalar> S;
34 S(0, 0) = Scalar(0);
35 S(0, 1) = -v(2);
36 S(0, 2) = v(1);
37 S(1, 0) = v(2);
38 S(1, 1) = Scalar(0);
39 S(1, 2) = -v(0);
40 S(2, 0) = -v(1);
41 S(2, 1) = v(0);
42 S(2, 2) = Scalar(0);
43 return S;
44}
45
53template <typename Scalar> Vec3<Scalar> unskew(const Mat3<Scalar> &S) {
54 Vec3<Scalar> v;
55 v(0) = S(2, 1);
56 v(1) = S(0, 2);
57 v(2) = S(1, 0);
58 return v;
59}
60
61// =============================================================================
62// DCM Composition
63// =============================================================================
64
74template <typename Scalar>
75Mat3<Scalar> compose_dcm(const Mat3<Scalar> &R1, const Mat3<Scalar> &R2) {
76 return R2 * R1;
77}
78
92template <typename Scalar>
93Mat3<Scalar> relative_dcm(const Mat3<Scalar> &R_A, const Mat3<Scalar> &R_B) {
94 return R_B.transpose() * R_A;
95}
96
97// =============================================================================
98// Small-Angle Approximation
99// =============================================================================
100
111template <typename Scalar>
112Mat3<Scalar> dcm_from_small_angle(const Vec3<Scalar> &theta) {
113 return Mat3<Scalar>::Identity() + skew(theta);
114}
115
127template <typename Scalar>
128Vec3<Scalar> small_angle_from_dcm(const Mat3<Scalar> &R) {
129 Scalar half = Scalar(0.5);
130 Vec3<Scalar> theta;
131 theta(0) = half * (R(2, 1) - R(1, 2));
132 theta(1) = half * (R(0, 2) - R(2, 0));
133 theta(2) = half * (R(1, 0) - R(0, 1));
134 return theta;
135}
136
137// =============================================================================
138// DCM Validation
139// =============================================================================
140
151template <typename Derived>
152auto is_valid_dcm(const Eigen::MatrixBase<Derived> &R, double tol = 1e-9) {
153 return janus::is_valid_rotation_matrix(R, tol);
154}
155
156// =============================================================================
157// DCM from Principal Axis
158// =============================================================================
159
166template <typename Scalar>
167Mat3<Scalar> dcm_principal_axis(Scalar theta, int axis) {
168 return janus::rotation_matrix_3d(theta, axis);
169}
170
171} // namespace vulcan
Definition Aerodynamics.hpp:11
Mat3< Scalar > skew(const Vec3< Scalar > &v)
Definition DCMUtils.hpp:32
Vec3< Scalar > small_angle_from_dcm(const Mat3< Scalar > &R)
Definition DCMUtils.hpp:128
Mat3< Scalar > dcm_from_small_angle(const Vec3< Scalar > &theta)
Definition DCMUtils.hpp:112
Mat3< Scalar > relative_dcm(const Mat3< Scalar > &R_A, const Mat3< Scalar > &R_B)
Definition DCMUtils.hpp:93
Mat3< Scalar > compose_dcm(const Mat3< Scalar > &R1, const Mat3< Scalar > &R2)
Definition DCMUtils.hpp:75
Mat3< Scalar > dcm_principal_axis(Scalar theta, int axis)
Definition DCMUtils.hpp:167
auto is_valid_dcm(const Eigen::MatrixBase< Derived > &R, double tol=1e-9)
Definition DCMUtils.hpp:152
Vec3< Scalar > unskew(const Mat3< Scalar > &S)
Definition DCMUtils.hpp:53