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