Geant4  10.01.p03
SpaceVectorR.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // ---------------------------------------------------------------------------
3 //
4 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
5 //
6 // This is the implementation of the subset of those methods of the Hep3Vector
7 // class which originated from the ZOOM SpaceVector class *and* which involve
8 // the concepts of rotation.
9 //
10 
11 #ifdef GNUPRAGMA
12 #pragma implementation
13 #endif
14 
15 #include "CLHEP/Vector/ThreeVector.h"
16 #include "CLHEP/Vector/AxisAngle.h"
17 #include "CLHEP/Vector/EulerAngles.h"
18 
19 namespace CLHEP {
20 
21 //-************************
22 // rotate about axis
23 //-************************
24 
25 Hep3Vector & Hep3Vector::rotate (const Hep3Vector & axis,
26  double ddelta) {
27  double r1 = axis.mag();
28  if ( r1 == 0 ) {
29  std::cerr << "Hep3Vector::rotate() - "
30  << "Attempt to rotate around a zero vector axis! " << std::endl;
31  return *this;
32  }
33  double scale=1.0/r1;
34  double ux = scale*axis.getX();
35  double uy = scale*axis.getY();
36  double uz = scale*axis.getZ();
37  double cd = std::cos(ddelta);
38  double sd = std::sin(ddelta);
39  double ocd = 1 - cd;
40  double rx;
41  double ry;
42  double rz;
43 
44  { double ocdux = ocd * ux;
45  rx = dx * ( cd + ocdux * ux ) +
46  dy * ( ocdux * uy - sd * uz ) +
47  dz * ( ocdux * uz + sd * uy ) ;
48  }
49 
50  { double ocduy = ocd * uy;
51  ry = dy * ( cd + ocduy * uy ) +
52  dz * ( ocduy * uz - sd * ux ) +
53  dx * ( ocduy * ux + sd * uz ) ;
54  }
55 
56  { double ocduz = ocd * uz;
57  rz = dz * ( cd + ocduz * uz ) +
58  dx * ( ocduz * ux - sd * uy ) +
59  dy * ( ocduz * uy + sd * ux ) ;
60  }
61 
62  dx = rx;
63  dy = ry;
64  dz = rz;
65 
66  return *this;
67 } /* rotate */
68 
69 //-****************************
70 // rotate by three euler angles
71 //-****************************
72 
73 
74 Hep3Vector & Hep3Vector::rotate (double phi1,
75  double theta1,
76  double psi1) {
77 
78  double rx;
79  double ry;
80  double rz;
81 
82  double sinPhi = std::sin( phi1 ), cosPhi = std::cos( phi1 );
83  double sinTheta = std::sin( theta1 ), cosTheta1 = std::cos( theta1 );
84  double sinPsi = std::sin( psi1 ), cosPsi = std::cos( psi1 );
85 
86  rx = (cosPsi * cosPhi - cosTheta1 * sinPsi * sinPhi) * dx +
87  (cosPsi * sinPhi + cosTheta1 * sinPsi * cosPhi) * dy +
88  (sinPsi * sinTheta) * dz ;
89 
90  ry = (- sinPsi * cosPhi - cosTheta1 * cosPsi * sinPhi) * dx +
91  (- sinPsi * sinPhi + cosTheta1 * cosPsi * cosPhi) * dy +
92  (cosPsi * sinTheta) * dz ;
93 
94  rz = (sinTheta * sinPhi) * dx +
95  (- sinTheta * cosPhi) * dy +
96  (cosTheta1) * dz ;
97 
98  dx = rx;
99  dy = ry;
100  dz = rz;
101 
102  return *this;
103 
104 } /* rotate */
105 
106 
107 //-*******************
108 // rotate(HepAxisAngle)
109 // rotate(HepEulerAngles)
110 //-*******************
111 
112 Hep3Vector & Hep3Vector::rotate (const HepAxisAngle & ax ) {
113  return rotate( ax.getAxis(), ax.delta() );
114 }
115 
116 Hep3Vector & Hep3Vector::rotate (const HepEulerAngles & ex ) {
117  return rotate( ex.phi(), ex.theta(), ex.psi() );
118 }
119 
120 
121 //-***********************
122 // rotationOf(HepAxisAngle)
123 // rotationOf(HepEulerAngles)
124 // and coordinate axis rotations
125 //-***********************
126 
127 Hep3Vector rotationOf (const Hep3Vector & vec, const HepAxisAngle & ax) {
128  Hep3Vector vv(vec);
129  return vv.rotate (ax);
130 }
131 
132 Hep3Vector rotationOf (const Hep3Vector & vec,
133  const Hep3Vector & axis, double ddelta) {
134  Hep3Vector vv(vec);
135  return vv.rotate(axis, ddelta);
136 }
137 
138 Hep3Vector rotationOf (const Hep3Vector & vec, const HepEulerAngles & ex) {
139  Hep3Vector vv(vec);
140  return vv.rotate (ex);
141 }
142 
143 Hep3Vector rotationOf (const Hep3Vector & vec,
144  double phi, double theta, double psi) {
145  Hep3Vector vv(vec);
146  return vv.rotate(phi, theta, psi);
147 }
148 
149 Hep3Vector rotationXOf (const Hep3Vector & vec, double ddelta) {
150  Hep3Vector vv(vec);
151  return vv.rotateX (ddelta);
152 }
153 
154 Hep3Vector rotationYOf (const Hep3Vector & vec, double ddelta) {
155  Hep3Vector vv(vec);
156  return vv.rotateY (ddelta);
157 }
158 
159 Hep3Vector rotationZOf (const Hep3Vector & vec, double ddelta) {
160  Hep3Vector vv(vec);
161  return vv.rotateZ (ddelta);
162 }
163 
164 } // namespace CLHEP
HepLorentzVector rotationOf(const HepLorentzVector &vec, const Hep3Vector &aaxis, double ddelta)
static const G4double cd
HepLorentzVector rotationXOf(const HepLorentzVector &vec, double phi)
HepLorentzVector rotationZOf(const HepLorentzVector &vec, double phi)
HepLorentzVector rotationYOf(const HepLorentzVector &vec, double phi)