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#include "TMath.h"
35
36#include <algorithm>
37#include <cassert>
38#include <iostream>
39
40
41namespace ROOT {
42namespace Math {
43
44
45//__________________________________________________________________________________________
46 /**
47 Rotation class with the (3D) rotation represented by
48 angles describing first a rotation of
49 an angle phi (yaw) about the Z axis,
50 followed by a rotation of an angle theta (pitch) about the Y axis,
51 followed by a third rotation of an angle psi (roll) about the X axis.
52 Note that the rotations are extrinsic rotations happening around a fixed coordinate system.
53 This is different than the convention of the ROOT::Math::EulerAngles class, where the rotation are intrinsic.
54 Also it has not to be confused with the typical Goldstein definition of the Euler Angles
55 (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.
56 Applying a RotationZYX(phi, theta, psi) to a vector is then equal to applying RotationX(psi) * RotationY(theta) * RotationZ(phi) to the same vector.
57
58
59 @ingroup GenVector
60
61 @see GenVector
62 */
63
65
66public:
67
68 typedef double Scalar;
69
70
71 // ========== Constructors and Assignment =====================
72
73 /**
74 Default constructor
75 */
76 RotationZYX() : fPhi(0.0), fTheta(0.0), fPsi(0.0) { }
77
78 /**
79 Constructor from phi, theta and psi
80 */
81 RotationZYX( Scalar phi, Scalar theta, Scalar psi ) :
82 fPhi(phi), fTheta(theta), fPsi(psi)
83 {Rectify();} // Added 27 Jan. 06 JMM
84
85 /**
86 Construct given a pair of pointers or iterators defining the
87 beginning and end of an array of three Scalars, to be treated as
88 the angles phi, theta and psi.
89 */
90 template<class IT>
91 RotationZYX(IT begin, IT end) { SetComponents(begin,end); }
92
93 // The compiler-generated copy ctor, copy assignment, and dtor are OK.
94
95 /**
96 Re-adjust components place angles in canonical ranges
97 */
98 void Rectify();
99
100
101 // ======== Construction and Assignment From other Rotation Forms ==================
102
103 /**
104 Construct from another supported rotation type (see gv_detail::convert )
105 */
106 template <class OtherRotation>
107 explicit constexpr RotationZYX(const OtherRotation & r) {gv_detail::convert(r,*this);}
108
109
110 /**
111 Assign from another supported rotation type (see gv_detail::convert )
112 */
113 template <class OtherRotation>
114 RotationZYX & operator=( OtherRotation const & r ) {
115 gv_detail::convert(r,*this);
116 return *this;
117 }
118
119
120 // ======== Components ==============
121
122 /**
123 Set the three Euler angles given a pair of pointers or iterators
124 defining the beginning and end of an array of three Scalars.
125 */
126 template<class IT>
127 void SetComponents(IT begin, IT end) {
128 fPhi = *begin++;
129 fTheta = *begin++;
130 fPsi = *begin++;
131 (void)end;
132 assert(begin == end);
133 Rectify();
134 }
135
136 /**
137 Get the axis and then the angle into data specified by an iterator begin
138 and another to the end of the desired data (4 past start).
139 */
140 template<class IT>
141 void GetComponents(IT begin, IT end) const {
142 *begin++ = fPhi;
143 *begin++ = fTheta;
144 *begin++ = fPsi;
145 (void)end;
146 assert(begin == end);
147 }
148
149 /**
150 Get the axis and then the angle into data specified by an iterator begin
151 */
152 template<class IT>
153 void GetComponents(IT begin) const {
154 *begin++ = fPhi;
155 *begin++ = fTheta;
156 *begin = fPsi;
157 }
158
159 /**
160 Set the components phi, theta, psi based on three Scalars.
161 */
162 void SetComponents(Scalar phi, Scalar theta, Scalar psi) {
163 fPhi=phi; fTheta=theta; fPsi=psi;
164 Rectify();
165 }
166
167 /**
168 Get the components phi, theta, psi into three Scalars.
169 */
170 void GetComponents(Scalar & phi, Scalar & theta, Scalar & psi) const {
171 phi=fPhi; theta=fTheta; psi=fPsi;
172 }
173
174 /**
175 Set Phi angle (Z rotation angle)
176 */
177 void SetPhi(Scalar phi) { fPhi=phi; Rectify(); }
178
179 /**
180 Return Phi angle (Z rotation angle)
181 */
182 Scalar Phi() const { return fPhi; }
183
184 /**
185 Set Theta angle (Y' rotation angle)
186 */
187 void SetTheta(Scalar theta) { fTheta=theta; Rectify(); }
188
189 /**
190 Return Theta angle (Y' rotation angle)
191 */
192 Scalar Theta() const { return fTheta; }
193
194 /**
195 Set Psi angle (X'' rotation angle)
196 */
197 void SetPsi(Scalar psi) { fPsi=psi; Rectify(); }
198
199 /**
200 Return Psi angle (X'' rotation angle)
201 */
202 Scalar Psi() const { return fPsi; }
203
204 // =========== operations ==============
205
206
207 /**
208 Rotation operation on a displacement vector in any coordinate system and tag
209 */
210 template <class CoordSystem, class U>
213 return Rotation3D(*this) ( v );
214 }
215
216 /**
217 Rotation operation on a position vector in any coordinate system
218 */
219 template <class CoordSystem, class U>
226
227 /**
228 Rotation operation on a Lorentz vector in any 4D coordinate system
229 */
230 template <class CoordSystem>
234 xyz = operator()(xyz);
235 LorentzVector< PxPyPzE4D<double> > xyzt (xyz.X(), xyz.Y(), xyz.Z(), v.E());
236 return LorentzVector<CoordSystem> ( xyzt );
237 }
238
239 /**
240 Rotation operation on an arbitrary vector v.
241 Preconditions: v must implement methods x(), y(), and z()
242 and the arbitrary vector type must have a constructor taking (x,y,z). GenVector coordinate systems whose
243 constructors take other coordinates use SetXYZ() instead.
244 */
245 template <class ForeignVector>
246 ForeignVector
247 operator() (const ForeignVector & v) const {
250 return Impl::MakeFromXYZ<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
317private:
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 TMath::Pi(); }
324
325}; // RotationZYX
326
327/**
328 Distance between two rotations
329 */
330template <class R>
331inline
332typename RotationZYX::Scalar
333Distance ( const RotationZYX& r1, const R & r2) {return gv_detail::dist(r1,r2);}
334
335/**
336 Multiplication of an axial rotation by an AxisAngle
337 */
338RotationZYX operator* (RotationX const & r1, RotationZYX const & r2);
339RotationZYX operator* (RotationY const & r1, RotationZYX const & r2);
340RotationZYX 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
347std::ostream & operator<< (std::ostream & os, const RotationZYX & e);
348
349
350} // namespace Math
351} // namespace ROOT
352
353#endif // ROOT_Math_GenVector_RotationZYX
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
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:46
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:68
Rotation class representing a 3D rotation about the X axis by the angle of rotation.
Definition RotationX.h:46
Rotation class representing a 3D rotation about the Y axis by the angle of rotation.
Definition RotationY.h:46
Rotation class with the (3D) rotation represented by angles describing first a rotation of an angle p...
Definition RotationZYX.h:64
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:91
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:76
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:81
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:46
Namespace for new Math classes and functions.
double dist(Rotation3D const &r1, Rotation3D const &r2)
void convert(R1 const &, R2 const)
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition AxisAngle.cxx:81
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
constexpr Double_t Pi()
Definition TMath.h:40