AGXDynamics  2.35.0.3
EulerAngles.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
19 #include <agx/agxCore_export.h>
20 #include <agx/Matrix3x3.h>
21 #include <agx/agx.h>
22 #include <agx/Vec3.h>
23 #include <agx/Quat.h>
24 #include <agx/EulerConvention.h>
25 
26 namespace agx
27 {
28  class OrthoMatrix3x3;
29 
30  template <typename T>
31  class Matrix3x3T;
32 
33  template <typename T>
34  class Matrix4x4T;
35 
70  {
71  public:
72 
73 #define AGX_EULER_AXES() const int axes[4] = {0,1,2,0}
74 #define AGX_EULER_PAXES() const int paxes[4] = {1,2,0,1};
75 
76  class EulerOrder
77  {
78  private:
79  EulerConvention::Convention m_c; // the current convention
80  // const static int axes[4]; // a utility for computations
81  // const static int paxes[4]; // a utility for computations
82  // used internally
83  inline int firstAxis() const {
84  return ( m_c >> 3 )&3;
85  }
86 
87  public:
88 #ifndef SWIG
89  const static char *names[]; // needed for debug purposes
90 #endif
91 
93 
95  int getConvention() const;
96 
100  bool operator=( const EulerConvention::Convention &c ); // NOLINT
101 
106  bool operator=( const int &c ); // NOLINT We should consider wether we really want to break convention here.
107 
109  inline bool isStatic() const {
110  return ! ( m_c&1 );
111  }
112  inline bool isOdd() const {
113  return ( m_c >> 2 )&1;
114  }
115  inline bool isRepeat() const {
116  return ( m_c >> 1 )&1;
117  }
118  inline int i() const {
119  AGX_EULER_AXES();
120  return axes[firstAxis()];
121  }
122  inline int j() const {
123  AGX_EULER_PAXES();
124  return paxes[i()+isOdd()];
125  }
126  inline int k() const {
127  AGX_EULER_PAXES();
128  return paxes[i()+!isOdd()];
129  }
130  };
131 
132 
133  private:
134  Real m_angles[3];
135  EulerOrder m_o;
136  void applyParity() ;
137  void shiftxz();
138  void flip();
139  void permute();
140  enum Axes {X, Y, Z, W};
141 
142  public:
143 
145  Real x()const;
146 
148  Real& x();
149 
151  Real y()const;
152 
154  Real& y();
155 
157  Real z()const;
158 
160  Real& z();
161 
165  inline Real& operator [] (size_t i);
166 
170  inline Real operator [] (size_t i) const;
171 
176  inline void set( const Vec3& angles );
177 
182  inline void set( Real x,
183  Real y,
184  Real z );
185 
186 
188  EulerAngles::EulerOrder& getOrder();
189 
191  const EulerAngles::EulerOrder& getOrder() const;
192 
194  //EulerAngles();
195 
198 
200  //EulerAngles( EulerConvention::Convention C );
201 
203  EulerAngles( const EulerAngles & e ) = default;
204 
206  EulerAngles( Real a, Real b, Real c, int C );
207 
210 
212  EulerAngles & operator=( const EulerAngles& e ) = default;
213 
215  explicit EulerAngles(const agx::Vec3& angles, EulerConvention::Convention C = EulerConvention::DEFAULT_CONVENTION);
216 
218  template <typename T>
219  explicit EulerAngles( const Matrix4x4T<T> & m, EulerConvention::Convention C = EulerConvention::DEFAULT_CONVENTION );
220 
222  template <typename T>
223  explicit EulerAngles( const Matrix3x3T<T>& m, EulerConvention::Convention C = EulerConvention::DEFAULT_CONVENTION );
224  explicit EulerAngles(const OrthoMatrix3x3& m, EulerConvention::Convention C = EulerConvention::DEFAULT_CONVENTION);
225 
227  explicit EulerAngles( const Quat& q, EulerConvention::Convention C = EulerConvention::DEFAULT_CONVENTION );
228 
230  static EulerAngles random(const Vec3& min = Vec3(Real(0.0)), const Vec3& max = Vec3(2 * agx::PI), EulerConvention::Convention c = EulerConvention::DEFAULT_CONVENTION);
231 
236  //int setJacobianBody(Matrix3x3 & m);
241  //int setJacobianWorld(Matrix3x3 & m);
242 
250  template<typename T>
251  EulerAngles& set(const Matrix4x4T<T>& m, EulerConvention::Convention c = EulerConvention::BAD);
252 
260  template<typename T>
261  EulerAngles& set(const Matrix3x3T<T> & m, EulerConvention::Convention C = EulerConvention::BAD);
262  EulerAngles& set(const OrthoMatrix3x3 & m, EulerConvention::Convention C = EulerConvention::BAD);
263 
271  EulerAngles& set(const Quat& q, EulerConvention::Convention C = EulerConvention::BAD);
272 
278  template<typename T>
279  bool get( Matrix4x4T<T>& m ) const;
280 
286  template<typename T>
287  bool get( Matrix3x3T<T> & m ) const;
288  bool get( OrthoMatrix3x3 & m ) const;
289 
295  bool get( Quat &q ) const;
296 
300  Real* ptr();
301 
305  const Real* ptr() const;
306  };
307 
309  {
310  return m_c;
311  }
312 
314  {
315  this->m_c = c;
316  return true;
317  }
318 
320 
321  inline Real EulerAngles::x() const
322  {
323  return m_angles[0];
324  }
325 
326  inline Real& EulerAngles::x()
327  {
328  return m_angles[0];
329  }
330 
331  inline Real EulerAngles::y() const
332  {
333  return m_angles[1];
334  }
335 
336  inline Real& EulerAngles::y()
337  {
338  return m_angles[1];
339  }
340 
341  inline Real EulerAngles::z() const
342  {
343  return m_angles[2];
344  }
345 
346  inline Real& EulerAngles::z()
347  {
348  return m_angles[2];
349  }
350 
351  inline Real& EulerAngles::operator [] (size_t i)
352  {
353  return m_angles[i];
354  }
355 
356  inline Real EulerAngles::operator [] (size_t i) const
357  {
358  return m_angles[i];
359  }
360 
361 
363  {
364  return m_o;
365  }
366 
367  inline const EulerAngles::EulerOrder& EulerAngles::getOrder() const
368  {
369  return m_o;
370  }
371 
372 
373  inline void EulerAngles::set( const Vec3& angles )
374  {
375  m_angles[0] = angles[0];
376  m_angles[1] = angles[1];
377  m_angles[2] = angles[2];
378  }
379 
380  inline void EulerAngles::set( Real x, Real y, Real z )
381  {
382  m_angles[0] = x;
383  m_angles[1] = y;
384  m_angles[2] = z;
385  }
386 
387 
388  inline std::ostream& operator<< ( std::ostream& os, const EulerAngles& e )
389  {
390  os << "[" << e[0] << " " << e[1] << " " << e[2] << "]";
391  return os;
392  }
393 
395  {
396  return m_angles;
397  }
398 
399  AGX_FORCE_INLINE const Real* EulerAngles::ptr() const
400  {
401  return m_angles;
402  }
403 
404  //AGXCORE_EXPORT std::ostream & operator<< ( std::ostream &os, const EulerAngles & a );
405  //AGXCORE_EXPORT std::ostream & operator<<( std::ostream &os, const EulerAngles::EulerOrder& o );
406 
407 
408 } // namespace agx
agx::EulerAngles::getOrder
EulerAngles::EulerOrder & getOrder()
Get the convention.
Definition: EulerAngles.h:362
AGXCORE_EXPORT
#define AGXCORE_EXPORT
agx::EulerAngles::EulerOrder::j
int j() const
Definition: EulerAngles.h:122
Matrix3x3.h
agx::Real
double Real
Definition: Real.h:42
agx::EulerAngles::EulerOrder
Definition: EulerAngles.h:76
agx::EulerAngles::x
Real x() const
Get the first angle.
Definition: EulerAngles.h:321
agx::EulerAngles::z
Real z() const
Get the third angle.
Definition: EulerAngles.h:341
AGX_EULER_PAXES
#define AGX_EULER_PAXES()
Definition: EulerAngles.h:74
EulerConvention.h
agx::PI
const Real PI
Definition: Math.h:63
agx::EulerAngles::EulerOrder::getConvention
int getConvention() const
Get the current convention.
Definition: EulerAngles.h:308
agx::EulerAngles::EulerOrder::i
int i() const
Definition: EulerAngles.h:118
agx::EulerAngles::EulerOrder::isStatic
bool isStatic() const
The computational routines used by the EulerAngle class.
Definition: EulerAngles.h:109
agx::EulerAngles::y
Real y() const
Get the second angle.
Definition: EulerAngles.h:331
agx::EulerAngles::EulerOrder::operator=
bool operator=(const EulerConvention::Convention &c)
Assignment operator.
Definition: EulerAngles.h:313
agx::EulerAngles::ptr
Real * ptr()
Definition: EulerAngles.h:394
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
agx::Matrix4x4T
Matrix class for affine transformations.
Definition: EulerAngles.h:34
agx::EulerConvention::Convention
Convention
The 24 Euler conventions.
Definition: EulerConvention.h:33
agx::operator<<
std::ostream & operator<<(std::ostream &stream, const AtomicValueT< T > &value)
Definition: AtomicValue.h:109
agx::EulerAngles::EulerOrder::k
int k() const
Definition: EulerAngles.h:126
agx::EulerAngles::EulerOrder::isOdd
bool isOdd() const
Definition: EulerAngles.h:112
Vec3.h
agx::random
T random(T min, T max)
Definition: Math.h:555
agx::EulerConvention::DEFAULT_CONVENTION
@ DEFAULT_CONVENTION
The default Euler convention used by agx.
Definition: EulerConvention.h:43
agx::Vec3
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3.h:36
agx::min
Vec3T< T > min(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:880
agx::EulerAngles::EulerOrder::isRepeat
bool isRepeat() const
Definition: EulerAngles.h:115
agxCore_export.h
agx::EulerAngles
This class provides conversion services between Euler angles in any of the 24 conventions and corresp...
Definition: EulerAngles.h:69
agx.h
Quat.h
agx::EulerConvention::BAD
@ BAD
Definition: EulerConvention.h:42
agx::EulerAngles::operator[]
Real & operator[](size_t i)
Get an element by index as a reference.
Definition: EulerAngles.h:351
agx::Quat
QuatT< Real > Quat
Definition: Quat.h:24
AGX_EULER_AXES
#define AGX_EULER_AXES()
Definition: EulerAngles.h:73
agx::Vec3T< Real >
agx::EulerAngles::EulerOrder::EulerOrder
EulerOrder(EulerConvention::Convention=EulerConvention::DEFAULT_CONVENTION)
Default constructor: EulerConvention::DEFAULT_CONVENTION convention and 0 angles.
Definition: EulerAngles.h:319
agx::Matrix3x3T
Definition: EulerAngles.h:31
agx::EulerAngles::set
void set(const Vec3 &angles)
Set the three angles in one call.
Definition: EulerAngles.h:373
agx::max
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:874
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58