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