AGX Dynamics  2.37.3.2
EulerAngles.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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 
216 
218  template <typename T>
220 
222  template <typename T>
225 
228 
231 
236  //int setJacobianBody(Matrix3x3 & m);
241  //int setJacobianWorld(Matrix3x3 & m);
242 
250  template<typename T>
252 
260  template<typename T>
263 
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 
327  {
328  return m_angles[0];
329  }
330 
331  inline Real EulerAngles::y() const
332  {
333  return m_angles[1];
334  }
335 
337  {
338  return m_angles[1];
339  }
340 
341  inline Real EulerAngles::z() const
342  {
343  return m_angles[2];
344  }
345 
347  {
348  return m_angles[2];
349  }
350 
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 
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 
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
#define AGX_EULER_AXES()
Definition: EulerAngles.h:73
T random(T min, T max)
Definition: Math.h:555
const Real PI
Definition: Math.h:63
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3.h:36
EulerAngles::EulerOrder & getOrder()
Get the convention.
Definition: EulerAngles.h:362
Real x() const
Get the first angle.
Definition: EulerAngles.h:321
Vec3T< T > min(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:861
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:855
int getConvention() const
Get the current convention.
Definition: EulerAngles.h:308
The default Euler convention used by agx.
Matrix class for affine transformations.
Definition: EulerAngles.h:34
Real z() const
Get the third angle.
Definition: EulerAngles.h:341
bool isStatic() const
The computational routines used by the EulerAngle class.
Definition: EulerAngles.h:109
#define AGX_FORCE_INLINE
Definition: Object.h:59
This class provides conversion services between Euler angles in any of the 24 conventions and corresp...
Definition: EulerAngles.h:69
#define AGX_EULER_PAXES()
Definition: EulerAngles.h:74
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
std::ostream & operator<<(std::ostream &os, const agx::AddedMassInteraction::Matrix6x6 &m)
Real y() const
Get the second angle.
Definition: EulerAngles.h:331
bool operator=(const EulerConvention::Convention &c)
Assignment operator.
Definition: EulerAngles.h:313
Real & operator[](size_t i)
Get an element by index as a reference.
Definition: EulerAngles.h:351
Convention
The 24 Euler conventions.
double Real
Definition: Real.h:42
EulerOrder(EulerConvention::Convention=EulerConvention::DEFAULT_CONVENTION)
Default constructor: EulerConvention::DEFAULT_CONVENTION convention and 0 angles. ...
Definition: EulerAngles.h:319
#define AGXCORE_EXPORT
Specialized types of matrices for holding orthogonal transformation matrices.
void set(const Vec3 &angles)
Set the three angles in one call.
Definition: EulerAngles.h:373