CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
Rotation.h
Go to the documentation of this file.
1// -*- C++ -*-
2// CLASSDOC OFF
3// $Id: Rotation.h,v 1.3 2003/10/23 21:29:52 garren Exp $
4// ---------------------------------------------------------------------------
5// CLASSDOC ON
6//
7// This file is a part of the CLHEP - a Class Library for High Energy Physics.
8//
9// This is the definition of the HepRotation class for performing rotations
10// on objects of the Hep3Vector (and HepLorentzVector) class.
11//
12// HepRotation is a concrete implementation of Hep3RotationInterface.
13//
14// .SS See Also
15// RotationInterfaces.h
16// ThreeVector.h, LorentzVector.h, LorentzRotation.h
17//
18// .SS Author
19// Leif Lonnblad, Mark Fischler
20
21#ifndef HEP_ROTATION_H
22#define HEP_ROTATION_H
23
24#include "CLHEP/Vector/defs.h"
25#include "CLHEP/Vector/RotationInterfaces.h"
26#include "CLHEP/Vector/RotationX.h"
27#include "CLHEP/Vector/RotationY.h"
28#include "CLHEP/Vector/RotationZ.h"
29#include "CLHEP/Vector/LorentzVector.h"
30
31namespace CLHEP {
32
33// Declarations of classes and global methods
34class HepRotation;
35inline HepRotation inverseOf ( const HepRotation & r );
36inline HepRotation operator * (const HepRotationX & rx, const HepRotation & r);
37inline HepRotation operator * (const HepRotationY & ry, const HepRotation & r);
38inline HepRotation operator * (const HepRotationZ & rz, const HepRotation & r);
39
40/**
41 * @author
42 * @ingroup vector
43 */
45
46public:
47
48 // ---------- Constructors and Assignment:
49
50 inline HepRotation();
51 // Default constructor. Gives a unit matrix.
52
53 inline HepRotation(const HepRotation & m);
54 inline HepRotation(HepRotation && m) = default;
55 // Copy and move constructors.
56
57 inline HepRotation(const HepRotationX & m);
58 inline HepRotation(const HepRotationY & m);
59 inline HepRotation(const HepRotationZ & m);
60 // Construct from specialized rotation.
61
62 HepRotation & set( const Hep3Vector & axis, double delta );
63 HepRotation ( const Hep3Vector & axis, double delta );
64 // Construct from axis and angle.
65
66 HepRotation & set( const HepAxisAngle & ax );
67 HepRotation ( const HepAxisAngle & ax );
68 // Construct from AxisAngle structure.
69
70 HepRotation & set( double phi, double theta, double psi );
71 HepRotation ( double phi, double theta, double psi );
72 // Construct from three Euler angles (in radians).
73
74 HepRotation & set( const HepEulerAngles & e );
75 HepRotation ( const HepEulerAngles & e );
76 // Construct from EulerAngles structure.
77
78 HepRotation ( const Hep3Vector & colX,
79 const Hep3Vector & colY,
80 const Hep3Vector & colZ );
81 // Construct from three *orthogonal* unit vector columns.
82 // NOTE:
83 // This constructor, and the two set methods below,
84 // will check that the columns (or rows) form an orthonormal
85 // matrix, and will adjust values so that this relation is
86 // as exact as possible.
87
88 HepRotation & set( const Hep3Vector & colX,
89 const Hep3Vector & colY,
90 const Hep3Vector & colZ );
91 // supply three *orthogonal* unit vectors for the columns.
92
94 const Hep3Vector & rowY,
95 const Hep3Vector & rowZ );
96 // supply three *orthogonal* unit vectors for the rows.
97
98 inline HepRotation & set(const HepRotationX & r);
99 inline HepRotation & set(const HepRotationY & r);
100 inline HepRotation & set(const HepRotationZ & r);
101 // set from specialized rotation.
102
104 inline HepRotation & operator = (HepRotation && r) = default;
105 // Copy and move assignment operators.
106
110 // Assignment from specialized rotation.
111
112 inline HepRotation &set( const HepRep3x3 & m );
113 inline HepRotation ( const HepRep3x3 & m );
114 // WARNING - NO CHECKING IS DONE!
115 // Constructon directly from from a 3x3 representation,
116 // which is required to be an orthogonal matrix.
117
118 inline ~HepRotation();
119 // Trivial destructor.
120
121 // ---------- Accessors:
122
123 inline Hep3Vector colX() const;
124 inline Hep3Vector colY() const;
125 inline Hep3Vector colZ() const;
126 // orthogonal unit-length column vectors
127
128 inline Hep3Vector rowX() const;
129 inline Hep3Vector rowY() const;
130 inline Hep3Vector rowZ() const;
131 // orthogonal unit-length row vectors
132
133 inline double xx() const;
134 inline double xy() const;
135 inline double xz() const;
136 inline double yx() const;
137 inline double yy() const;
138 inline double yz() const;
139 inline double zx() const;
140 inline double zy() const;
141 inline double zz() const;
142 // Elements of the rotation matrix (Geant4).
143
144 inline HepRep3x3 rep3x3() const;
145 // 3x3 representation:
146
147 // ------------ Subscripting:
148
150 public:
151 inline HepRotation_row(const HepRotation &, int);
152 inline double operator [] (int) const;
153 private:
154 const HepRotation & rr;
155 int ii;
156 };
157 // Helper class for implemention of C-style subscripting r[i][j]
158
159 inline const HepRotation_row operator [] (int) const;
160 // Returns object of the helper class for C-style subscripting r[i][j]
161 // i and j range from 0 to 2.
162
163 double operator () (int, int) const;
164 // Fortran-style subscripting: returns (i,j) element of the rotation matrix.
165 // Note: i and j still range from 0 to 2. [Rotation.cc]
166
167 // ------------ Euler angles:
168 inline double getPhi () const;
169 inline double getTheta() const;
170 inline double getPsi () const;
171 double phi () const;
172 double theta() const;
173 double psi () const;
175
176 // ------------ axis & angle of rotation:
177 inline double getDelta() const;
178 inline Hep3Vector getAxis () const;
179 double delta() const;
180 Hep3Vector axis () const;
181 HepAxisAngle axisAngle() const;
182 void getAngleAxis(double & delta, Hep3Vector & axis) const;
183 // Returns the rotation angle and rotation axis (Geant4). [Rotation.cc]
184
185 // ------------- Angles of rotated axes
186 double phiX() const;
187 double phiY() const;
188 double phiZ() const;
189 double thetaX() const;
190 double thetaY() const;
191 double thetaZ() const;
192 // Return angles (RADS) made by rotated axes against original axes (Geant4).
193 // [Rotation.cc]
194
195 // ---------- Other accessors treating pure rotation as a 4-rotation
196
197 inline HepLorentzVector col1() const;
198 inline HepLorentzVector col2() const;
199 inline HepLorentzVector col3() const;
200 // orthosymplectic 4-vector columns - T component will be zero
201
202 inline HepLorentzVector col4() const;
203 // Will be (0,0,0,1) for this pure Rotation.
204
205 inline HepLorentzVector row1() const;
206 inline HepLorentzVector row2() const;
207 inline HepLorentzVector row3() const;
208 // orthosymplectic 4-vector rows - T component will be zero
209
210 inline HepLorentzVector row4() const;
211 // Will be (0,0,0,1) for this pure Rotation.
212
213 inline double xt() const;
214 inline double yt() const;
215 inline double zt() const;
216 inline double tx() const;
217 inline double ty() const;
218 inline double tz() const;
219 // Will be zero for this pure Rotation
220
221 inline double tt() const;
222 // Will be one for this pure Rotation
223
224 inline HepRep4x4 rep4x4() const;
225 // 4x4 representation.
226
227 // --------- Mutators
228
229 void setPhi (double phi);
230 // change Euler angle phi, leaving theta and psi unchanged.
231
232 void setTheta (double theta);
233 // change Euler angle theta, leaving phi and psi unchanged.
234
235 void setPsi (double psi);
236 // change Euler angle psi, leaving theta and phi unchanged.
237
238 void setAxis (const Hep3Vector & axis);
239 // change rotation axis, leaving delta unchanged.
240
241 void setDelta (double delta);
242 // change angle of rotation, leaving rotation axis unchanged.
243
244 // ---------- Decomposition:
245
246 void decompose (HepAxisAngle & rotation, Hep3Vector & boost) const;
247 void decompose (Hep3Vector & boost, HepAxisAngle & rotation) const;
248 // These are trivial, as the boost vector is 0. [RotationP.cc]
249
250 // ---------- Comparisons:
251
252 bool isIdentity() const;
253 // Returns true if the identity matrix (Geant4). [Rotation.cc]
254
255 int compare( const HepRotation & r ) const;
256 // Dictionary-order comparison, in order zz, zy, zx, yz, ... xx
257 // Used in operator<, >, <=, >=
258
259 inline bool operator== ( const HepRotation & r ) const;
260 inline bool operator!= ( const HepRotation & r ) const;
261 inline bool operator< ( const HepRotation & r ) const;
262 inline bool operator> ( const HepRotation & r ) const;
263 inline bool operator<= ( const HepRotation & r ) const;
264 inline bool operator>= ( const HepRotation & r ) const;
265
266 double distance2( const HepRotation & r ) const;
267 // 3 - Tr ( this/r ) -- This works with RotationX, Y or Z also
268
269 double howNear( const HepRotation & r ) const;
270 bool isNear( const HepRotation & r,
271 double epsilon=Hep4RotationInterface::tolerance) const;
272
273 double distance2( const HepBoost & lt ) const;
274 // 3 - Tr ( this ) + |b|^2 / (1-|b|^2)
275 double distance2( const HepLorentzRotation & lt ) const;
276 // 3 - Tr ( this/r ) + |b|^2 / (1-|b|^2) where b is the boost vector of lt
277
278 double howNear( const HepBoost & lt ) const;
279 double howNear( const HepLorentzRotation & lt ) const;
280 bool isNear( const HepBoost & lt,
281 double epsilon=Hep4RotationInterface::tolerance) const;
282 bool isNear( const HepLorentzRotation & lt,
283 double epsilon=Hep4RotationInterface::tolerance) const;
284
285 // ---------- Properties:
286
287 double norm2() const;
288 // distance2 (IDENTITY), which is 3 - Tr ( *this )
289
290 void rectify();
291 // non-const but logically moot correction for accumulated roundoff errors
292 // rectify averages the matrix with the transpose of its actual
293 // inverse (absent accumulated roundoff errors, the transpose IS
294 // the inverse)); this removes to first order those errors.
295 // Then it formally extracts axis and delta, and forms a true
296 // HepRotation with those values of axis and delta.
297
298 // ---------- Application:
299
300 inline Hep3Vector operator() (const Hep3Vector & p) const;
301 // Rotate a Hep3Vector.
302
303 inline Hep3Vector operator * (const Hep3Vector & p) const;
304 // Multiplication with a Hep3Vector.
305
307 // Rotate (the space part of) a HepLorentzVector.
308
310 // Multiplication with a HepLorentzVector.
311
312 // ---------- Operations in the group of Rotations
313
314 inline HepRotation operator * (const HepRotation & r) const;
315 // Product of two rotations (this) * r - matrix multiplication
316
317 inline HepRotation operator * (const HepRotationX & rx) const;
318 inline HepRotation operator * (const HepRotationY & ry) const;
319 inline HepRotation operator * (const HepRotationZ & rz) const;
320 // Product of two rotations (this) * r - faster when specialized type
321
323 inline HepRotation & transform (const HepRotation & r);
324 // Matrix multiplication.
325 // Note a *= b; <=> a = a * b; while a.transform(b); <=> a = b * a;
326
330 inline HepRotation & transform (const HepRotationX & r);
331 inline HepRotation & transform (const HepRotationY & r);
332 inline HepRotation & transform (const HepRotationZ & r);
333 // Matrix multiplication by specialized matrices
334
335 HepRotation & rotateX(double delta);
336 // Rotation around the x-axis; equivalent to R = RotationX(delta) * R
337
338 HepRotation & rotateY(double delta);
339 // Rotation around the y-axis; equivalent to R = RotationY(delta) * R
340
341 HepRotation & rotateZ(double delta);
342 // Rotation around the z-axis; equivalent to R = RotationZ(delta) * R
343
344 HepRotation & rotate(double delta, const Hep3Vector & axis);
345 inline HepRotation & rotate(double delta, const Hep3Vector * axis);
346 // Rotation around a specified vector.
347 // r.rotate(d,a) is equivalent to r = Rotation(d,a) * r
348
349 HepRotation & rotateAxes(const Hep3Vector & newX,
350 const Hep3Vector & newY,
351 const Hep3Vector & newZ);
352 // Rotation of local axes defined by 3 orthonormal vectors (Geant4).
353 // Equivalent to r = Rotation (newX, newY, newZ) * r
354
355 inline HepRotation inverse() const;
356 // Returns the inverse.
357
358 inline HepRotation & invert();
359 // Inverts the Rotation matrix.
360
361 // ---------- I/O:
362
363 std::ostream & print( std::ostream & os ) const;
364 // Aligned six-digit-accurate output of the rotation matrix. [RotationIO.cc]
365
366 // ---------- Identity Rotation:
367
368 static const HepRotation IDENTITY;
369
370 // ---------- Tolerance
371
372 static inline double getTolerance();
373 static inline double setTolerance(double tol);
374
375protected:
376
377 inline HepRotation(double mxx, double mxy, double mxz,
378 double myx, double myy, double myz,
379 double mzx, double mzy, double mzz);
380 // Protected constructor.
381 // DOES NOT CHECK FOR VALIDITY AS A ROTATION.
382
383 friend HepRotation operator* (const HepRotationX & rx, const HepRotation & r);
384 friend HepRotation operator* (const HepRotationY & ry, const HepRotation & r);
385 friend HepRotation operator* (const HepRotationZ & rz, const HepRotation & r);
386
387 double rxx, rxy, rxz,
390 // The matrix elements.
391
392private:
393 bool
394 setCols ( const Hep3Vector & u1, // Vectors assume to be of unit length
395 const Hep3Vector & u2,
396 const Hep3Vector & u3,
397 double u1u2,
398 Hep3Vector & v1, // Returned vectors
399 Hep3Vector & v2,
400 Hep3Vector & v3 ) const;
401 void setArbitrarily (const Hep3Vector & colX, // assumed to be of unit length
402 Hep3Vector & v1,
403 Hep3Vector & v2,
404 Hep3Vector & v3) const;
405}; // HepRotation
406
407inline
408std::ostream & operator <<
409 ( std::ostream & os, const HepRotation & r ) {return r.print(os);}
410
411} // namespace CLHEP
412
413#include "CLHEP/Vector/Rotation.icc"
414
415#ifdef ENABLE_BACKWARDS_COMPATIBILITY
416// backwards compatibility will be enabled ONLY in CLHEP 1.9
417using namespace CLHEP;
418#endif
419
420#endif /* HEP_ROTATION_H */
421
HepRotation_row(const HepRotation &, int)
HepAxisAngle axisAngle() const
Definition: RotationA.cc:121
double operator()(int, int) const
Definition: Rotation.cc:25
double getPsi() const
double getPhi() const
static double getTolerance()
double zz() const
HepEulerAngles eulerAngles() const
Definition: RotationE.cc:203
double yz() const
Hep3Vector colX() const
HepRotation & rotate(double delta, const Hep3Vector *axis)
HepRotation(HepRotation &&m)=default
bool operator==(const HepRotation &r) const
bool operator!=(const HepRotation &r) const
HepLorentzVector col3() const
HepRotation & rotateAxes(const Hep3Vector &newX, const Hep3Vector &newY, const Hep3Vector &newZ)
Definition: Rotation.cc:101
double zx() const
void setPsi(double psi)
Definition: RotationE.cc:273
std::ostream & print(std::ostream &os) const
Definition: RotationIO.cc:18
HepRotation(double mxx, double mxy, double mxz, double myx, double myy, double myz, double mzx, double mzy, double mzz)
Hep3Vector axis() const
Definition: RotationA.cc:76
HepRotation & setRows(const Hep3Vector &rowX, const Hep3Vector &rowY, const Hep3Vector &rowZ)
Definition: RotationC.cc:138
double phi() const
Definition: RotationE.cc:70
HepRotation & set(const HepRotationY &r)
double thetaY() const
Definition: Rotation.cc:141
HepRotation inverse() const
double tz() const
HepRotation(const HepRotationY &m)
HepRotation & rotate(double delta, const Hep3Vector &axis)
Definition: Rotation.cc:44
Hep3Vector rowY() const
Hep3Vector colY() const
Hep3Vector getAxis() const
const HepRotation_row operator[](int) const
bool isIdentity() const
Definition: Rotation.cc:168
HepRotation & operator*=(const HepRotation &r)
double ty() const
double distance2(const HepRotation &r) const
Definition: RotationP.cc:31
HepRotation & transform(const HepRotationZ &r)
HepLorentzVector col1() const
double delta() const
Definition: RotationA.cc:63
HepLorentzVector col2() const
HepLorentzVector col4() const
double norm2() const
Definition: RotationP.cc:48
static double setTolerance(double tol)
HepRotation(const HepRotationZ &m)
double tx() const
HepRotation & transform(const HepRotation &r)
double phiY() const
Definition: Rotation.cc:129
double yx() const
HepRep3x3 rep3x3() const
static const HepRotation IDENTITY
Definition: Rotation.h:368
HepRotation(const HepRotationX &m)
HepRotation & set(const HepRotationX &r)
double zy() const
HepRep4x4 rep4x4() const
HepLorentzVector row1() const
HepRotation(const HepRep3x3 &m)
bool operator>(const HepRotation &r) const
void decompose(HepAxisAngle &rotation, Hep3Vector &boost) const
Definition: RotationP.cc:21
double thetaX() const
Definition: Rotation.cc:137
double zt() const
HepRotation & set(const Hep3Vector &axis, double delta)
Definition: RotationA.cc:24
void getAngleAxis(double &delta, Hep3Vector &axis) const
Definition: Rotation.cc:149
HepRotation & operator=(const HepRotation &r)
bool isNear(const HepRotation &r, double epsilon=Hep4RotationInterface::tolerance) const
Definition: RotationP.cc:43
void setDelta(double delta)
Definition: RotationA.cc:132
Hep3Vector colZ() const
double xx() const
HepLorentzVector row2() const
double howNear(const HepRotation &r) const
Definition: RotationP.cc:39
HepRotation & rotateX(double delta)
Definition: Rotation.cc:62
double psi() const
Definition: RotationE.cc:110
HepRotation & set(const HepRep3x3 &m)
HepRotation & transform(const HepRotationX &r)
Hep3Vector rowX() const
double theta() const
Definition: RotationE.cc:104
double phiX() const
Definition: Rotation.cc:125
double tt() const
HepRotation & rotateZ(double delta)
Definition: Rotation.cc:88
double yy() const
void setAxis(const Hep3Vector &axis)
Definition: RotationA.cc:128
double xz() const
void setPhi(double phi)
Definition: RotationE.cc:265
HepLorentzVector row3() const
double yt() const
HepRotation & rotateY(double delta)
Definition: Rotation.cc:75
Hep3Vector rowZ() const
double getTheta() const
bool operator<(const HepRotation &r) const
HepLorentzVector row4() const
HepLorentzVector operator()(const HepLorentzVector &w) const
double thetaZ() const
Definition: Rotation.cc:145
HepRotation & set(const HepRotationZ &r)
HepRotation & transform(const HepRotationY &r)
int compare(const HepRotation &r) const
Definition: Rotation.cc:174
HepRotation & invert()
HepRotation(const HepRotation &m)
double xy() const
friend HepRotation operator*(const HepRotationX &rx, const HepRotation &r)
bool operator>=(const HepRotation &r) const
bool operator<=(const HepRotation &r) const
double getDelta() const
void setTheta(double theta)
Definition: RotationE.cc:269
double phiZ() const
Definition: Rotation.cc:133
double xt() const
HepBoost inverseOf(const HepBoost &lt)
HepMatrix operator*(const HepMatrix &hm1, const HepDiagMatrix &hm2)
Definition: DiagMatrix.cc:372