Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
43 @sa Overview of the @ref GenVector "physics vector library"
44 */
46
47public:
48
49 typedef double Scalar;
50
51 /**
52 Default constructor
53 */
54 constexpr EulerAngles() : fPhi(0.0), fTheta(0.0), fPsi(0.0) { }
55
56 /**
57 Constructor from phi, theta and psi
58 */
59 EulerAngles( Scalar phi, Scalar theta, Scalar psi ) :
60 fPhi(phi), fTheta(theta), fPsi(psi)
61 {Rectify();} // Added 27 Jan. 06 JMM
62
63 /**
64 Construct given a pair of pointers or iterators defining the
65 beginning and end of an array of three Scalars, to be treated as
66 the angles phi, theta and psi.
67 */
68 template<class IT>
69 constexpr EulerAngles(IT begin, IT end) { SetComponents(begin,end); }
70
71 // The compiler-generated copy ctor, copy assignment, and dtor are OK.
72
73 /**
74 Re-adjust components place angles in canonical ranges
75 */
76 void Rectify();
77
78
79 // ======== Construction and assignment from any other rotation ==================
80
81 /**
82 Create from any other supported rotation (see gv_detail::convert )
83 */
84 template <class OtherRotation>
85 explicit constexpr EulerAngles(const OtherRotation & r) {gv_detail::convert(r,*this);}
86
87 /**
88 Assign from any other rotation (see gv_detail::convert )
89 */
90 template <class OtherRotation>
91 EulerAngles & operator=( OtherRotation const & r ) {
92 gv_detail::convert(r,*this);
93 return *this;
94 }
95
96#ifdef OLD
97 explicit EulerAngles(const Rotation3D & r) {gv_detail::convert(r,*this);}
98
99 /**
100 Construct from a rotation matrix
101 */
102 explicit EulerAngles(const Rotation3D & r) {gv_detail::convert(r,*this);}
103
104 /**
105 Construct from a rotation represented by a Quaternion
106 */
107 explicit EulerAngles(const Quaternion & q) {gv_detail::convert(q,*this);}
108
109 /**
110 Construct from an AxisAngle
111 */
112 explicit EulerAngles(const AxisAngle & a ) { gv_detail::convert(a, *this); }
113
114 /**
115 Construct from an axial rotation
116 */
117 explicit EulerAngles( RotationZ const & r ) { gv_detail::convert(r, *this); }
118 explicit EulerAngles( RotationY const & r ) { gv_detail::convert(r, *this); }
119 explicit EulerAngles( RotationX const & r ) { gv_detail::convert(r, *this); }
120
121
122 /**
123 Assign from an AxisAngle
124 */
126 operator=( AxisAngle const & a ) { return operator=(EulerAngles(a)); }
127
128 /**
129 Assign from a Quaternion
130 */
132 operator=( Quaternion const & q ) {return operator=(EulerAngles(q)); }
133
134 /**
135 Assign from an axial rotation
136 */
138 operator=( RotationZ const & r ) { return operator=(EulerAngles(r)); }
140 operator=( RotationY const & r ) { return operator=(EulerAngles(r)); }
142 operator=( RotationX const & r ) { return operator=(EulerAngles(r)); }
143
144#endif
145
146 // ======== Components ==============
147
148 /**
149 Set the three Euler angles given a pair of pointers or iterators
150 defining the beginning and end of an array of three Scalars.
151 */
152 template<class IT>
153 void SetComponents(IT begin, IT end) {
154 fPhi = *begin++;
155 fTheta = *begin++;
156 fPsi = *begin++;
157 (void)end;
158 assert(begin == end);
159 Rectify(); // Added 27 Jan. 06 JMM
160 }
161
162 /**
163 Get the axis and then the angle into data specified by an iterator begin
164 and another to the end of the desired data (4 past start).
165 */
166 template<class IT>
167 void GetComponents(IT begin, IT end) const {
168 *begin++ = fPhi;
169 *begin++ = fTheta;
170 *begin++ = fPsi;
171 (void)end;
172 assert(begin == end);
173 }
174
175 /**
176 Get the axis and then the angle into data specified by an iterator begin
177 */
178 template<class IT>
179 void GetComponents(IT begin) const {
180 *begin++ = fPhi;
181 *begin++ = fTheta;
182 *begin = fPsi;
183 }
184
185 /**
186 Set the components phi, theta, psi based on three Scalars.
187 */
188 void SetComponents(Scalar phi, Scalar theta, Scalar psi) {
189 fPhi=phi; fTheta=theta; fPsi=psi;
190 Rectify(); // Added 27 Jan. 06 JMM
191 }
192
193 /**
194 Get the components phi, theta, psi into three Scalars.
195 */
196 void GetComponents(Scalar & phi, Scalar & theta, Scalar & psi) const {
197 phi=fPhi; theta=fTheta; psi=fPsi;
198 }
199
200 /**
201 Set Phi Euler angle // JMM 30 Jan. 2006
202 */
203 void SetPhi(Scalar phi) { fPhi=phi; Rectify(); }
204
205 /**
206 Return Phi Euler angle
207 */
208 Scalar Phi() const { return fPhi; }
209
210 /**
211 Set Theta Euler angle // JMM 30 Jan. 2006
212 */
213 void SetTheta(Scalar theta) { fTheta=theta; Rectify(); }
214
215 /**
216 Return Theta Euler angle
217 */
218 Scalar Theta() const { return fTheta; }
219
220 /**
221 Set Psi Euler angle // JMM 30 Jan. 2006
222 */
223 void SetPsi(Scalar psi) { fPsi=psi; Rectify(); }
224
225 /**
226 Return Psi Euler angle
227 */
228 Scalar Psi() const { return fPsi; }
229
230 // =========== operations ==============
231
232
233 /**
234 Rotation operation on a displacement vector in any coordinate system and tag
235 */
236 template <class CoordSystem, class U>
239 return Rotation3D(*this) ( v );
240 }
241
242 /**
243 Rotation operation on a position vector in any coordinate system
244 */
245 template <class CoordSystem, class U>
250 return PositionVector3D<CoordSystem,U> ( rxyz );
251 }
252
253 /**
254 Rotation operation on a Lorentz vector in any 4D coordinate system
255 */
256 template <class CoordSystem>
260 xyz = operator()(xyz);
261 LorentzVector< PxPyPzE4D<double> > xyzt (xyz.X(), xyz.Y(), xyz.Z(), v.E());
262 return LorentzVector<CoordSystem> ( xyzt );
263 }
264
265 /**
266 Rotation operation on an arbitrary vector v.
267 Preconditions: v must implement methods x(), y(), and z()
268 and the arbitrary vector type must have a constructor taking (x,y,z)
269 */
270 template <class ForeignVector>
271 ForeignVector
272 operator() (const ForeignVector & v) const {
275 return ForeignVector ( rxyz.X(), rxyz.Y(), rxyz.Z() );
276 }
277
278 /**
279 Overload operator * for rotation on a vector
280 */
281 template <class AVector>
282 inline
283 AVector operator* (const AVector & v) const
284 {
285 return operator()(v);
286 }
287
288 /**
289 Invert a rotation in place
290 */
291 // theta stays the same and negative rotation in Theta is done via a rotation
292 // of + PI in phi and Psi
293 void Invert() {
294 Scalar tmp = -fPhi;
295 fPhi = -fPsi + Pi();
296 fPsi=tmp + Pi();
297 }
298
299 /**
300 Return inverse of a rotation
301 */
302 EulerAngles Inverse() const { return EulerAngles(-fPsi + Pi(), fTheta, -fPhi + Pi()); }
303
304 // ========= Multi-Rotation Operations ===============
305
306 /**
307 Multiply (combine) two rotations
308 */
309 EulerAngles operator * (const Rotation3D & r) const;
310 EulerAngles operator * (const AxisAngle & a) const;
311 EulerAngles operator * (const EulerAngles & e) const;
312 EulerAngles operator * (const Quaternion & q) const;
313 EulerAngles operator * (const RotationX & rx) const;
314 EulerAngles operator * (const RotationY & ry) const;
315 EulerAngles operator * (const RotationZ & rz) const;
316
317 /**
318 Post-Multiply (on right) by another rotation : T = T*R
319 */
320 template <class R>
321 EulerAngles & operator *= (const R & r) { return *this = (*this)*r; }
322
323 /**
324 Distance between two rotations
325 */
326 template <class R>
327 Scalar Distance ( const R & r ) const {return gv_detail::dist(*this,r);}
328
329 /**
330 Equality/inequality operators
331 */
332 bool operator == (const EulerAngles & rhs) const {
333 if( fPhi != rhs.fPhi ) return false;
334 if( fTheta != rhs.fTheta ) return false;
335 if( fPsi != rhs.fPsi ) return false;
336 return true;
337 }
338 bool operator != (const EulerAngles & rhs) const {
339 return ! operator==(rhs);
340 }
341
342private:
343
344 double fPhi; // Z rotation angle (first) defined in [-PI,PI]
345 double fTheta; // X rotation angle (second) defined only [0,PI]
346 double fPsi; // Z rotation angle (third) defined in [-PI,PI]
347
348 static double Pi() { return M_PI; }
349
350}; // EulerAngles
351
352/**
353 Distance between two rotations
354 */
355template <class R>
356inline
357typename EulerAngles::Scalar
358Distance ( const EulerAngles& r1, const R & r2) {return gv_detail::dist(r1,r2);}
359
360/**
361 Multiplication of an axial rotation by an AxisAngle
362 */
363EulerAngles operator* (RotationX const & r1, EulerAngles const & r2);
364EulerAngles operator* (RotationY const & r1, EulerAngles const & r2);
365EulerAngles operator* (RotationZ const & r1, EulerAngles const & r2);
366
367/**
368 Stream Output and Input
369 */
370 // TODO - I/O should be put in the manipulator form
371
372std::ostream & operator<< (std::ostream & os, const EulerAngles & e);
373
374} // namespace Math
375} // namespace ROOT
376
377
378#endif /* ROOT_Math_GenVector_EulerAngles */
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
#define M_PI
Definition Rotated.cxx:105
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
float * q
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition AxisAngle.h:42
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:45
Scalar Psi() const
Return Psi Euler angle.
bool operator!=(const EulerAngles &rhs) const
Scalar Theta() const
Return Theta Euler angle.
void SetPsi(Scalar psi)
Set Psi Euler angle // JMM 30 Jan.
void SetTheta(Scalar theta)
Set Theta Euler angle // JMM 30 Jan.
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...
void GetComponents(Scalar &phi, Scalar &theta, Scalar &psi) const
Get the components phi, theta, psi into three Scalars.
void SetComponents(Scalar phi, Scalar theta, Scalar psi)
Set the components phi, theta, psi based on three Scalars.
void GetComponents(IT begin) const
Get the axis and then the angle into data specified by an iterator begin.
void SetPhi(Scalar phi)
Set Phi Euler angle // JMM 30 Jan.
EulerAngles & operator*=(const R &r)
Post-Multiply (on right) by another rotation : T = T*R.
EulerAngles & operator=(OtherRotation const &r)
Assign from any other rotation (see gv_detail::convert )
Definition EulerAngles.h:91
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
constexpr 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:69
void Invert()
Invert a rotation in place.
bool operator==(const EulerAngles &rhs) const
Equality/inequality operators.
EulerAngles Inverse() const
Return inverse of a rotation.
void Rectify()
Re-adjust components place angles in canonical ranges.
EulerAngles(Scalar phi, Scalar theta, Scalar psi)
Constructor from phi, theta and psi.
Definition EulerAngles.h:59
DisplacementVector3D< CoordSystem, U > operator()(const DisplacementVector3D< CoordSystem, U > &v) const
Rotation operation on a displacement vector in any coordinate system and tag.
constexpr EulerAngles()
Default constructor.
Definition EulerAngles.h:54
constexpr EulerAngles(const OtherRotation &r)
Create from any other supported rotation (see gv_detail::convert )
Definition EulerAngles.h:85
Scalar Distance(const R &r) const
Distance between two rotations.
Scalar Phi() const
Return Phi Euler angle.
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...
Class describing a generic LorentzVector in the 4D space-time, using the specified coordinate system ...
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:49
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition Rotation3D.h:67
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition RotationX.h:45
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Definition RotationY.h:45
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Definition RotationZ.h:45
Namespace for new Math classes and functions.
double dist(Rotation3D const &r1, Rotation3D const &r2)
void convert(R1 const &, R2 const)
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:321
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...