AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EulerAngles.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 
21 #include <agx/Matrix3x3.h>
22 
23 #include <agx/agx.h>
24 #include <agx/Vec3.h>
25 #include <agx/Quat.h>
26 #include <agx/EulerConvention.h>
27 
28 namespace agx
29 {
30  class OrthoMatrix3x3;
31 
32  template <typename T>
33  class Matrix3x3T;
34 
35  template <typename T>
36  class Matrix4x4T;
37 
38 
73  {
74 
75  public:
76 
77 
78 
79 #define AGX_EULER_AXES() const int axes[4] = {0,1,2,0}
80 #define AGX_EULER_PAXES() const int paxes[4] = {1,2,0,1};
81 
82  class EulerOrder
83  {
84  private:
85  EulerConvention::Convention m_c; // the current convention
86  // const static int axes[4]; // a utility for computations
87  // const static int paxes[4]; // a utility for computations
88  // used internally
89  inline int firstAxis() const {
90  return ( m_c >> 3 )&3;
91  }
92 
93  public:
94 #ifndef SWIG
95  const static char *names[]; // needed for debug purposes
96 #endif
97 
99 
101  int getConvention() const;
102 
106  bool operator=( const EulerConvention::Convention &c ); // NOLINT
107 
112  bool operator=( const int &c ); // NOLINT We should consider wether we really want to break convention here.
113 
115  inline bool isStatic() const {
116  return ! ( m_c&1 );
117  }
118  inline bool isOdd() const {
119  return ( m_c >> 2 )&1;
120  }
121  inline bool isRepeat() const {
122  return ( m_c >> 1 )&1;
123  }
124  inline int i() const {
125  AGX_EULER_AXES();
126  return axes[firstAxis()];
127  }
128  inline int j() const {
129  AGX_EULER_PAXES();
130  return paxes[i()+isOdd()];
131  }
132  inline int k() const {
133  AGX_EULER_PAXES();
134  return paxes[i()+!isOdd()];
135  }
136  };
137 
138 
139  private:
140  Real m_angles[3];
141  EulerOrder m_o;
142  void applyParity() ;
143  void shiftxz();
144  void flip();
145  void permute();
146  enum Axes {X, Y, Z, W};
147 
148  public:
149 
151  Real x()const;
152 
154  Real& x();
155 
157  Real y()const;
158 
160  Real& y();
161 
163  Real z()const;
164 
166  Real& z();
167 
171  inline Real& operator [] (size_t i);
172 
176  inline Real operator [] (size_t i) const;
177 
182  inline void set( const Vec3& angles );
183 
188  inline void set( Real x,
189  Real y,
190  Real z );
191 
192 
194  EulerAngles::EulerOrder& getOrder();
195 
197  const EulerAngles::EulerOrder& getOrder() const;
198 
200  //EulerAngles();
201 
204 
206  //EulerAngles( EulerConvention::Convention C );
207 
209  EulerAngles( const EulerAngles & e ) = default;
210 
212  EulerAngles( Real a, Real b, Real c, int C );
213 
216 
218  explicit EulerAngles(const agx::Vec3& angles, EulerConvention::Convention C = EulerConvention::DEFAULT_CONVENTION);
219 
220 
222  EulerAngles & operator=( const EulerAngles& e ) = default;
223 
225  explicit EulerAngles( const Matrix4x4T<Real> & m, EulerConvention::Convention C = EulerConvention::DEFAULT_CONVENTION );
226 
228  explicit EulerAngles( const Quat& q, EulerConvention::Convention C = EulerConvention::DEFAULT_CONVENTION );
229 
231  explicit EulerAngles( const OrthoMatrix3x3& m, EulerConvention::Convention C = EulerConvention::DEFAULT_CONVENTION );
232 
233  static EulerAngles random(const Vec3& min = Vec3(Real(0.0)), const Vec3& max = Vec3(2 * agx::PI), EulerConvention::Convention c = EulerConvention::DEFAULT_CONVENTION);
234 
239  //int setJacobianBody(Matrix3x3 & m);
244  //int setJacobianWorld(Matrix3x3 & m);
245 
253  EulerAngles& set(const Matrix4x4T<Real32>& m, EulerConvention::Convention c = EulerConvention::BAD);
254  EulerAngles& set(const Matrix4x4T<Real64>& m, EulerConvention::Convention c = EulerConvention::BAD);
255 
263  EulerAngles& set(const OrthoMatrix3x3& m, EulerConvention::Convention C = EulerConvention::BAD);
264 
272  EulerAngles& set(const Matrix3x3T<Real> & m, EulerConvention::Convention C = EulerConvention::BAD);
273 
281  EulerAngles& set(const Quat& q, EulerConvention::Convention C = EulerConvention::BAD);
282 
288  bool get( Matrix4x4T<Real32>& m ) const;
289  bool get( Matrix4x4T<Real64>& m ) const;
290 
296  bool get( OrthoMatrix3x3 & m ) const;
297 
303  bool get( Matrix3x3T<double> & m ) const;
304 
310  bool get(Matrix3x3T<float> &m) const;
311 
317  bool get( Quat &q ) const;
318 
322  Real* ptr();
323 
327  const Real* ptr() const;
328 
329  };
330 
332  {
333  return m_c;
334  }
335 
337  {
338  this->m_c = c;
339  return true;
340  }
341 
343 
344  inline Real EulerAngles::x() const
345  {
346  return m_angles[0];
347  }
349  {
350  return m_angles[0];
351  }
352  inline Real EulerAngles::y() const
353  {
354  return m_angles[1];
355  }
357  {
358  return m_angles[1];
359  }
360  inline Real EulerAngles::z() const
361  {
362  return m_angles[2];
363  }
365  {
366  return m_angles[2];
367  }
368 
369  inline Real& EulerAngles::operator [] (size_t i)
370  {
371  return m_angles[i];
372  }
373 
374  inline Real EulerAngles::operator [] (size_t i) const
375  {
376  return m_angles[i];
377  }
378 
379 
381  {
382  return m_o;
383  }
384 
386  {
387  return m_o;
388  }
389 
390 
391  inline void EulerAngles::set( const Vec3& angles )
392  {
393  m_angles[0] = angles[0];
394  m_angles[1] = angles[1];
395  m_angles[2] = angles[2];
396  }
397 
398  inline void EulerAngles::set( Real x, Real y, Real z )
399  {
400  m_angles[0] = x;
401  m_angles[1] = y;
402  m_angles[2] = z;
403  }
404 
405 
406  inline std::ostream& operator<< ( std::ostream& os, const EulerAngles& e )
407  {
408  os << "[" << e[0] << " " << e[1] << " " << e[2] << "]";
409  return os;
410  }
411 
413  {
414  return m_angles;
415  }
416 
418  {
419  return m_angles;
420  }
421 
422  //AGXCORE_EXPORT std::ostream & operator<< ( std::ostream &os, const EulerAngles & a );
423  //AGXCORE_EXPORT std::ostream & operator<<( std::ostream &os, const EulerAngles::EulerOrder& o );
424 
425 
426 } // namespace agx
#define AGX_EULER_AXES()
Definition: EulerAngles.h:79
T random(T min, T max)
Definition: Math.h:551
const Real PI
Definition: Math.h:61
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:380
bool isStatic() const
The computational routines used by the EulerAngle class.
Definition: EulerAngles.h:115
Vec3T< T > min(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:880
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:874
std::ostream & operator<<(std::ostream &stream, const AtomicValueT< T > &value)
Definition: AtomicValue.h:109
The default Euler convention used by agx.
Matrix class for affine transformations.
Definition: EulerAngles.h:36
#define AGX_FORCE_INLINE
Definition: Object.h:62
int getConvention() const
Get the current convention.
Definition: EulerAngles.h:331
This class provides conversion services between Euler angles in any of the 24 conventions and corresp...
Definition: EulerAngles.h:72
#define AGX_EULER_PAXES()
Definition: EulerAngles.h:80
QuatT< Real > Quat
Definition: Quat.h:24
Real x() const
Get the first angle.
Definition: EulerAngles.h:344
bool operator=(const EulerConvention::Convention &c)
Assignment operator.
Definition: EulerAngles.h:336
Real & operator[](size_t i)
Get an element by index as a reference.
Definition: EulerAngles.h:369
Real z() const
Get the third angle.
Definition: EulerAngles.h:360
Real y() const
Get the second angle.
Definition: EulerAngles.h:352
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:342
#define AGXCORE_EXPORT
void set(const Vec3 &angles)
Set the three angles in one call.
Definition: EulerAngles.h:391