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