Logo ROOT  
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  void SetComponents(IT begin, IT end) {
125  fPhi = *begin++;
126  fTheta = *begin++;
127  fPsi = *begin++;
128  (void)end;
129  assert(begin == end);
130  Rectify();
131  }
132 
133  /**
134  Get the axis and then the angle into data specified by an iterator begin
135  and another to the end of the desired data (4 past start).
136  */
137  template<class IT>
138  void GetComponents(IT begin, IT end) const {
139  *begin++ = fPhi;
140  *begin++ = fTheta;
141  *begin++ = fPsi;
142  (void)end;
143  assert(begin == end);
144  }
145 
146  /**
147  Get the axis and then the angle into data specified by an iterator begin
148  */
149  template<class IT>
150  void GetComponents(IT begin) const {
151  *begin++ = fPhi;
152  *begin++ = fTheta;
153  *begin = fPsi;
154  }
155 
156  /**
157  Set the components phi, theta, psi based on three Scalars.
158  */
159  void SetComponents(Scalar phi, Scalar theta, Scalar psi) {
160  fPhi=phi; fTheta=theta; fPsi=psi;
161  Rectify();
162  }
163 
164  /**
165  Get the components phi, theta, psi into three Scalars.
166  */
167  void GetComponents(Scalar & phi, Scalar & theta, Scalar & psi) const {
168  phi=fPhi; theta=fTheta; psi=fPsi;
169  }
170 
171  /**
172  Set Phi angle (Z rotation angle)
173  */
174  void SetPhi(Scalar phi) { fPhi=phi; Rectify(); }
175 
176  /**
177  Return Phi angle (Z rotation angle)
178  */
179  Scalar Phi() const { return fPhi; }
180 
181  /**
182  Set Theta angle (Y' rotation angle)
183  */
184  void SetTheta(Scalar theta) { fTheta=theta; Rectify(); }
185 
186  /**
187  Return Theta angle (Y' rotation angle)
188  */
189  Scalar Theta() const { return fTheta; }
190 
191  /**
192  Set Psi angle (X'' rotation angle)
193  */
194  void SetPsi(Scalar psi) { fPsi=psi; Rectify(); }
195 
196  /**
197  Return Psi angle (X'' rotation angle)
198  */
199  Scalar Psi() const { return fPsi; }
200 
201  // =========== operations ==============
202 
203 
204  /**
205  Rotation operation on a displacement vector in any coordinate system and tag
206  */
207  template <class CoordSystem, class U>
210  return Rotation3D(*this) ( v );
211  }
212 
213  /**
214  Rotation operation on a position vector in any coordinate system
215  */
216  template <class CoordSystem, class U>
221  return PositionVector3D<CoordSystem,U> ( rxyz );
222  }
223 
224  /**
225  Rotation operation on a Lorentz vector in any 4D coordinate system
226  */
227  template <class CoordSystem>
229  operator() (const LorentzVector<CoordSystem> & v) const {
231  xyz = operator()(xyz);
232  LorentzVector< PxPyPzE4D<double> > xyzt (xyz.X(), xyz.Y(), xyz.Z(), v.E());
233  return LorentzVector<CoordSystem> ( xyzt );
234  }
235 
236  /**
237  Rotation operation on an arbitrary vector v.
238  Preconditions: v must implement methods x(), y(), and z()
239  and the arbitrary vector type must have a constructor taking (x,y,z)
240  */
241  template <class ForeignVector>
242  ForeignVector
243  operator() (const ForeignVector & v) const {
246  return ForeignVector ( rxyz.X(), rxyz.Y(), rxyz.Z() );
247  }
248 
249  /**
250  Overload operator * for rotation on a vector
251  */
252  template <class AVector>
253  inline
254  AVector operator* (const AVector & v) const
255  {
256  return operator()(v);
257  }
258 
259  /**
260  Invert a rotation in place
261  */
262  void Invert();
263 
264  /**
265  Return inverse of a rotation
266  */
267  RotationZYX Inverse() const {
268  RotationZYX r(*this);
269  r.Invert();
270  return r;
271  }
272 
273 
274  // ========= Multi-Rotation Operations ===============
275 
276  /**
277  Multiply (combine) two rotations
278  */
279  RotationZYX operator * (const RotationZYX & e) const;
280  RotationZYX operator * (const Rotation3D & r) const;
281  RotationZYX operator * (const AxisAngle & a) const;
283  RotationZYX operator * (const EulerAngles & q) const;
284  RotationZYX operator * (const RotationX & rx) const;
285  RotationZYX operator * (const RotationY & ry) const;
286  RotationZYX operator * (const RotationZ & rz) const;
287 
288  /**
289  Post-Multiply (on right) by another rotation : T = T*R
290  */
291  template <class R>
292  RotationZYX & operator *= (const R & r) { return *this = (*this)*r; }
293 
294  /**
295  Distance between two rotations
296  */
297  template <class R>
298  Scalar Distance ( const R & r ) const {return gv_detail::dist(*this,r);}
299 
300  /**
301  Equality/inequality operators
302  */
303  bool operator == (const RotationZYX & rhs) const {
304  if( fPhi != rhs.fPhi ) return false;
305  if( fTheta != rhs.fTheta ) return false;
306  if( fPsi != rhs.fPsi ) return false;
307  return true;
308  }
309  bool operator != (const RotationZYX & rhs) const {
310  return ! operator==(rhs);
311  }
312 
313 private:
314 
315  double fPhi; // Z rotation angle (yaw) defined in (-PI,PI]
316  double fTheta; // Y' rotation angle (pitch) defined in [-PI/2,PI/2]
317  double fPsi; // X'' rotation angle (roll) defined in (-PI,PI]
318 
319  static double Pi() { return M_PI; }
320 
321 }; // RotationZYX
322 
323 /**
324  Distance between two rotations
325  */
326 template <class R>
327 inline
328 typename RotationZYX::Scalar
329 Distance ( const RotationZYX& r1, const R & r2) {return gv_detail::dist(r1,r2);}
330 
331 /**
332  Multiplication of an axial rotation by an AxisAngle
333  */
334 RotationZYX operator* (RotationX const & r1, RotationZYX const & r2);
335 RotationZYX operator* (RotationY const & r1, RotationZYX const & r2);
336 RotationZYX operator* (RotationZ const & r1, RotationZYX const & r2);
337 
338 /**
339  Stream Output and Input
340  */
341  // TODO - I/O should be put in the manipulator form
342 
343 std::ostream & operator<< (std::ostream & os, const RotationZYX & e);
344 
345 
346 } // namespace Math
347 } // namespace ROOT
348 
349 #endif // ROOT_Math_GenVector_RotationZYX
ROOT::Math::RotationZYX::SetPhi
void SetPhi(Scalar phi)
Set Phi angle (Z rotation angle)
Definition: RotationZYX.h:189
ROOT::Math::RotationZYX::operator!=
bool operator!=(const RotationZYX &rhs) const
Definition: RotationZYX.h:324
ROOT::Math::AxisAngle
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition: AxisAngle.h:51
e
#define e(i)
Definition: RSha256.hxx:121
ROOT::Math::RotationZYX::fTheta
double fTheta
Definition: RotationZYX.h:331
ROOT::Math::RotationZYX::Theta
Scalar Theta() const
Return Theta angle (Y' rotation angle)
Definition: RotationZYX.h:204
ROOT::Math::RotationZYX::Pi
static double Pi()
Definition: RotationZYX.h:334
ROOT::Math::RotationZYX::operator*=
RotationZYX & operator*=(const R &r)
Post-Multiply (on right) by another rotation : T = T*R.
Definition: RotationZYX.h:307
ROOT::Math::RotationZYX::Rectify
void Rectify()
Re-adjust components place angles in canonical ranges.
Definition: RotationZYX.cxx:118
ROOT::Math::RotationZYX
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Definition: RotationZYX.h:71
ROOT::Math::PositionVector3D
Class describing a generic position vector (point) in 3 dimensions.
Definition: PositionVector3D.h:63
r
ROOT::R::TRInterface & r
Definition: Object.C:4
ROOT::Math::RotationZ
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Definition: RotationZ.h:53
ROOT::Math::Rotation3D
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition: Rotation3D.h:75
ROOT::Math::RotationZYX::SetTheta
void SetTheta(Scalar theta)
Set Theta angle (Y' rotation angle)
Definition: RotationZYX.h:199
ROOT::Math::operator<<
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition: AxisAngle.cxx:101
ROOT::Math::RotationZYX::RotationZYX
RotationZYX()
Default constructor.
Definition: RotationZYX.h:88
ROOT::Math::DisplacementVector3D::Y
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
Definition: DisplacementVector3D.h:287
ROOT::Math::RotationZYX::Inverse
RotationZYX Inverse() const
Return inverse of a rotation.
Definition: RotationZYX.h:282
v
@ v
Definition: rootcling_impl.cxx:3635
q
float * q
Definition: THbookFile.cxx:89
R
#define R(a, b, c, d, e, f, g, h, i)
Definition: RSha256.hxx:128
ROOT::Math::RotationZYX::SetComponents
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:139
ROOT::Math::gv_detail::dist
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:63
ROOT::Math::RotationZYX::fPhi
double fPhi
Definition: RotationZYX.h:330
ROOT::Math::RotationZYX::Distance
Scalar Distance(const R &r) const
Distance between two rotations.
Definition: RotationZYX.h:313
Math.h
ROOT::Math::RotationZYX::fPsi
double fPsi
Definition: RotationZYX.h:332
a
auto * a
Definition: textangle.C:12
ROOT::Math::RotationZYX::operator==
bool operator==(const RotationZYX &rhs) const
Equality/inequality operators.
Definition: RotationZYX.h:318
ROOT::Math::EulerAngles
EulerAngles class describing rotation as three angles (Euler Angles).
Definition: EulerAngles.h:53
ROOT::Math::RotationZYX::Scalar
double Scalar
Definition: RotationZYX.h:80
ROOT::Math::DisplacementVector3D::X
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Definition: DisplacementVector3D.h:282
ROOT::Math::RotationX
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition: RotationX.h:53
PositionVector3D.h
void
typedef void((*Func_t)())
ROOT::Math::RotationZYX::Phi
Scalar Phi() const
Return Phi angle (Z rotation angle)
Definition: RotationZYX.h:194
ROOT::Math::DisplacementVector3D::Z
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
Definition: DisplacementVector3D.h:292
3DConversions.h
ROOT::Math::operator*
AxisAngle operator*(RotationX const &r1, AxisAngle const &r2)
Multiplication of an axial rotation by an AxisAngle.
Definition: AxisAngleXother.cxx:191
Rotation3D.h
ROOT::Math::RotationZYX::operator=
RotationZYX & operator=(OtherRotation const &r)
Assign from another supported rotation type (see gv_detail::convert )
Definition: RotationZYX.h:126
DisplacementVector3D.h
ROOT::Math::RotationZYX::SetPsi
void SetPsi(Scalar psi)
Set Psi angle (X'' rotation angle)
Definition: RotationZYX.h:209
ROOT::Math::Scalar
Rotation3D::Scalar Scalar
Definition: Rotation3DxAxial.cxx:69
M_PI
#define M_PI
Definition: Rotated.cxx:105
ROOT::Math::gv_detail::convert
void convert(R1 const &, R2 const)
Definition: 3DConversions.h:56
ROOT::Math::DisplacementVector3D
Class describing a generic displacement vector in 3 dimensions.
Definition: DisplacementVector3D.h:67
ROOT::Math::RotationZYX::Invert
void Invert()
Invert a rotation in place.
Definition: RotationZYX.cxx:148
LorentzVector.h
ROOT::Math::RotationZYX::operator*
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition: RotationZYX.h:269
ROOT::Math::Quaternion
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Definition: Quaternion.h:57
ROOT::Math::RotationZYX::operator()
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:224
ROOT::Math::Distance
AxisAngle::Scalar Distance(const AxisAngle &r1, const R &r2)
Distance between two rotations.
Definition: AxisAngle.h:330
ROOT
VSD Structures.
Definition: StringConv.hxx:21
ROOT::Math::RotationZYX::Psi
Scalar Psi() const
Return Psi angle (X'' rotation angle)
Definition: RotationZYX.h:214
Math
ROOT::Math::LorentzVector
Definition: LorentzVector.h:70
ROOT::Math::RotationY
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Definition: RotationY.h:53
ROOT::Math::RotationZYX::GetComponents
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:153