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