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 */
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>
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 */
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 */
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());
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)
243 */
244 template <class ForeignVector>
251
252 /**
253 Overload operator * for rotation on a vector
254 */
255 template <class AVector>
256 inline
258 {
259 return operator()(v);
260 }
261
262 /**
263 Invert a rotation in place
264 */
265 void Invert();
266
267 /**
268 Return inverse of a rotation
269 */
271 RotationZYX r(*this);
272 r.Invert();
273 return r;
274 }
275
276
277 // ========= Multi-Rotation Operations ===============
278
279 /**
280 Multiply (combine) two rotations
281 */
282 RotationZYX operator * (const RotationZYX & e) const;
283 RotationZYX operator * (const Rotation3D & r) const;
284 RotationZYX operator * (const AxisAngle & a) const;
285 RotationZYX operator * (const Quaternion & q) const;
286 RotationZYX operator * (const EulerAngles & q) const;
287 RotationZYX operator * (const RotationX & rx) const;
288 RotationZYX operator * (const RotationY & ry) const;
289 RotationZYX operator * (const RotationZ & rz) const;
290
291 /**
292 Post-Multiply (on right) by another rotation : T = T*R
293 */
294 template <class R>
295 RotationZYX & operator *= (const R & r) { return *this = (*this)*r; }
296
297 /**
298 Distance between two rotations
299 */
300 template <class R>
301 Scalar Distance ( const R & r ) const {return gv_detail::dist(*this,r);}
302
303 /**
304 Equality/inequality operators
305 */
306 bool operator == (const RotationZYX & rhs) const {
307 if( fPhi != rhs.fPhi ) return false;
308 if( fTheta != rhs.fTheta ) return false;
309 if( fPsi != rhs.fPsi ) return false;
310 return true;
311 }
312 bool operator != (const RotationZYX & rhs) const {
313 return ! operator==(rhs);
314 }
315
316private:
317
318 double fPhi; // Z rotation angle (yaw) defined in (-PI,PI]
319 double fTheta; // Y' rotation angle (pitch) defined in [-PI/2,PI/2]
320 double fPsi; // X'' rotation angle (roll) defined in (-PI,PI]
321
322 static double Pi() { return TMath::Pi(); }
323
324}; // RotationZYX
325
326/**
327 Distance between two rotations
328 */
329template <class R>
330inline
331typename RotationZYX::Scalar
332Distance ( const RotationZYX& r1, const R & r2) {return gv_detail::dist(r1,r2);}
333
334/**
335 Multiplication of an axial rotation by an AxisAngle
336 */
337RotationZYX operator* (RotationX const & r1, RotationZYX const & r2);
338RotationZYX operator* (RotationY const & r1, RotationZYX const & r2);
339RotationZYX operator* (RotationZ const & r1, RotationZYX const & r2);
340
341/**
342 Stream Output and Input
343 */
344 // TODO - I/O should be put in the manipulator form
345
346std::ostream & operator<< (std::ostream & os, const RotationZYX & e);
347
348
349} // namespace Math
350} // namespace ROOT
351
352#endif // ROOT_Math_GenVector_RotationZYX
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
EulerAngles class describing rotation as three angles (Euler Angles).
Definition EulerAngles.h:46
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: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:321
Namespace for new ROOT classes and functions.
constexpr Double_t Pi()
Definition TMath.h:38