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