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