NumCpp  2.8.0
A Templatized Header Only C++ Implementation of the Python NumPy Library
DCM.hpp
Go to the documentation of this file.
1 #pragma once
29 
30 #include "NumCpp/Functions/dot.hpp"
32 #include "NumCpp/Linalg/det.hpp"
33 #include "NumCpp/NdArray.hpp"
36 #include "NumCpp/Vector/Vec3.hpp"
37 
38 namespace nc
39 {
40  namespace rotations
41  {
42  //================================================================================
44  class DCM
45  {
46  public:
47  //============================================================================
48  // Method Description:
57  static NdArray<double> eulerAngles(double roll, double pitch, double yaw)
58  {
59  return Quaternion(roll, pitch, yaw).toDCM();
60  }
61 
62  //============================================================================
63  // Method Description:
71  {
72  return Quaternion(angles).toDCM();
73  }
74 
75  //============================================================================
76  // Method Description:
84  static NdArray<double> eulerAxisAngle(const NdArray<double>& inAxis, double inAngle)
85  {
86  return Quaternion(inAxis, inAngle).toDCM();
87  }
88 
89  //============================================================================
90  // Method Description:
98  static NdArray<double> eulerAxisAngle(const Vec3& inAxis, double inAngle)
99  {
100  return Quaternion(inAxis, inAngle).toDCM();
101  }
102 
103  //============================================================================
104  // Method Description:
111  static bool isValid(const NdArray<double>& inArray)
112  {
113  const Shape inShape = inArray.shape();
114  return inShape.rows == inShape.cols &&
115  utils::essentiallyEqual(round(linalg::det<double>(inArray), 2), 1.0) &&
116  utils::essentiallyEqual(round(linalg::det<double>(inArray.transpose()), 2), 1.0);
117  }
118 
119  //============================================================================
120  // Method Description:
126  static double roll(const NdArray<double>& dcm)
127  {
128  return Quaternion(dcm).roll();
129  }
130 
131  //============================================================================
132  // Method Description:
138  static double pitch(const NdArray<double>& dcm)
139  {
140  return Quaternion(dcm).pitch();
141  }
142 
143  //============================================================================
144  // Method Description:
150  static double yaw(const NdArray<double>& dcm)
151  {
152  return Quaternion(dcm).yaw();
153  }
154 
155  //============================================================================
156  // Method Description:
163  static NdArray<double> xRotation(double inAngle)
164  {
165  return DCM::eulerAxisAngle(Vec3{ 1.0, 0.0, 0.0 }, inAngle);
166  }
167 
168  //============================================================================
169  // Method Description:
176  static NdArray<double> yRotation(double inAngle)
177  {
178  return DCM::eulerAxisAngle(Vec3{ 0.0, 1.0, 0.0 }, inAngle);
179  }
180 
181  //============================================================================
182  // Method Description:
189  static NdArray<double> zRotation(double inAngle)
190  {
191  return DCM::eulerAxisAngle(Vec3{ 0.0, 0.0, 1.0 }, inAngle);
192  }
193  };
194  } // namespace rotations
195 } // namespace nc
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4276
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4650
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:50
Factory methods for generating direction cosine matrices and vectors.
Definition: DCM.hpp:45
static NdArray< double > eulerAxisAngle(const Vec3 &inAxis, double inAngle)
Definition: DCM.hpp:98
static double pitch(const NdArray< double > &dcm)
Definition: DCM.hpp:138
static NdArray< double > eulerAngles(double roll, double pitch, double yaw)
Definition: DCM.hpp:57
static NdArray< double > xRotation(double inAngle)
Definition: DCM.hpp:163
static NdArray< double > eulerAngles(const NdArray< double > &angles)
Definition: DCM.hpp:70
static NdArray< double > yRotation(double inAngle)
Definition: DCM.hpp:176
static NdArray< double > zRotation(double inAngle)
Definition: DCM.hpp:189
static bool isValid(const NdArray< double > &inArray)
Definition: DCM.hpp:111
static double roll(const NdArray< double > &dcm)
Definition: DCM.hpp:126
static NdArray< double > eulerAxisAngle(const NdArray< double > &inAxis, double inAngle)
Definition: DCM.hpp:84
static double yaw(const NdArray< double > &dcm)
Definition: DCM.hpp:150
Holds a unit quaternion.
Definition: Quaternion.hpp:58
double roll() const noexcept
Definition: Quaternion.hpp:353
double yaw() const noexcept
Definition: Quaternion.hpp:546
double pitch() const noexcept
Definition: Quaternion.hpp:333
NdArray< double > toDCM() const
Definition: Quaternion.hpp:488
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:51
Definition: Coordinate.hpp:45
dtype round(dtype inValue, uint8 inDecimals=0)
Definition: round.hpp:45