NumCpp  1.0
A C++ implementation of the Python Numpy library
DCM.hpp
Go to the documentation of this file.
1 #pragma once
30 
31 #include "NumCpp/Linalg/det.hpp"
32 #include "NumCpp/Functions/dot.hpp"
34 #include "NumCpp/NdArray.hpp"
37 #include "NumCpp/Vector/Vec3.hpp"
38 
39 namespace nc
40 {
41  namespace rotations
42  {
43  //================================================================================
45  class DCM
46  {
47  public:
48  //============================================================================
49  // Method Description:
59  static NdArray<double> eulerAngles(double roll, double pitch, double yaw)
60  {
61  return Quaternion(roll, pitch, yaw).toDCM();
62  }
63 
64  //============================================================================
65  // Method Description:
74  {
75  return Quaternion(angles).toDCM();
76  }
77 
78  //============================================================================
79  // Method Description:
88  static NdArray<double> eulerAxisAngle(const NdArray<double>& inAxis, double inAngle)
89  {
90  return Quaternion(inAxis, inAngle).toDCM();
91  }
92 
93  //============================================================================
94  // Method Description:
103  static NdArray<double> eulerAxisAngle(const Vec3& inAxis, double inAngle)
104  {
105  return Quaternion(inAxis, inAngle).toDCM();
106  }
107 
108  //============================================================================
109  // Method Description:
118  static bool isValid(const NdArray<double>& inArray)
119  {
120  const Shape inShape = inArray.shape();
121  if (!(inShape.rows == inShape.cols &&
122  utils::essentiallyEqual(round(linalg::det<double>(inArray), 2), 1.0) &&
123  utils::essentiallyEqual(round(linalg::det<double>(inArray.transpose()), 2), 1.0)))
124  {
125  return false;
126  }
127  return true;
128  }
129 
130  //============================================================================
131  // Method Description:
137  static double roll(const NdArray<double>& dcm)
138  {
139  return Quaternion(dcm).roll();
140  }
141 
142  //============================================================================
143  // Method Description:
149  static double pitch(const NdArray<double>& dcm)
150  {
151  return Quaternion(dcm).pitch();
152  }
153 
154  //============================================================================
155  // Method Description:
161  static double yaw(const NdArray<double>& dcm)
162  {
163  return Quaternion(dcm).yaw();
164  }
165 
166  //============================================================================
167  // Method Description:
176  static NdArray<double> xRotation(double inAngle)
177  {
178  return DCM::eulerAxisAngle(Vec3{ 1.0, 0.0, 0.0 }, inAngle);
179  }
180 
181  //============================================================================
182  // Method Description:
191  static NdArray<double> yRotation(double inAngle)
192  {
193  return DCM::eulerAxisAngle(Vec3{ 0.0, 1.0, 0.0 }, inAngle);
194  }
195 
196  //============================================================================
197  // Method Description:
206  static NdArray<double> zRotation(double inAngle)
207  {
208  return DCM::eulerAxisAngle(Vec3{ 0.0, 0.0, 1.0 }, inAngle);
209  }
210  };
211  }
212 }
nc::rotations::DCM::eulerAngles
static NdArray< double > eulerAngles(const NdArray< double > &angles)
Definition: DCM.hpp:73
nc::rotations::DCM::isValid
static bool isValid(const NdArray< double > &inArray)
Definition: DCM.hpp:118
nc::NdArray::shape
Shape shape() const noexcept
Definition: NdArrayCore.hpp:4296
nc::rotations::Quaternion
Holds a unit quaternion.
Definition: Quaternion.hpp:58
nc::rotations::DCM::eulerAxisAngle
static NdArray< double > eulerAxisAngle(const NdArray< double > &inAxis, double inAngle)
Definition: DCM.hpp:88
nc::rotations::Quaternion::pitch
double pitch() const noexcept
Definition: Quaternion.hpp:343
nc::rotations::Quaternion::toDCM
NdArray< double > toDCM() const
Definition: Quaternion.hpp:506
nc::utils::essentiallyEqual
bool essentiallyEqual(dtype inValue1, dtype inValue2) noexcept
Definition: essentiallyEqual.hpp:53
nc::rotations::Quaternion::yaw
double yaw() const noexcept
Definition: Quaternion.hpp:567
nc::rotations::DCM::xRotation
static NdArray< double > xRotation(double inAngle)
Definition: DCM.hpp:176
nc::rotations::DCM::pitch
static double pitch(const NdArray< double > &dcm)
Definition: DCM.hpp:149
nc::rotations::Quaternion::roll
double roll() const noexcept
Definition: Quaternion.hpp:363
Quaternion.hpp
nc::NdArray::transpose
NdArray< dtype > transpose() const
Definition: NdArrayCore.hpp:4591
nc::NdArray< double >
NdArray.hpp
dot.hpp
Vec3.hpp
nc::Shape
A Shape Class for NdArrays.
Definition: Core/Shape.hpp:41
nc::Shape::cols
uint32 cols
Definition: Core/Shape.hpp:46
nc::rotations::DCM
Factory methods for generating direction cosine matrices and vectors.
Definition: DCM.hpp:45
nc::rotations::DCM::yRotation
static NdArray< double > yRotation(double inAngle)
Definition: DCM.hpp:191
nc::rotations::DCM::zRotation
static NdArray< double > zRotation(double inAngle)
Definition: DCM.hpp:206
nc
Definition: Coordinate.hpp:45
det.hpp
nc::Shape::rows
uint32 rows
Definition: Core/Shape.hpp:45
essentiallyEqual.hpp
nc::round
dtype round(dtype inValue, uint8 inDecimals=0)
Definition: round.hpp:47
nc::rotations::DCM::yaw
static double yaw(const NdArray< double > &dcm)
Definition: DCM.hpp:161
nc::rotations::DCM::eulerAxisAngle
static NdArray< double > eulerAxisAngle(const Vec3 &inAxis, double inAngle)
Definition: DCM.hpp:103
nc::Vec3
Holds a 3D vector.
Definition: Vec3.hpp:50
nc::rotations::DCM::eulerAngles
static NdArray< double > eulerAngles(double roll, double pitch, double yaw)
Definition: DCM.hpp:59
nc::rotations::DCM::roll
static double roll(const NdArray< double > &dcm)
Definition: DCM.hpp:137
round.hpp