NumCpp  2.4.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:
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
nc::rotations::DCM::eulerAngles
static NdArray< double > eulerAngles(const NdArray< double > &angles)
Definition: DCM.hpp:72
nc::rotations::DCM::isValid
static bool isValid(const NdArray< double > &inArray)
Definition: DCM.hpp:117
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4356
nc::rotations::Quaternion
Holds a unit quaternion.
Definition: Quaternion.hpp:57
nc::rotations::DCM::eulerAxisAngle
static NdArray< double > eulerAxisAngle(const NdArray< double > &inAxis, double inAngle)
Definition: DCM.hpp:87
nc::rotations::Quaternion::pitch
double pitch() const noexcept
Definition: Quaternion.hpp:342
nc::rotations::Quaternion::toDCM
NdArray< double > toDCM() const
Definition: Quaternion.hpp:505
nc::utils::essentiallyEqual
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:52
nc::rotations::Quaternion::yaw
double yaw() const noexcept
Definition: Quaternion.hpp:566
nc::rotations::DCM::xRotation
static NdArray< double > xRotation(double inAngle)
Definition: DCM.hpp:171
nc::rotations::DCM::pitch
static double pitch(const NdArray< double > &dcm)
Definition: DCM.hpp:144
nc::rotations::Quaternion::roll
double roll() const noexcept
Definition: Quaternion.hpp:362
Quaternion.hpp
nc::NdArray::transpose
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4652
nc::NdArray< double >
NdArray.hpp
dot.hpp
Vec3.hpp
nc::Shape
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:40
nc::Shape::cols
uint32 cols
Definition: Core/Shape.hpp:45
nc::rotations::DCM
Factory methods for generating direction cosine matrices and vectors.
Definition: DCM.hpp:44
nc::rotations::DCM::yRotation
static NdArray< double > yRotation(double inAngle)
Definition: DCM.hpp:186
nc::rotations::DCM::zRotation
static NdArray< double > zRotation(double inAngle)
Definition: DCM.hpp:201
nc
Definition: Coordinate.hpp:44
det.hpp
nc::Shape::rows
uint32 rows
Definition: Core/Shape.hpp:44
essentiallyEqual.hpp
nc::round
dtype round(dtype inValue, uint8 inDecimals=0)
Definition: round.hpp:46
nc::rotations::DCM::yaw
static double yaw(const NdArray< double > &dcm)
Definition: DCM.hpp:156
nc::rotations::DCM::eulerAxisAngle
static NdArray< double > eulerAxisAngle(const Vec3 &inAxis, double inAngle)
Definition: DCM.hpp:102
nc::Vec3
Holds a 3D vector.
Definition: Vec3.hpp:49
nc::rotations::DCM::eulerAngles
static NdArray< double > eulerAngles(double roll, double pitch, double yaw)
Definition: DCM.hpp:58
nc::rotations::DCM::roll
static double roll(const NdArray< double > &dcm)
Definition: DCM.hpp:132
round.hpp