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_MathX_GenVectorX_RotationZYX
19#define ROOT_MathX_GenVectorX_RotationZYX 1
20
21#include "Math/Math.h"
22
24
26
28
30
32
33#include <algorithm>
34#include <cassert>
35#include <iostream>
36
38
40
41namespace ROOT {
42namespace ROOT_MATH_ARCH {
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) *
56 RotationZ(phi) to the same vector.
57
58
59 @ingroup GenVectorX
60
61 @see GenVectorX
62*/
63
65
66public:
67 typedef double Scalar;
68
69 // ========== Constructors and Assignment =====================
70
71 /**
72 Default constructor
73 */
74 RotationZYX() : fPhi(0.0), fTheta(0.0), fPsi(0.0) {}
75
76 /**
77 Constructor from phi, theta and psi
78 */
79 RotationZYX(Scalar phi, Scalar theta, Scalar psi) : fPhi(phi), fTheta(theta), fPsi(psi)
80 {
81 Rectify();
82 } // 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)
91 {
92 SetComponents(begin, end);
93 }
94
95 // The compiler-generated copy ctor, copy assignment, and dtor are OK.
96
97 /**
98 Re-adjust components place angles in canonical ranges
99 */
100 void Rectify();
101
102 // ======== Construction and Assignment From other Rotation Forms ==================
103
104 /**
105 Construct from another supported rotation type (see gv_detail::convert )
106 */
107 template <class OtherRotation>
108 explicit RotationZYX(const OtherRotation &r)
109 {
110 gv_detail::convert(r, *this);
111 }
112
113 /**
114 Assign from another supported rotation type (see gv_detail::convert )
115 */
116 template <class OtherRotation>
118 {
119 gv_detail::convert(r, *this);
120 return *this;
121 }
122
123 // ======== Components ==============
124
125 /**
126 Set the three Euler angles given a pair of pointers or iterators
127 defining the beginning and end of an array of three Scalars.
128 */
129 template <class IT>
130 void SetComponents(IT begin, IT end)
131 {
132 fPhi = *begin++;
133 fTheta = *begin++;
134 fPsi = *begin++;
135 (void)end;
136 assert(begin == end);
137 Rectify();
138 }
139
140 /**
141 Get the axis and then the angle into data specified by an iterator begin
142 and another to the end of the desired data (4 past start).
143 */
144 template <class IT>
145 void GetComponents(IT begin, IT end) const
146 {
147 *begin++ = fPhi;
148 *begin++ = fTheta;
149 *begin++ = fPsi;
150 (void)end;
151 assert(begin == end);
152 }
153
154 /**
155 Get the axis and then the angle into data specified by an iterator begin
156 */
157 template <class IT>
158 void GetComponents(IT begin) const
159 {
160 *begin++ = fPhi;
161 *begin++ = fTheta;
162 *begin = fPsi;
163 }
164
165 /**
166 Set the components phi, theta, psi based on three Scalars.
167 */
169 {
170 fPhi = phi;
171 fTheta = theta;
172 fPsi = psi;
173 Rectify();
174 }
175
176 /**
177 Get the components phi, theta, psi into three Scalars.
178 */
179 void GetComponents(Scalar &phi, Scalar &theta, Scalar &psi) const
180 {
181 phi = fPhi;
182 theta = fTheta;
183 psi = fPsi;
184 }
185
186 /**
187 Set Phi angle (Z rotation angle)
188 */
189 void SetPhi(Scalar phi)
190 {
191 fPhi = phi;
192 Rectify();
193 }
194
195 /**
196 Return Phi angle (Z rotation angle)
197 */
198 Scalar Phi() const { return fPhi; }
199
200 /**
201 Set Theta angle (Y' rotation angle)
202 */
203 void SetTheta(Scalar theta)
204 {
205 fTheta = theta;
206 Rectify();
207 }
208
209 /**
210 Return Theta angle (Y' rotation angle)
211 */
212 Scalar Theta() const { return fTheta; }
213
214 /**
215 Set Psi angle (X'' rotation angle)
216 */
218 {
219 fPsi = psi;
220 Rectify();
221 }
222
223 /**
224 Return Psi angle (X'' rotation angle)
225 */
226 Scalar Psi() const { return fPsi; }
227
228 // =========== operations ==============
229
230 /**
231 Rotation operation on a displacement vector in any coordinate system and tag
232 */
233 template <class CoordSystem, class U>
238
239 /**
240 Rotation operation on a position vector in any coordinate system
241 */
242 template <class CoordSystem, class U>
249
250 /**
251 Rotation operation on a Lorentz vector in any 4D coordinate system
252 */
253 template <class CoordSystem>
255 {
257 xyz = operator()(xyz);
258 LorentzVector<PxPyPzE4D<double>> xyzt(xyz.X(), xyz.Y(), xyz.Z(), v.E());
260 }
261
262 /**
263 Rotation operation on an arbitrary vector v.
264 Preconditions: v must implement methods x(), y(), and z()
265 and the arbitrary vector type must have a constructor taking (x,y,z)
266 */
267 template <class ForeignVector>
274
275 /**
276 Overload operator * for rotation on a vector
277 */
278 template <class AVector>
279 inline AVector operator*(const AVector &v) const
280 {
281 return operator()(v);
282 }
283
284 /**
285 Invert a rotation in place
286 */
287 void Invert();
288
289 /**
290 Return inverse of a rotation
291 */
293 {
294 RotationZYX r(*this);
295 r.Invert();
296 return r;
297 }
298
299 // ========= Multi-Rotation Operations ===============
300
301 /**
302 Multiply (combine) two rotations
303 */
304 RotationZYX operator*(const RotationZYX &e) const;
305 RotationZYX operator*(const Rotation3D &r) const;
306 RotationZYX operator*(const AxisAngle &a) const;
307 RotationZYX operator*(const Quaternion &q) const;
308 RotationZYX operator*(const EulerAngles &q) const;
309 RotationZYX operator*(const RotationX &rx) const;
310 RotationZYX operator*(const RotationY &ry) const;
311 RotationZYX operator*(const RotationZ &rz) const;
312
313 /**
314 Post-Multiply (on right) by another rotation : T = T*R
315 */
316 template <class R>
318 {
319 return *this = (*this) * r;
320 }
321
322 /**
323 Distance between two rotations
324 */
325 template <class R>
326 Scalar Distance(const R &r) const
327 {
328 return gv_detail::dist(*this, r);
329 }
330
331 /**
332 Equality/inequality operators
333 */
334 bool operator==(const RotationZYX &rhs) const
335 {
336 if (fPhi != rhs.fPhi)
337 return false;
338 if (fTheta != rhs.fTheta)
339 return false;
340 if (fPsi != rhs.fPsi)
341 return false;
342 return true;
343 }
344 bool operator!=(const RotationZYX &rhs) const { return !operator==(rhs); }
345
346private:
347 double fPhi; // Z rotation angle (yaw) defined in (-PI,PI]
348 double fTheta; // Y' rotation angle (pitch) defined in [-PI/2,PI/2]
349 double fPsi; // X'' rotation angle (roll) defined in (-PI,PI]
350
351 static double Pi() { return M_PI; }
352
353}; // RotationZYX
354
355/**
356 Distance between two rotations
357 */
358template <class R>
359inline typename RotationZYX::Scalar Distance(const RotationZYX &r1, const R &r2)
360{
361 return gv_detail::dist(r1, r2);
362}
363
364/**
365 Multiplication of an axial rotation by an AxisAngle
366 */
370
371/**
372 Stream Output and Input
373 */
374// TODO - I/O should be put in the manipulator form
375#if !defined(ROOT_MATH_SYCL) && !defined(ROOT_MATH_CUDA)
376std::ostream &operator<<(std::ostream &os, const RotationZYX &e);
377#endif
378
379} // namespace ROOT_MATH_ARCH
380} // namespace ROOT
381
382#endif // ROOT_MathX_GenVectorX_RotationZYX
#define a(i)
Definition RSha256.hxx:99
#define e(i)
Definition RSha256.hxx:103
#define M_PI
Definition Rotated.cxx:105
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:46
EulerAngles class describing rotation as three angles (Euler Angles).
Definition EulerAngles.h:50
Rotation class with the (3D) rotation represented by a unit quaternion (u, i, j, k).
Definition Quaternion.h:52
Rotation class with the (3D) rotation represented by a 3x3 orthogonal matrix.
Definition Rotation3D.h:71
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:64
RotationZYX & operator*=(const R &r)
Post-Multiply (on right) by another rotation : T = T*R.
Scalar Phi() const
Return Phi angle (Z rotation angle)
void GetComponents(IT begin) const
Get the axis and then the angle into data specified by an iterator begin.
AVector operator*(const AVector &v) const
Overload operator * for rotation on a vector.
PositionVector3D< CoordSystem, U > operator()(const PositionVector3D< CoordSystem, U > &v) const
Rotation operation on a position vector in any coordinate system.
LorentzVector< CoordSystem > operator()(const LorentzVector< CoordSystem > &v) const
Rotation operation on a Lorentz vector in any 4D coordinate system.
DisplacementVector3D< CoordSystem, U > operator()(const DisplacementVector3D< CoordSystem, U > &v) const
Rotation operation on a displacement vector in any coordinate system and tag.
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...
Scalar Distance(const R &r) const
Distance between two rotations.
void GetComponents(Scalar &phi, Scalar &theta, Scalar &psi) const
Get the components phi, theta, psi into three Scalars.
RotationZYX(const OtherRotation &r)
Construct from another supported rotation type (see gv_detail::convert )
bool operator!=(const RotationZYX &rhs) const
RotationZYX()
Default constructor.
Definition RotationZYX.h:74
void SetPhi(Scalar phi)
Set Phi angle (Z rotation angle)
void SetTheta(Scalar theta)
Set Theta angle (Y' 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...
bool operator==(const RotationZYX &rhs) const
Equality/inequality operators.
void Invert()
Invert a rotation in place.
RotationZYX & operator=(OtherRotation const &r)
Assign from another supported rotation type (see gv_detail::convert )
RotationZYX(Scalar phi, Scalar theta, Scalar psi)
Constructor from phi, theta and psi.
Definition RotationZYX.h:79
Scalar Psi() const
Return Psi angle (X'' rotation angle)
RotationZYX Inverse() const
Return inverse of a rotation.
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
void SetPsi(Scalar psi)
Set Psi angle (X'' rotation angle)
Scalar Theta() const
Return Theta angle (Y' rotation angle)
ForeignVector operator()(const ForeignVector &v) const
Rotation operation on an arbitrary vector v.
void Rectify()
Re-adjust components place angles in canonical ranges.
void SetComponents(Scalar phi, Scalar theta, Scalar psi)
Set the components phi, theta, psi based on three Scalars.
Rotation class representing a 3D rotation about the Z axis by the angle of rotation.
Definition RotationZ.h:45
double dist(Rotation3D const &r1, Rotation3D const &r2)
void convert(R1 const &, R2 const)
AxisAngle::Scalar Distance(const AxisAngle &r1, const R &r2)
Distance between two rotations.
Definition AxisAngle.h:346
std::ostream & operator<<(std::ostream &os, const AxisAngle &a)
Stream Output and Input.
Definition AxisAngle.cxx:98
AxisAngle operator*(RotationX const &r1, AxisAngle const &r2)
Multiplication of an axial rotation by an AxisAngle.