Geant4  v4-10.4-release
SpaceVectorR.cc
이 파일의 문서화 페이지로 가기
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
16 #include "CLHEP/Vector/AxisAngle.h"
18
19 namespace CLHEP {
20
21 //-************************
23 //-************************
24
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
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
113  return rotate( ax.getAxis(), ax.delta() );
114 }
115
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
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
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
double psi() const
double delta() const
double getZ() const
Hep3Vector & rotateX(double)
Definition: ThreeVector.cc:90
HepLorentzVector rotationXOf(const HepLorentzVector &vec, double delta)
Double_t scale
HepLorentzVector rotationYOf(const HepLorentzVector &vec, double delta)
double phi() const
double getX() const
static const G4double cd
HepLorentzVector rotationZOf(const HepLorentzVector &vec, double delta)
double getY() const
Hep3Vector & rotate(double, const Hep3Vector &)
Definition: ThreeVectorR.cc:28
double theta() const
HepLorentzVector rotationOf(const HepLorentzVector &vec, const Hep3Vector &axis, double delta)
Hep3Vector & rotateZ(double)
Definition: ThreeVector.cc:110
double mag() const
Hep3Vector getAxis() const
Hep3Vector & rotateY(double)
Definition: ThreeVector.cc:100