Momentum Scripting v1
Loading...
Searching...
No Matches
EulerAngles.h
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 without having a written signed agreement with Algoryx Simulation AB.
9
10Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
11from using this software, unless otherwise stated in written agreements with
12Algoryx Simulation AB.
13*/
14
15#ifndef MOMENTUM_EULERANGLES_H
16#define MOMENTUM_EULERANGLES_H
17
18#include <momentum_namespace.h>
19#include <momentum_export.h>
20
21#include "Vec3.h"
22#include "Quat.h"
23#include "Matrix4x4.h"
24#include "EulerConvention.h"
25#include <agx/EulerAngles.h>
26
27namespace MOMENTUM_NAMESPACE
28{
29
30
63 class MOMENTUM_EXPORT EulerAngles
64 {
65
66 public:
67
68
69#ifndef SWIG
71#define MOMENTUM_EULER_AXES() const int axes[4] = {0,1,2,0}
72#define MOMENTUM_EULER_PAXES() const int paxes[4] = {1,2,0,1};
74
76 {
77 private:
78 EulerConvention::Convention m_c; // the current convention
79 // const static int axes[4]; // a utility for computations
80 // const static int paxes[4]; // a utility for computations
81 // used internally
82 inline int firstAxis() const {
83 return ( m_c >> 3 )&3;
84 }
85
86 public:
87 const static char *names[]; // needed for debug purposes
89 EulerOrder(EulerConvention::Convention = EulerConvention::DEFAULT_CONVENTION);
90
92 int getConvention() const;
93
97 bool operator=( const EulerConvention::Convention &c );
102 bool operator=( const int &c );
104 inline bool isStatic() const {
105 return ! ( m_c&1 );
106 }
107 inline bool isOdd() const {
108 return ( m_c >> 2 )&1;
109 }
110 inline bool isRepeat() const {
111 return ( m_c >> 1 )&1;
112 }
113 inline int i() const {
114 MOMENTUM_EULER_AXES();
115 return axes[firstAxis()];
116 }
117 inline int j() const {
118 MOMENTUM_EULER_PAXES();
119 return paxes[i()+isOdd()];
120 }
121 inline int k() const {
122 MOMENTUM_EULER_PAXES();
123 return paxes[i()+!isOdd()];
124 }
125 };
126#endif
127
128
129 private:
130 double m_angles[3];
131 EulerOrder m_o;
132 void applyParity() ;
133 void shiftxz();
134 void flip();
135 void permute();
136 enum Axes {X, Y, Z, W};
137
138 public:
139
141 double x()const;
142
144 double setX(double val);
145
147 double y()const;
148
150 double setY(double val);
151
153 double z()const;
154
156 double setZ(double val);
157
158#ifndef SWIG
162 inline double& operator [] (int i);
163
167 inline double operator [] (int i) const;
168#endif
173 inline void set( const Vec3& angles );
174
179 inline void set( double x,
180 double y,
181 double z );
182
183
185 const EulerAngles::EulerOrder& setOrder(const EulerAngles::EulerOrder& order);
186
188 const EulerAngles::EulerOrder& getOrder() const;
189
191 //EulerAngles();
192
194 EulerAngles(EulerConvention::Convention C = EulerConvention::DEFAULT_CONVENTION);
195
196#ifndef SWIG
198 operator agx::EulerAngles() const
199 {
200 return agx::EulerAngles(x(), y(), z(), m_o.getConvention());
201 }
202
203 EulerAngles(const agx::EulerAngles& e)
204 {
205 (*this) = EulerAngles(e.x(), e.y(), e.z(), e.getOrder().getConvention());
206 }
208
209#endif
210
213
214#ifndef SWIG
216 EulerAngles( double a, double b, double c, int C );
217#endif
219 EulerAngles(double a, double b, double c, EulerConvention::Convention C = EulerConvention::DEFAULT_CONVENTION);
220
222 explicit EulerAngles(const Vec3& angles, EulerConvention::Convention C = EulerConvention::DEFAULT_CONVENTION);
223
224
225#ifndef SWIG
228#endif
230 EulerAngles( const Matrix4x4 & m, EulerConvention::Convention C = EulerConvention::DEFAULT_CONVENTION );
231
233 EulerAngles( const Quat& q, EulerConvention::Convention C = EulerConvention::DEFAULT_CONVENTION );
234
235
236 static EulerAngles random(const Vec3& min = Vec3(double(0.0)), const Vec3& max = Vec3(2 * MOMENTUM_NAMESPACE::PI), EulerConvention::Convention c = EulerConvention::DEFAULT_CONVENTION);
237
244 void set(const Matrix4x4 & m, EulerConvention::Convention C = EulerConvention::BAD);
245
246
253 void set(const Quat& q, EulerConvention::Convention C = EulerConvention::BAD);
254
260 std::pair<Matrix4x4, bool> getAsMatrix4x4(Matrix4x4 matrix) const;
261
262
268 std::pair<Quat, bool> getAsQuat() const;
269
271 Vec3 asVec3() const;
272
273 };
274
276 {
277 return m_c;
278 }
279
281 {
282 this->m_c = c;
283 return true;
284 }
285
287
288 inline double EulerAngles::x() const
289 {
290 return m_angles[0];
291 }
292 inline double EulerAngles::setX(double val)
293 {
294 m_angles[0] = val;
295 return m_angles[0];
296 }
297 inline double EulerAngles::y() const
298 {
299 return m_angles[1];
300 }
301 inline double EulerAngles::setY(double val)
302 {
303 m_angles[1] = val;
304 return m_angles[1];
305 }
306 inline double EulerAngles::z() const
307 {
308 return m_angles[2];
309 }
310 inline double EulerAngles::setZ(double val)
311 {
312 m_angles[2] = val;
313 return m_angles[2];
314 }
315
316 inline double& EulerAngles::operator [] (int i)
317 {
318 return m_angles[i];
319 }
320
321 inline double EulerAngles::operator [] (int i) const
322 {
323 return m_angles[i];
324 }
325
326
328 {
329 m_o = order;
330 return m_o;
331 }
332
334 {
335 return m_o;
336 }
337
339 {
340 return Vec3( m_angles[ 0 ], m_angles[ 1 ], m_angles[ 2 ] );
341 }
342
343 inline void EulerAngles::set( const Vec3& angles )
344 {
345 m_angles[0] = angles[0];
346 m_angles[1] = angles[1];
347 m_angles[2] = angles[2];
348 }
349
350 inline void EulerAngles::set( double x, double y, double z )
351 {
352 m_angles[0] = x;
353 m_angles[1] = y;
354 m_angles[2] = z;
355 }
356
357
358 inline std::ostream& operator<< ( std::ostream& os, const EulerAngles& e )
359 {
360 os << "[" << e[0] << " " << e[1] << " " << e[2] << "]";
361 return os;
362 }
363
364
365
366} // namespace momentum
367
368#endif
int j() const
Definition: EulerAngles.h:117
bool isStatic() const
The computational routines used by the EulerAngle class.
Definition: EulerAngles.h:104
bool operator=(const int &c)
Assignment operator and conversion from int.
int k() const
Definition: EulerAngles.h:121
bool isOdd() const
Definition: EulerAngles.h:107
int i() const
Definition: EulerAngles.h:113
int getConvention() const
Get the current convention.
Definition: EulerAngles.h:275
EulerOrder(EulerConvention::Convention=EulerConvention::DEFAULT_CONVENTION)
Default constructor: EulerConvention::Convention::DEFAULT_CONVENTION convention and 0 angles.
Definition: EulerAngles.h:286
bool isRepeat() const
Definition: EulerAngles.h:110
bool operator=(const EulerConvention::Convention &c)
Assignment operator.
Definition: EulerAngles.h:280
This class provides conversion services between Euler angles in any of the 24 conventions and corresp...
Definition: EulerAngles.h:64
void set(const Vec3 &angles)
Set the three angles in one call.
Definition: EulerAngles.h:343
double z() const
Get the third angle.
Definition: EulerAngles.h:306
double x() const
Get the first angle.
Definition: EulerAngles.h:288
static EulerAngles random(const Vec3 &min=Vec3(double(0.0)), const Vec3 &max=Vec3(2 *MOMENTUM_NAMESPACE::PI), EulerConvention::Convention c=EulerConvention::DEFAULT_CONVENTION)
EulerAngles operator=(const EulerAngles &e)
Assignment operator.
EulerAngles(double a, double b, double c, EulerConvention::Convention C=EulerConvention::DEFAULT_CONVENTION)
Explicit constructor.
const EulerAngles::EulerOrder & getOrder() const
Get or set the convention.
Definition: EulerAngles.h:333
std::pair< Matrix4x4, bool > getAsMatrix4x4(Matrix4x4 matrix) const
Compute the value of matrix m that corresponds to current angles in current convention.
double setY(double val)
Get or set the second angle.
Definition: EulerAngles.h:301
EulerAngles(const Matrix4x4 &m, EulerConvention::Convention C=EulerConvention::DEFAULT_CONVENTION)
Construct from affine matrix in given convention.
double setZ(double val)
Get or set the third angle.
Definition: EulerAngles.h:310
double setX(double val)
Get or set the first angle.
Definition: EulerAngles.h:292
std::pair< Quat, bool > getAsQuat() const
Compute the value of quaternion q that corresponds to current angles in current convention.
const EulerAngles::EulerOrder & setOrder(const EulerAngles::EulerOrder &order)
Get the convention.
Definition: EulerAngles.h:327
void set(const Quat &q, EulerConvention::Convention C=EulerConvention::BAD)
Set the angles to correspond to quaternion q in given convention.
double & operator[](int i)
Get an element by index as a reference.
Definition: EulerAngles.h:316
double y() const
Get the second angle.
Definition: EulerAngles.h:297
EulerAngles(EulerConvention::Convention C=EulerConvention::DEFAULT_CONVENTION)
Default constructor.
EulerAngles(const Quat &q, EulerConvention::Convention C=EulerConvention::DEFAULT_CONVENTION)
Construct from quaternion in given convention.
EulerAngles(const Vec3 &angles, EulerConvention::Convention C=EulerConvention::DEFAULT_CONVENTION)
Explicit constructor.
Vec3 asVec3() const
Definition: EulerAngles.h:338
EulerAngles(const EulerAngles &e)
Copy constructor.
EulerAngles(double a, double b, double c, int C)
Explicit constructor.
void set(const Matrix4x4 &m, EulerConvention::Convention C=EulerConvention::BAD)
Set the angles to correspond to matrix m in given convention.
Convention
Definition: EulerConvention.h:32
Matrix class for affine transformations.
Definition: Matrix4x4.h:51
The object holding quaternions and providing operations on these.
Definition: Quat.h:55
A 3 dimensional vector which can be used to define a point or a vector and contains basic arithmetic.
Definition: Vec3.h:40
Namespace for Momentum Scripting API.
Definition: AffineMatrix4x4.h:29
std::ostream & operator<<(std::ostream &os, const EulerAngles &e)
Definition: EulerAngles.h:358
const double PI
Definition: momentum_math.h:37