 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
40namespace ROOT {
41namespace 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
62
63public:
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>
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 */
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;
282 RotationZYX operator * (const Quaternion & q) 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
313private:
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 */
326template <class R>
327inline
328typename RotationZYX::Scalar
329Distance ( const RotationZYX& r1, const R & r2) {return gv_detail::dist(r1,r2);}
330
331/**
332 Multiplication of an axial rotation by an AxisAngle
333 */
334RotationZYX operator* (RotationX const & r1, RotationZYX const & r2);
335RotationZYX operator* (RotationY const & r1, RotationZYX const & r2);
336RotationZYX 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
343std::ostream & operator<< (std::ostream & os, const RotationZYX & e);
344
345
346} // namespace Math
347} // namespace ROOT
348
349#endif // ROOT_Math_GenVector_RotationZYX
ROOT::R::TRInterface & r
Definition: Object.C:4
#define R(a, b, c, d, e, f, g, h, i)
Definition: RSha256.hxx:110
#define e(i)
Definition: RSha256.hxx:103
#define M_PI
Definition: Rotated.cxx:105
float * q
Definition: THbookFile.cxx:87
typedef void((*Func_t)())
AxisAngle class describing rotation represented with direction axis (3D Vector) and an angle of rotat...
Definition: AxisAngle.h:41
Class describing a generic displacement vector in 3 dimensions.
Scalar X() const
Cartesian X, converting if necessary from internal coordinate system.
Scalar Y() const
Cartesian Y, converting if necessary from internal coordinate system.
Scalar Z() const
Cartesian Z, converting if necessary from internal coordinate system.
EulerAngles class describing rotation as three angles (Euler Angles).
Definition: EulerAngles.h:43
Class describing a generic position vector (point) in 3 dimensions.
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Definition: Quaternion.h:47
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition: Rotation3D.h:65
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition: RotationX.h:43
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Definition: RotationY.h:43
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Definition: RotationZYX.h:61
Scalar Phi() const
Return Phi angle (Z rotation angle)
Definition: RotationZYX.h:179
RotationZYX & operator*=(const R &r)
Post-Multiply (on right) by another rotation : T = T*R.
Definition: RotationZYX.h:292
void GetComponents(Scalar &phi, Scalar &theta, Scalar &psi) const
Get the components phi, theta, psi into three Scalars.
Definition: RotationZYX.h:167
Scalar Distance(const R &r) const
Distance between two rotations.
Definition: RotationZYX.h:298
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
Scalar Psi() const
Return Psi angle (X'' rotation angle)
Definition: RotationZYX.h:199
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:138
RotationZYX & operator=(OtherRotation const &r)
Assign from another supported rotation type (see gv_detail::convert )
Definition: RotationZYX.h:111
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:124
static double Pi()
Definition: RotationZYX.h:319
RotationZYX()
Default constructor.
Definition: RotationZYX.h:73
Scalar Theta() const
Return Theta angle (Y' rotation angle)
Definition: RotationZYX.h:189
bool operator!=(const RotationZYX &rhs) const
Definition: RotationZYX.h:309
RotationZYX(Scalar phi, Scalar theta, Scalar psi)
Constructor from phi, theta and psi.
Definition: RotationZYX.h:78
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:209
void GetComponents(IT begin) const
Get the axis and then the angle into data specified by an iterator begin.
Definition: RotationZYX.h:150
void SetPhi(Scalar phi)
Set Phi angle (Z rotation angle)
Definition: RotationZYX.h:174
void SetPsi(Scalar psi)
Set Psi angle (X'' rotation angle)
Definition: RotationZYX.h:194
bool operator==(const RotationZYX &rhs) const
Equality/inequality operators.
Definition: RotationZYX.h:303
void Rectify()
Re-adjust components place angles in canonical ranges.
void SetTheta(Scalar theta)
Set Theta angle (Y' rotation angle)
Definition: RotationZYX.h:184
RotationZYX(const OtherRotation &r)
Construct from another supported rotation type (see gv_detail::convert )
Definition: RotationZYX.h:104
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
Definition: RotationZYX.h:254
void Invert()
Invert a rotation in place.
void SetComponents(Scalar phi, Scalar theta, Scalar psi)
Set the components phi, theta, psi based on three Scalars.
Definition: RotationZYX.h:159
RotationZYX Inverse() const
Return inverse of a rotation.
Definition: RotationZYX.h:267
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Definition: RotationZ.h:43
Namespace for new Math classes and functions.
double dist(Rotation3D const &r1, Rotation3D const &r2)
Definition: 3DDistances.cxx:48
void convert(R1 const &, R2 const)
Definition: 3DConversions.h:41
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition: AxisAngle.cxx:91
AxisAngle operator*(RotationX const &r1, AxisAngle const &r2)
Multiplication of an axial rotation by an AxisAngle.
AxisAngle::Scalar Distance(const AxisAngle &r1, const R &r2)
Distance between two rotations.
Definition: AxisAngle.h:320
VSD Structures.
Definition: StringConv.hxx:21
auto * a
Definition: textangle.C:12