Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
Rotation.h
이 파일의 문서화 페이지로 가기
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 
29 #include "CLHEP/Vector/RotationX.h"
30 #include "CLHEP/Vector/RotationY.h"
31 #include "CLHEP/Vector/RotationZ.h"
33 
34 namespace CLHEP {
35 
36 // Declarations of classes and global methods
37 class HepRotation;
38 inline HepRotation inverseOf ( const HepRotation & r );
39 inline HepRotation operator * (const HepRotationX & rx, const HepRotation & r);
40 inline HepRotation operator * (const HepRotationY & ry, const HepRotation & r);
41 inline HepRotation operator * (const HepRotationZ & rz, const HepRotation & r);
42 
47 class HepRotation {
48 
49 public:
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 
105  inline HepRotation & operator = (const HepRotation & r);
106  // Assignment.
107 
108  inline HepRotation & operator = (const HepRotationX & r);
109  inline HepRotation & operator = (const HepRotationY & r);
110  inline HepRotation & operator = (const HepRotationZ & r);
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;
175  HepEulerAngles eulerAngles() 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,
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,
283  bool isNear( const HepLorentzRotation & lt,
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 
307  inline HepLorentzVector operator()( const HepLorentzVector & w ) const;
308  // Rotate (the space part of) a HepLorentzVector.
309 
310  inline HepLorentzVector operator* ( const HepLorentzVector & w ) const;
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 
323  inline HepRotation & operator *= (const HepRotation & r);
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 
328  inline HepRotation & operator *= (const HepRotationX & r);
329  inline HepRotation & operator *= (const HepRotationY & r);
330  inline HepRotation & operator *= (const HepRotationZ & r);
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 
376 protected:
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,
389  ryx, ryy, ryz,
390  rzx, rzy, rzz;
391  // The matrix elements.
392 
393 private:
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 
408 inline
409 std::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 
HepLorentzVector row3() const
HepAxisAngle axisAngle() const
Definition: RotationA.cc:124
double tz() const
Hep3Vector axis() const
Definition: RotationA.cc:79
HepRotation & operator=(const HepRotation &r)
Hep3Vector colY() const
bool isIdentity() const
Definition: Rotation.cc:172
void setDelta(double delta)
Definition: RotationA.cc:135
HepLorentzVector row4() const
void setArbitrarily(const Hep3Vector &colX, Hep3Vector &v1, Hep3Vector &v2, Hep3Vector &v3) const
Definition: RotationC.cc:48
HepEulerAngles eulerAngles() const
Definition: RotationE.cc:201
double yx() const
HepLorentzVector col1() const
bool operator<(const HepRotation &r) const
std::ostream & print(std::ostream &os) const
Definition: RotationIO.cc:21
static DLL_API const HepRotation IDENTITY
Definition: Rotation.h:369
double zz() const
void decompose(HepAxisAngle &rotation, Hep3Vector &boost) const
Definition: RotationP.cc:23
bool operator==(const HepRotation &r) const
const char * p
Definition: xmltok.h:285
bool operator>(const HepRotation &r) const
const HepRotation_row operator[](int) const
HepLorentzVector col3() const
double thetaZ() const
Definition: Rotation.cc:149
static double setTolerance(double tol)
double xt() const
double yz() const
bool operator>=(const HepRotation &r) const
Hep3Vector colZ() const
HepRotation & set(const Hep3Vector &axis, double delta)
Definition: RotationA.cc:27
int compare(const HepRotation &r) const
Definition: Rotation.cc:178
double thetaY() const
Definition: Rotation.cc:145
double theta() const
Definition: RotationE.cc:104
static double getTolerance()
double xz() const
double yt() const
HepLorentzVector row1() const
double phiY() const
Definition: Rotation.cc:133
Hep3Vector colX() const
HepLorentzRotation operator*(const HepRotation &r, const HepLorentzRotation &lt)
Hep3Vector rowX() const
double psi() const
Definition: RotationE.cc:110
bool setCols(const Hep3Vector &u1, const Hep3Vector &u2, const Hep3Vector &u3, double u1u2, Hep3Vector &v1, Hep3Vector &v2, Hep3Vector &v3) const
Definition: RotationC.cc:25
double zx() const
void getAngleAxis(double &delta, Hep3Vector &axis) const
Definition: Rotation.cc:153
double phiX() const
Definition: Rotation.cc:129
double xx() const
double tx() const
bool operator<=(const HepRotation &r) const
bool operator!=(const HepRotation &r) const
HepRep4x4 rep4x4() const
HepLorentzVector col2() const
HepLorentzVector row2() const
double zt() const
double phi() const
Definition: RotationE.cc:70
double getPhi() const
HepBoost inverseOf(const HepBoost &lt)
double delta() const
Definition: RotationA.cc:66
#define DLL_API
Definition: defs.h:19
HepRotation & operator*=(const HepRotation &r)
double ty() const
double operator()(int, int) const
Definition: Rotation.cc:28
double getTheta() const
double getDelta() const
static constexpr double m
void setAxis(const Hep3Vector &axis)
Definition: RotationA.cc:131
double distance2(const HepRotation &r) const
Definition: RotationP.cc:33
double epsilon(double density, double temperature)
void setPhi(double phi)
Definition: RotationE.cc:262
HepRotation & rotateY(double delta)
Definition: Rotation.cc:79
double zy() const
Hep3Vector operator*(const Hep3Vector &p) const
double norm2() const
Definition: RotationP.cc:50
Hep3Vector rowZ() const
HepLorentzVector col4() const
double yy() const
void setTheta(double theta)
Definition: RotationE.cc:266
HepRotation & rotateZ(double delta)
Definition: Rotation.cc:92
Hep3Vector getAxis() const
HepRotation & rotate(double delta, const Hep3Vector &axis)
Definition: Rotation.cc:47
double xy() const
HepRotation & transform(const HepRotation &r)
Hep3Vector rowY() const
bool isNear(const HepRotation &r, double epsilon=Hep4RotationInterface::tolerance) const
Definition: RotationP.cc:45
HepRotation & setRows(const Hep3Vector &rowX, const Hep3Vector &rowY, const Hep3Vector &rowZ)
Definition: RotationC.cc:142
HepRotation_row(const HepRotation &, int)
HepRotation & rotateAxes(const Hep3Vector &newX, const Hep3Vector &newY, const Hep3Vector &newZ)
Definition: Rotation.cc:105
double phiZ() const
Definition: Rotation.cc:137
HepRep3x3 rep3x3() const
double thetaX() const
Definition: Rotation.cc:141
double howNear(const HepRotation &r) const
Definition: RotationP.cc:41
double tt() const
HepRotation & rotateX(double delta)
Definition: Rotation.cc:66
HepRotation & invert()
HepRotation inverse() const
void setPsi(double psi)
Definition: RotationE.cc:270
double getPsi() const
static DLL_API double tolerance