Logo ROOT  
Reference Guide
EulerAngles.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Authors: W. Brown, M. Fischler, L. Moneta 2005
3
4 /**********************************************************************
5 * *
6 * Copyright (c) 2005 , LCG ROOT MathLib Team *
7 * *
8 * *
9 **********************************************************************/
10
11// Header file for class EulerAngles
12//
13// Created by: Lorenzo Moneta at Tue May 10 17:55:10 2005
14//
15// Last update: Tue May 10 17:55:10 2005
16//
17#ifndef ROOT_Math_GenVector_EulerAngles
18#define ROOT_Math_GenVector_EulerAngles 1
19
25#include <algorithm>
26#include <cassert>
27
28namespace ROOT {
29namespace Math {
30
31
32//__________________________________________________________________________________________
33 /**
34 EulerAngles class describing rotation as three angles (Euler Angles).
35 The Euler angles definition matches that of Classical Mechanics (Goldstein).
36 It is also the same convention defined in
37 <A HREF="http://mathworld.wolfram.com/EulerAngles.html">mathworld</A>
38 and used in Mathematica and CLHEP. Note that the ROOT class TRotation defines
39 a slightly different convention.
40
41 @ingroup GenVector
42 */
44
45public:
46
47 typedef double Scalar;
48
49 /**
50 Default constructor
51 */
52 EulerAngles() : fPhi(0.0), fTheta(0.0), fPsi(0.0) { }
53
54 /**
55 Constructor from phi, theta and psi
56 */
57 EulerAngles( Scalar phi, Scalar theta, Scalar psi ) :
58 fPhi(phi), fTheta(theta), fPsi(psi)
59 {Rectify();} // Added 27 Jan. 06 JMM
60
61 /**
62 Construct given a pair of pointers or iterators defining the
63 beginning and end of an array of three Scalars, to be treated as
64 the angles phi, theta and psi.
65 */
66 template<class IT>
67 EulerAngles(IT begin, IT end) { SetComponents(begin,end); }
68
69 // The compiler-generated copy ctor, copy assignment, and dtor are OK.
70
71 /**
72 Re-adjust components place angles in canonical ranges
73 */
74 void Rectify();
75
76
77 // ======== Construction and assignement from any other rotation ==================
78
79 /**
80 Create from any other supported rotation (see gv_detail::convert )
81 */
82 template <class OtherRotation>
83 explicit EulerAngles(const OtherRotation & r) {gv_detail::convert(r,*this);}
84
85 /**
86 Assign from any other rotation (see gv_detail::convert )
87 */
88 template <class OtherRotation>
89 EulerAngles & operator=( OtherRotation const & r ) {
90 gv_detail::convert(r,*this);
91 return *this;
92 }
93
94#ifdef OLD
95 explicit EulerAngles(const Rotation3D & r) {gv_detail::convert(r,*this);}
96
97 /**
98 Construct from a rotation matrix
99 */
100 explicit EulerAngles(const Rotation3D & r) {gv_detail::convert(r,*this);}
101
102 /**
103 Construct from a rotation represented by a Quaternion
104 */
105 explicit EulerAngles(const Quaternion & q) {gv_detail::convert(q,*this);}
106
107 /**
108 Construct from an AxisAngle
109 */
110 explicit EulerAngles(const AxisAngle & a ) { gv_detail::convert(a, *this); }
111
112 /**
113 Construct from an axial rotation
114 */
115 explicit EulerAngles( RotationZ const & r ) { gv_detail::convert(r, *this); }
116 explicit EulerAngles( RotationY const & r ) { gv_detail::convert(r, *this); }
117 explicit EulerAngles( RotationX const & r ) { gv_detail::convert(r, *this); }
118
119
120 /**
121 Assign from an AxisAngle
122 */
124 operator=( AxisAngle const & a ) { return operator=(EulerAngles(a)); }
125
126 /**
127 Assign from a Quaternion
128 */
130 operator=( Quaternion const & q ) {return operator=(EulerAngles(q)); }
131
132 /**
133 Assign from an axial rotation
134 */
136 operator=( RotationZ const & r ) { return operator=(EulerAngles(r)); }
138 operator=( RotationY const & r ) { return operator=(EulerAngles(r)); }
140 operator=( RotationX const & r ) { return operator=(EulerAngles(r)); }
141
142#endif
143
144 // ======== Components ==============
145
146 /**
147 Set the three Euler angles given a pair of pointers or iterators
148 defining the beginning and end of an array of three Scalars.
149 */
150 template<class IT>
151 void SetComponents(IT begin, IT end) {
152 fPhi = *begin++;
153 fTheta = *begin++;
154 fPsi = *begin++;
155 (void)end;
156 assert(begin == end);
157 Rectify(); // Added 27 Jan. 06 JMM
158 }
159
160 /**
161 Get the axis and then the angle into data specified by an iterator begin
162 and another to the end of the desired data (4 past start).
163 */
164 template<class IT>
165 void GetComponents(IT begin, IT end) const {
166 *begin++ = fPhi;
167 *begin++ = fTheta;
168 *begin++ = fPsi;
169 (void)end;
170 assert(begin == end);
171 }
172
173 /**
174 Get the axis and then the angle into data specified by an iterator begin
175 */
176 template<class IT>
177 void GetComponents(IT begin) const {
178 *begin++ = fPhi;
179 *begin++ = fTheta;
180 *begin = fPsi;
181 }
182
183 /**
184 Set the components phi, theta, psi based on three Scalars.
185 */
186 void SetComponents(Scalar phi, Scalar theta, Scalar psi) {
187 fPhi=phi; fTheta=theta; fPsi=psi;
188 Rectify(); // Added 27 Jan. 06 JMM
189 }
190
191 /**
192 Get the components phi, theta, psi into three Scalars.
193 */
194 void GetComponents(Scalar & phi, Scalar & theta, Scalar & psi) const {
195 phi=fPhi; theta=fTheta; psi=fPsi;
196 }
197
198 /**
199 Set Phi Euler angle // JMM 30 Jan. 2006
200 */
201 void SetPhi(Scalar phi) { fPhi=phi; Rectify(); }
202
203 /**
204 Return Phi Euler angle
205 */
206 Scalar Phi() const { return fPhi; }
207
208 /**
209 Set Theta Euler angle // JMM 30 Jan. 2006
210 */
211 void SetTheta(Scalar theta) { fTheta=theta; Rectify(); }
212
213 /**
214 Return Theta Euler angle
215 */
216 Scalar Theta() const { return fTheta; }
217
218 /**
219 Set Psi Euler angle // JMM 30 Jan. 2006
220 */
221 void SetPsi(Scalar psi) { fPsi=psi; Rectify(); }
222
223 /**
224 Return Psi Euler angle
225 */
226 Scalar Psi() const { return fPsi; }
227
228 // =========== operations ==============
229
230
231 /**
232 Rotation operation on a displacement vector in any coordinate system and tag
233 */
234 template <class CoordSystem, class U>
237 return Rotation3D(*this) ( v );
238 }
239
240 /**
241 Rotation operation on a position vector in any coordinate system
242 */
243 template <class CoordSystem, class U>
248 return PositionVector3D<CoordSystem,U> ( rxyz );
249 }
250
251 /**
252 Rotation operation on a Lorentz vector in any 4D coordinate system
253 */
254 template <class CoordSystem>
258 xyz = operator()(xyz);
259 LorentzVector< PxPyPzE4D<double> > xyzt (xyz.X(), xyz.Y(), xyz.Z(), v.E());
260 return LorentzVector<CoordSystem> ( xyzt );
261 }
262
263 /**
264 Rotation operation on an arbitrary vector v.
265 Preconditions: v must implement methods x(), y(), and z()
266 and the arbitrary vector type must have a constructor taking (x,y,z)
267 */
268 template <class ForeignVector>
269 ForeignVector
270 operator() (const ForeignVector & v) const {
273 return ForeignVector ( rxyz.X(), rxyz.Y(), rxyz.Z() );
274 }
275
276 /**
277 Overload operator * for rotation on a vector
278 */
279 template <class AVector>
280 inline
281 AVector operator* (const AVector & v) const
282 {
283 return operator()(v);
284 }
285
286 /**
287 Invert a rotation in place
288 */
289 // theta stays the same and negative rotation in Theta is done via a rotation
290 // of + PI in phi and Psi
291 void Invert() {
292 Scalar tmp = -fPhi;
293 fPhi = -fPsi + Pi();
294 fPsi=tmp + Pi();
295 }
296
297 /**
298 Return inverse of a rotation
299 */
300 EulerAngles Inverse() const { return EulerAngles(-fPsi + Pi(), fTheta, -fPhi + Pi()); }
301
302 // ========= Multi-Rotation Operations ===============
303
304 /**
305 Multiply (combine) two rotations
306 */
307 EulerAngles operator * (const Rotation3D & r) const;
308 EulerAngles operator * (const AxisAngle & a) const;
309 EulerAngles operator * (const EulerAngles & e) const;
310 EulerAngles operator * (const Quaternion & q) const;
311 EulerAngles operator * (const RotationX & rx) const;
312 EulerAngles operator * (const RotationY & ry) const;
313 EulerAngles operator * (const RotationZ & rz) const;
314
315 /**
316 Post-Multiply (on right) by another rotation : T = T*R
317 */
318 template <class R>
319 EulerAngles & operator *= (const R & r) { return *this = (*this)*r; }
320
321 /**
322 Distance between two rotations
323 */
324 template <class R>
325 Scalar Distance ( const R & r ) const {return gv_detail::dist(*this,r);}
326
327 /**
328 Equality/inequality operators
329 */
330 bool operator == (const EulerAngles & rhs) const {
331 if( fPhi != rhs.fPhi ) return false;
332 if( fTheta != rhs.fTheta ) return false;
333 if( fPsi != rhs.fPsi ) return false;
334 return true;
335 }
336 bool operator != (const EulerAngles & rhs) const {
337 return ! operator==(rhs);
338 }
339
340private:
341
342 double fPhi; // Z rotation angle (first) defined in [-PI,PI]
343 double fTheta; // X rotation angle (second) defined only [0,PI]
344 double fPsi; // Z rotation angle (third) defined in [-PI,PI]
345
346 static double Pi() { return M_PI; }
347
348}; // EulerAngles
349
350/**
351 Distance between two rotations
352 */
353template <class R>
354inline
355typename EulerAngles::Scalar
356Distance ( const EulerAngles& r1, const R & r2) {return gv_detail::dist(r1,r2);}
357
358/**
359 Multiplication of an axial rotation by an AxisAngle
360 */
361EulerAngles operator* (RotationX const & r1, EulerAngles const & r2);
362EulerAngles operator* (RotationY const & r1, EulerAngles const & r2);
363EulerAngles operator* (RotationZ const & r1, EulerAngles const & r2);
364
365/**
366 Stream Output and Input
367 */
368 // TODO - I/O should be put in the manipulator form
369
370std::ostream & operator<< (std::ostream & os, const EulerAngles & e);
371
372} // namespace Math
373} // namespace ROOT
374
375
376#endif /* ROOT_Math_GenVector_EulerAngles */
ROOT::R::TRInterface & r
Definition: Object.C:4
#define e(i)
Definition: RSha256.hxx:103
#define M_PI
Definition: Rotated.cxx:105
float * q
Definition: THbookFile.cxx:87
typedef void((*Func_t)())
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition: AxisAngle.h:41
Class describing a generic displacement vector in 3 dimensions.
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
EulerAngles class describing rotation as three angles (Euler Angles).
Definition: EulerAngles.h:43
Scalar Psi() const
Return Psi Euler angle.
Definition: EulerAngles.h:226
bool operator!=(const EulerAngles &rhs) const
Definition: EulerAngles.h:336
Scalar Theta() const
Return Theta Euler angle.
Definition: EulerAngles.h:216
void SetPsi(Scalar psi)
Set Psi Euler angle // JMM 30 Jan.
Definition: EulerAngles.h:221
void SetTheta(Scalar theta)
Set Theta Euler angle // JMM 30 Jan.
Definition: EulerAngles.h:211
void GetComponents(IT begin, IT end) const
Get the axis and then the angle into data specified by an iterator begin and another to the end of th...
Definition: EulerAngles.h:165
void GetComponents(Scalar &phi, Scalar &theta, Scalar &psi) const
Get the components phi, theta, psi into three Scalars.
Definition: EulerAngles.h:194
EulerAngles()
Default constructor.
Definition: EulerAngles.h:52
void SetComponents(Scalar phi, Scalar theta, Scalar psi)
Set the components phi, theta, psi based on three Scalars.
Definition: EulerAngles.h:186
void GetComponents(IT begin) const
Get the axis and then the angle into data specified by an iterator begin.
Definition: EulerAngles.h:177
void SetPhi(Scalar phi)
Set Phi Euler angle // JMM 30 Jan.
Definition: EulerAngles.h:201
EulerAngles & operator*=(const R &r)
Post-Multiply (on right) by another rotation : T = T*R.
Definition: EulerAngles.h:319
EulerAngles & operator=(OtherRotation const &r)
Assign from any other rotation (see gv_detail::convert )
Definition: EulerAngles.h:89
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition: EulerAngles.h:281
EulerAngles(const OtherRotation &r)
Create from any other supported rotation (see gv_detail::convert )
Definition: EulerAngles.h:83
void Invert()
Invert a rotation in place.
Definition: EulerAngles.h:291
EulerAngles(IT begin, IT end)
Construct given a pair of pointers or iterators defining the beginning and end of an array of three S...
Definition: EulerAngles.h:67
bool operator==(const EulerAngles &rhs) const
Equality/inequality operators.
Definition: EulerAngles.h:330
EulerAngles Inverse() const
Return inverse of a rotation.
Definition: EulerAngles.h:300
static double Pi()
Definition: EulerAngles.h:346
void Rectify()
Re-adjust components place angles in canonical ranges.
Definition: EulerAngles.cxx:37
EulerAngles(Scalar phi, Scalar theta, Scalar psi)
Constructor from phi, theta and psi.
Definition: EulerAngles.h:57
DisplacementVector3D< CoordSystem, U > operator()(const DisplacementVector3D< CoordSystem, U > &v) const
Rotation operation on a displacement vector in any coordinate system and tag.
Definition: EulerAngles.h:236
Scalar Distance(const R &r) const
Distance between two rotations.
Definition: EulerAngles.h:325
Scalar Phi() const
Return Phi Euler angle.
Definition: EulerAngles.h:206
void SetComponents(IT begin, IT end)
Set the three Euler angles given a pair of pointers or iterators defining the beginning and end of an...
Definition: EulerAngles.h:151
Class describing a generic position vector (point) in 3 dimensions.
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Definition: Quaternion.h:47
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition: Rotation3D.h:65
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition: RotationX.h:43
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Definition: RotationY.h:43
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Definition: RotationZ.h:43
Namespace for new Math classes and functions.
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
void convert(R1 const &, R2 const)
Definition: 3DConversions.h:41
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition: AxisAngle.cxx:91
AxisAngle operator*(RotationX const &r1, AxisAngle const &r2)
Multiplication of an axial rotation by an AxisAngle.
AxisAngle::Scalar Distance(const AxisAngle &r1, const R &r2)
Distance between two rotations.
Definition: AxisAngle.h:320
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: StringConv.hxx:21
auto * a
Definition: textangle.C:12