NumCpp  2.12.1
A Templatized Header Only C++ Implementation of the Python NumPy Library
DCM.hpp
Go to the documentation of this file.
1
28#pragma once
29
32#include "NumCpp/Linalg/det.hpp"
33#include "NumCpp/NdArray.hpp"
37
39{
40 //================================================================================
42 class DCM
43 {
44 public:
45 //============================================================================
46 // Method Description:
55 static NdArray<double> eulerAngles(double roll, double pitch, double yaw)
56 {
57 return Quaternion(roll, pitch, yaw).toDCM();
58 }
59
60 //============================================================================
61 // Method Description:
69 {
70 return Quaternion(angles).toDCM();
71 }
72
73 //============================================================================
74 // Method Description:
82 static NdArray<double> eulerAxisAngle(const NdArray<double>& inAxis, double inAngle)
83 {
84 return Quaternion(inAxis, inAngle).toDCM();
85 }
86
87 //============================================================================
88 // Method Description:
96 static NdArray<double> eulerAxisAngle(const Vec3& inAxis, double inAngle)
97 {
98 return Quaternion(inAxis, inAngle).toDCM();
99 }
100
101 //============================================================================
102 // Method Description:
109 static bool isValid(const NdArray<double>& inArray)
110 {
111 const Shape inShape = inArray.shape();
112 return inShape.rows == inShape.cols &&
113 utils::essentiallyEqual(round(linalg::det<double>(inArray), 2), 1.) &&
114 utils::essentiallyEqual(round(linalg::det<double>(inArray.transpose()), 2), 1.);
115 }
116
117 //============================================================================
118 // Method Description:
124 static double roll(const NdArray<double>& dcm)
125 {
126 return Quaternion(dcm).roll();
127 }
128
129 //============================================================================
130 // Method Description:
136 static double pitch(const NdArray<double>& dcm)
137 {
138 return Quaternion(dcm).pitch();
139 }
140
141 //============================================================================
142 // Method Description:
148 static double yaw(const NdArray<double>& dcm)
149 {
150 return Quaternion(dcm).yaw();
151 }
152
153 //============================================================================
154 // Method Description:
161 static NdArray<double> xRotation(double inAngle)
162 {
163 return DCM::eulerAxisAngle(Vec3{ 1., 0., 0. }, inAngle);
164 }
165
166 //============================================================================
167 // Method Description:
174 static NdArray<double> yRotation(double inAngle)
175 {
176 return DCM::eulerAxisAngle(Vec3{ 0., 1., 0. }, inAngle);
177 }
178
179 //============================================================================
180 // Method Description:
187 static NdArray<double> zRotation(double inAngle)
188 {
189 return DCM::eulerAxisAngle(Vec3{ 0., 0., 1. }, inAngle);
190 }
191 };
192} // namespace nc::rotations
self_type transpose() const
Definition: NdArrayCore.hpp:4882
const Shape & shape() const noexcept
Definition: NdArrayCore.hpp:4511
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
uint32 rows
Definition: Core/Shape.hpp:44
uint32 cols
Definition: Core/Shape.hpp:45
Holds a 3D vector.
Definition: Vec3.hpp:51
Factory methods for generating direction cosine matrices and vectors.
Definition: DCM.hpp:43
static NdArray< double > eulerAngles(const NdArray< double > &angles)
Definition: DCM.hpp:68
static NdArray< double > eulerAxisAngle(const Vec3 &inAxis, double inAngle)
Definition: DCM.hpp:96
static NdArray< double > yRotation(double inAngle)
Definition: DCM.hpp:174
static NdArray< double > xRotation(double inAngle)
Definition: DCM.hpp:161
static NdArray< double > zRotation(double inAngle)
Definition: DCM.hpp:187
static double pitch(const NdArray< double > &dcm)
Definition: DCM.hpp:136
static bool isValid(const NdArray< double > &inArray)
Definition: DCM.hpp:109
static NdArray< double > eulerAxisAngle(const NdArray< double > &inAxis, double inAngle)
Definition: DCM.hpp:82
static double roll(const NdArray< double > &dcm)
Definition: DCM.hpp:124
static double yaw(const NdArray< double > &dcm)
Definition: DCM.hpp:148
static NdArray< double > eulerAngles(double roll, double pitch, double yaw)
Definition: DCM.hpp:55
Holds a unit quaternion.
Definition: Quaternion.hpp:56
double roll() const noexcept
Definition: Quaternion.hpp:402
double yaw() const noexcept
Definition: Quaternion.hpp:607
double pitch() const noexcept
Definition: Quaternion.hpp:370
NdArray< double > toDCM() const
Definition: Quaternion.hpp:549
Definition: DCM.hpp:39
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:49
dtype round(dtype inValue, uint8 inDecimals=0)
Definition: round.hpp:45