Logo ROOT   6.08/07
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 #ifndef ROOT_Math_Math
22 #include "Math/Math.h"
23 #endif
24 
25 #ifndef ROOT_Math_GenVector_Rotation3D
27 #endif
28 
29 
30 #ifndef ROOT_Math_GenVector_DisplacementVector3D
32 #endif
33 
34 #ifndef ROOT_Math_GenVector_PositionVector3D
36 #endif
37 
38 #ifndef ROOT_Math_GenVector_LorentzVector
40 #endif
41 
42 #ifndef ROOT_Math_GenVector_3DConversions
44 #endif
45 
46 
47 #include <algorithm>
48 #include <cassert>
49 #include <iostream>
50 
51 
52 namespace ROOT {
53 namespace Math {
54 
55 
56 //__________________________________________________________________________________________
57  /**
58  Rotation class with the (3D) rotation represented by
59  angles describing first a rotation of
60  an angle phi (yaw) about the Z axis,
61  followed by a rotation of an angle theta (pitch) about the new Y' axis,
62  followed by a third rotation of an angle psi (roll) about the final X'' axis.
63  This is sometimes referred to as the Euler 321 sequence.
64  It has not to be confused with the typical Goldstein definition of the Euler Angles
65  (Z-X-Z or 313 sequence) which is used by the ROOT::Math::EulerAngles class.
66 
67 
68  @ingroup GenVector
69  */
70 
71 class RotationZYX {
72 
73 public:
74 
75  typedef double Scalar;
76 
77 
78  // ========== Constructors and Assignment =====================
79 
80  /**
81  Default constructor
82  */
83  RotationZYX() : fPhi(0.0), fTheta(0.0), fPsi(0.0) { }
84 
85  /**
86  Constructor from phi, theta and psi
87  */
88  RotationZYX( Scalar phi, Scalar theta, Scalar psi ) :
89  fPhi(phi), fTheta(theta), fPsi(psi)
90  {Rectify();} // Added 27 Jan. 06 JMM
91 
92  /**
93  Construct given a pair of pointers or iterators defining the
94  beginning and end of an array of three Scalars, to be treated as
95  the angles phi, theta and psi.
96  */
97  template<class IT>
98  RotationZYX(IT begin, IT end) { SetComponents(begin,end); }
99 
100  // The compiler-generated copy ctor, copy assignment, and dtor are OK.
101 
102  /**
103  Re-adjust components place angles in canonical ranges
104  */
105  void Rectify();
106 
107 
108  // ======== Construction and Assignment From other Rotation Forms ==================
109 
110  /**
111  Construct from another supported rotation type (see gv_detail::convert )
112  */
113  template <class OtherRotation>
114  explicit RotationZYX(const OtherRotation & r) {gv_detail::convert(r,*this);}
115 
116 
117  /**
118  Assign from another supported rotation type (see gv_detail::convert )
119  */
120  template <class OtherRotation>
121  RotationZYX & operator=( OtherRotation const & r ) {
122  gv_detail::convert(r,*this);
123  return *this;
124  }
125 
126 
127  // ======== Components ==============
128 
129  /**
130  Set the three Euler angles given a pair of pointers or iterators
131  defining the beginning and end of an array of three Scalars.
132  */
133  template<class IT>
134 #ifndef NDEBUG
135  void SetComponents(IT begin, IT end) {
136 #else
137  void SetComponents(IT begin, IT ) {
138 #endif
139  fPhi = *begin++;
140  fTheta = *begin++;
141  fPsi = *begin++;
142  assert(begin == end);
143  Rectify();
144  }
145 
146  /**
147  Get the axis and then the angle into data specified by an iterator begin
148  and another to the end of the desired data (4 past start).
149  */
150  template<class IT>
151 #ifndef NDEBUG
152  void GetComponents(IT begin, IT end) const {
153 #else
154  void GetComponents(IT begin, IT ) const {
155 #endif
156  *begin++ = fPhi;
157  *begin++ = fTheta;
158  *begin++ = fPsi;
159  assert(begin == end);
160  }
161 
162  /**
163  Get the axis and then the angle into data specified by an iterator begin
164  */
165  template<class IT>
166  void GetComponents(IT begin) const {
167  *begin++ = fPhi;
168  *begin++ = fTheta;
169  *begin = fPsi;
170  }
171 
172  /**
173  Set the components phi, theta, psi based on three Scalars.
174  */
175  void SetComponents(Scalar phi, Scalar theta, Scalar psi) {
176  fPhi=phi; fTheta=theta; fPsi=psi;
177  Rectify();
178  }
179 
180  /**
181  Get the components phi, theta, psi into three Scalars.
182  */
183  void GetComponents(Scalar & phi, Scalar & theta, Scalar & psi) const {
184  phi=fPhi; theta=fTheta; psi=fPsi;
185  }
186 
187  /**
188  Set Phi angle (Z rotation angle)
189  */
190  void SetPhi(Scalar phi) { fPhi=phi; Rectify(); }
191 
192  /**
193  Return Phi angle (Z rotation angle)
194  */
195  Scalar Phi() const { return fPhi; }
196 
197  /**
198  Set Theta angle (Y' rotation angle)
199  */
200  void SetTheta(Scalar theta) { fTheta=theta; Rectify(); }
201 
202  /**
203  Return Theta angle (Y' rotation angle)
204  */
205  Scalar Theta() const { return fTheta; }
206 
207  /**
208  Set Psi angle (X'' rotation angle)
209  */
210  void SetPsi(Scalar psi) { fPsi=psi; Rectify(); }
211 
212  /**
213  Return Psi angle (X'' rotation angle)
214  */
215  Scalar Psi() const { return fPsi; }
216 
217  // =========== operations ==============
218 
219 
220  /**
221  Rotation operation on a displacement vector in any coordinate system and tag
222  */
223  template <class CoordSystem, class U>
226  return Rotation3D(*this) ( v );
227  }
228 
229  /**
230  Rotation operation on a position vector in any coordinate system
231  */
232  template <class CoordSystem, class U>
237  return PositionVector3D<CoordSystem,U> ( rxyz );
238  }
239 
240  /**
241  Rotation operation on a Lorentz vector in any 4D coordinate system
242  */
243  template <class CoordSystem>
247  xyz = operator()(xyz);
248  LorentzVector< PxPyPzE4D<double> > xyzt (xyz.X(), xyz.Y(), xyz.Z(), v.E());
249  return LorentzVector<CoordSystem> ( xyzt );
250  }
251 
252  /**
253  Rotation operation on an arbitrary vector v.
254  Preconditions: v must implement methods x(), y(), and z()
255  and the arbitrary vector type must have a constructor taking (x,y,z)
256  */
257  template <class ForeignVector>
258  ForeignVector
259  operator() (const ForeignVector & v) const {
262  return ForeignVector ( rxyz.X(), rxyz.Y(), rxyz.Z() );
263  }
264 
265  /**
266  Overload operator * for rotation on a vector
267  */
268  template <class AVector>
269  inline
270  AVector operator* (const AVector & v) const
271  {
272  return operator()(v);
273  }
274 
275  /**
276  Invert a rotation in place
277  */
278  void Invert();
279 
280  /**
281  Return inverse of a rotation
282  */
284  RotationZYX r(*this);
285  r.Invert();
286  return r;
287  }
288 
289 
290  // ========= Multi-Rotation Operations ===============
291 
292  /**
293  Multiply (combine) two rotations
294  */
295  RotationZYX operator * (const RotationZYX & e) const;
296  RotationZYX operator * (const Rotation3D & r) const;
297  RotationZYX operator * (const AxisAngle & a) const;
298  RotationZYX operator * (const Quaternion & q) const;
299  RotationZYX operator * (const EulerAngles & q) const;
300  RotationZYX operator * (const RotationX & rx) const;
301  RotationZYX operator * (const RotationY & ry) const;
302  RotationZYX operator * (const RotationZ & rz) const;
303 
304  /**
305  Post-Multiply (on right) by another rotation : T = T*R
306  */
307  template <class R>
308  RotationZYX & operator *= (const R & r) { return *this = (*this)*r; }
309 
310  /**
311  Distance between two rotations
312  */
313  template <class R>
314  Scalar Distance ( const R & r ) const {return gv_detail::dist(*this,r);}
315 
316  /**
317  Equality/inequality operators
318  */
319  bool operator == (const RotationZYX & rhs) const {
320  if( fPhi != rhs.fPhi ) return false;
321  if( fTheta != rhs.fTheta ) return false;
322  if( fPsi != rhs.fPsi ) return false;
323  return true;
324  }
325  bool operator != (const RotationZYX & rhs) const {
326  return ! operator==(rhs);
327  }
328 
329 private:
330 
331  double fPhi; // Z rotation angle (yaw) defined in (-PI,PI]
332  double fTheta; // Y' rotation angle (pitch) defined in [-PI/2,PI/2]
333  double fPsi; // X'' rotation angle (roll) defined in (-PI,PI]
334 
335  static double Pi() { return M_PI; }
336 
337 }; // RotationZYX
338 
339 /**
340  Distance between two rotations
341  */
342 template <class R>
343 inline
344 typename RotationZYX::Scalar
345 Distance ( const RotationZYX& r1, const R & r2) {return gv_detail::dist(r1,r2);}
346 
347 /**
348  Multiplication of an axial rotation by an AxisAngle
349  */
350 RotationZYX operator* (RotationX const & r1, RotationZYX const & r2);
351 RotationZYX operator* (RotationY const & r1, RotationZYX const & r2);
352 RotationZYX operator* (RotationZ const & r1, RotationZYX const & r2);
353 
354 /**
355  Stream Output and Input
356  */
357  // TODO - I/O should be put in the manipulator form
358 
359 std::ostream & operator<< (std::ostream & os, const RotationZYX & e);
360 
361 
362 } // namespace Math
363 } // namespace ROOT
364 
365 #endif // ROOT_Math_GenVector_RotationZYX
Class describing a generic LorentzVector in the 4D space-time, using the specified coordinate system ...
Definition: LorentzVector.h:54
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:183
Scalar Psi() const
Return Psi angle (X&#39;&#39; rotation angle)
Definition: RotationZYX.h:215
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition: RotationZYX.h:270
void SetPsi(Scalar psi)
Set Psi angle (X&#39;&#39; rotation angle)
Definition: RotationZYX.h:210
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:308
void Rectify()
Re-adjust components place angles in canonical ranges.
void SetPhi(Scalar phi)
Set Phi angle (Z rotation angle)
Definition: RotationZYX.h:190
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:71
TArc * a
Definition: textangle.C:12
static double Pi()
Definition: RotationZYX.h:335
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:98
void GetComponents(IT begin) const
Get the axis and then the angle into data specified by an iterator begin.
Definition: RotationZYX.h:166
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:114
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:225
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.
Scalar E() const
return 4-th component (time, or energy for a 4-momentum vector)
Class describing a generic displacement vector in 3 dimensions.
TRandom2 r(17)
#define M_PI
Definition: Rotated.cxx:105
SVector< double, 2 > v
Definition: Dict.h:5
unsigned int r1[N_CITIES]
Definition: simanTSP.cxx:321
RotationZYX()
Default constructor.
Definition: RotationZYX.h:83
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:175
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:200
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:152
void Invert()
Invert a rotation in place.
bool operator!=(const RotationZYX &rhs) const
Definition: RotationZYX.h:325
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:319
Scalar Theta() const
Return Theta angle (Y&#39; rotation angle)
Definition: RotationZYX.h:205
Namespace for new Math classes and functions.
RotationZYX Inverse() const
Return inverse of a rotation.
Definition: RotationZYX.h:283
Scalar Phi() const
Return Phi angle (Z rotation angle)
Definition: RotationZYX.h:195
RotationZYX(Scalar phi, Scalar theta, Scalar psi)
Constructor from phi, theta and psi.
Definition: RotationZYX.h:88
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:135
RotationZYX & operator=(OtherRotation const &r)
Assign from another supported rotation type (see gv_detail::convert )
Definition: RotationZYX.h:121
::ROOT::Math::DisplacementVector3D< Cartesian3D< Scalar > > Vect() const
get the spatial components of the Vector in a DisplacementVector based on Cartesian Coordinates ...
Scalar Distance(const R &r) const
Distance between two rotations.
Definition: RotationZYX.h:314
TRandom3 R
a TMatrixD.
Definition: testIO.cxx:28
unsigned int r2[N_CITIES]
Definition: simanTSP.cxx:322