AGX Dynamics 2.41.3.0
Loading...
Searching...
No Matches
EulerAngles.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx 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
26namespace 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
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
92 EulerOrder(EulerConvention::Convention = EulerConvention::DEFAULT_CONVENTION);
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 {
120 return axes[firstAxis()];
121 }
122 inline int j() const {
124 return paxes[i()+isOdd()];
125 }
126 inline int k() const {
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
197 EulerAngles(EulerConvention::Convention C = EulerConvention::DEFAULT_CONVENTION);
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
209 EulerAngles(Real a, Real b, Real c, EulerConvention::Convention C = EulerConvention::DEFAULT_CONVENTION);
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
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_PAXES()
Definition: EulerAngles.h:74
#define AGX_EULER_AXES()
Definition: EulerAngles.h:73
#define AGXCORE_EXPORT
bool isStatic() const
The computational routines used by the EulerAngle class.
Definition: EulerAngles.h:109
bool operator=(const EulerConvention::Convention &c)
Assignment operator.
Definition: EulerAngles.h:313
EulerOrder(EulerConvention::Convention=EulerConvention::DEFAULT_CONVENTION)
Default constructor: EulerConvention::DEFAULT_CONVENTION convention and 0 angles.
Definition: EulerAngles.h:319
int getConvention() const
Get the current convention.
Definition: EulerAngles.h:308
bool operator=(const int &c)
Assignment operator and conversion from int.
This class provides conversion services between Euler angles in any of the 24 conventions and corresp...
Definition: EulerAngles.h:70
EulerAngles & set(const OrthoMatrix3x3 &m, EulerConvention::Convention C=EulerConvention::BAD)
EulerAngles(EulerConvention::Convention C=EulerConvention::DEFAULT_CONVENTION)
Default constructor.
bool get(Quat &q) const
Compute the value of quaternion q that corresponds to current angles in current convention.
EulerAngles & set(const Matrix3x3T< T > &m, EulerConvention::Convention C=EulerConvention::BAD)
Set the angles to correspond to matrix m in given convention.
bool get(Matrix4x4T< T > &m) const
Compute the value of matrix m that corresponds to current angles in current convention.
bool get(OrthoMatrix3x3 &m) const
Real x() const
Get the first angle.
Definition: EulerAngles.h:321
Real & operator[](size_t i)
Get an element by index as a reference.
Definition: EulerAngles.h:351
Real y() const
Get the second angle.
Definition: EulerAngles.h:331
EulerAngles(Real a, Real b, Real c, int C)
Explicit constructor.
void set(const Vec3 &angles)
Set the three angles in one call.
Definition: EulerAngles.h:373
EulerAngles(const EulerAngles &e)=default
Convention is set to C and angles are set to 0.
EulerAngles(const agx::Vec3 &angles, EulerConvention::Convention C=EulerConvention::DEFAULT_CONVENTION)
Explicit constructor.
EulerAngles(const Quat &q, EulerConvention::Convention C=EulerConvention::DEFAULT_CONVENTION)
Construct from quaternion in given convention.
EulerAngles(const OrthoMatrix3x3 &m, EulerConvention::Convention C=EulerConvention::DEFAULT_CONVENTION)
EulerAngles(const Matrix4x4T< T > &m, EulerConvention::Convention C=EulerConvention::DEFAULT_CONVENTION)
Construct from 4x4 matrix in given convention.
EulerAngles::EulerOrder & getOrder()
Get the convention.
Definition: EulerAngles.h:362
EulerAngles & set(const Quat &q, EulerConvention::Convention C=EulerConvention::BAD)
Set the angles to correspond to quaternion q in given convention.
EulerAngles & operator=(const EulerAngles &e)=default
Assignment operator.
EulerAngles(Real a, Real b, Real c, EulerConvention::Convention C=EulerConvention::DEFAULT_CONVENTION)
Explicit constructor.
bool get(Matrix3x3T< T > &m) const
Compute the value of matrix m that corresponds to current angles in current convention.
EulerAngles & set(const Matrix4x4T< T > &m, EulerConvention::Convention c=EulerConvention::BAD)
Compute Jacobian matrix between angular velocity in body coordinates and rate of change of angles.
EulerAngles(const Matrix3x3T< T > &m, EulerConvention::Convention C=EulerConvention::DEFAULT_CONVENTION)
Construct from 3x3 Matrix in given convention.
static EulerAngles random(const Vec3 &min=Vec3(Real(0.0)), const Vec3 &max=Vec3(2 *agx::PI), EulerConvention::Convention c=EulerConvention::DEFAULT_CONVENTION)
Generate an EulerAngles object with random angles in every axis [ 0 - 2PI ].
Real z() const
Get the third angle.
Definition: EulerAngles.h:341
Convention
The 24 Euler conventions.
Matrix class for affine transformations.
Definition: Matrix4x4.h:58
Specialized types of matrices for holding orthogonal transformation matrices.
#define AGX_FORCE_INLINE
Definition: macros.h:58
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
std::ostream & operator<<(std::ostream &os, const agx::AddedMassInteraction::Matrix6x6 &m)
static constexpr Real PI
Definition: Math.h:63
double Real
Definition: Real.h:42