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