NumCpp  2.5.1
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:
58  static NdArray<double> eulerAngles(double roll, double pitch, double yaw)
59  {
60  return Quaternion(roll, pitch, yaw).toDCM();
61  }
62 
63  //============================================================================
64  // Method Description:
73  {
74  return Quaternion(angles).toDCM();
75  }
76 
77  //============================================================================
78  // Method Description:
87  static NdArray<double> eulerAxisAngle(const NdArray<double>& inAxis, double inAngle)
88  {
89  return Quaternion(inAxis, inAngle).toDCM();
90  }
91 
92  //============================================================================
93  // Method Description:
102  static NdArray<double> eulerAxisAngle(const Vec3& inAxis, double inAngle)
103  {
104  return Quaternion(inAxis, inAngle).toDCM();
105  }
106 
107  //============================================================================
108  // Method Description:
117  static bool isValid(const NdArray<double>& inArray)
118  {
119  const Shape inShape = inArray.shape();
120  return inShape.rows == inShape.cols &&
121  utils::essentiallyEqual(round(linalg::det<double>(inArray), 2), 1.0) &&
122  utils::essentiallyEqual(round(linalg::det<double>(inArray.transpose()), 2), 1.0);
123  }
124 
125  //============================================================================
126  // Method Description:
132  static double roll(const NdArray<double>& dcm)
133  {
134  return Quaternion(dcm).roll();
135  }
136 
137  //============================================================================
138  // Method Description:
144  static double pitch(const NdArray<double>& dcm)
145  {
146  return Quaternion(dcm).pitch();
147  }
148 
149  //============================================================================
150  // Method Description:
156  static double yaw(const NdArray<double>& dcm)
157  {
158  return Quaternion(dcm).yaw();
159  }
160 
161  //============================================================================
162  // Method Description:
171  static NdArray<double> xRotation(double inAngle)
172  {
173  return DCM::eulerAxisAngle(Vec3{ 1.0, 0.0, 0.0 }, inAngle);
174  }
175 
176  //============================================================================
177  // Method Description:
186  static NdArray<double> yRotation(double inAngle)
187  {
188  return DCM::eulerAxisAngle(Vec3{ 0.0, 1.0, 0.0 }, inAngle);
189  }
190 
191  //============================================================================
192  // Method Description:
201  static NdArray<double> zRotation(double inAngle)
202  {
203  return DCM::eulerAxisAngle(Vec3{ 0.0, 0.0, 1.0 }, inAngle);
204  }
205  };
206  } // namespace rotations
207 } // namespace nc
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4483
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4830
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:102
static double pitch(const NdArray< double > &dcm)
Definition: DCM.hpp:144
static NdArray< double > eulerAngles(double roll, double pitch, double yaw)
Definition: DCM.hpp:58
static NdArray< double > xRotation(double inAngle)
Definition: DCM.hpp:171
static NdArray< double > eulerAngles(const NdArray< double > &angles)
Definition: DCM.hpp:72
static NdArray< double > yRotation(double inAngle)
Definition: DCM.hpp:186
static NdArray< double > zRotation(double inAngle)
Definition: DCM.hpp:201
static bool isValid(const NdArray< double > &inArray)
Definition: DCM.hpp:117
static double roll(const NdArray< double > &dcm)
Definition: DCM.hpp:132
static NdArray< double > eulerAxisAngle(const NdArray< double > &inAxis, double inAngle)
Definition: DCM.hpp:87
static double yaw(const NdArray< double > &dcm)
Definition: DCM.hpp:156
Holds a unit quaternion.
Definition: Quaternion.hpp:58
double roll() const noexcept
Definition: Quaternion.hpp:362
double yaw() const noexcept
Definition: Quaternion.hpp:566
double pitch() const noexcept
Definition: Quaternion.hpp:342
NdArray< double > toDCM() const
Definition: Quaternion.hpp:505
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:52
Definition: Coordinate.hpp:45
dtype round(dtype inValue, uint8 inDecimals=0)
Definition: round.hpp:46