Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
14
15#include <cmath>
16#include <iostream>
17
18namespace CLHEP {
19
20//-************************
21// rotate about axis
22//-************************
23
25 double ddelta) {
26 double r1 = axis.mag();
27 if ( r1 == 0 ) {
28 std::cerr << "Hep3Vector::rotate() - "
29 << "Attempt to rotate around a zero vector axis! " << std::endl;
30 return *this;
31 }
32 double scale=1.0/r1;
33 double ux = scale*axis.getX();
34 double uy = scale*axis.getY();
35 double uz = scale*axis.getZ();
36 double cd = std::cos(ddelta);
37 double sd = std::sin(ddelta);
38 double ocd = 1 - cd;
39 double rx;
40 double ry;
41 double rz;
42
43 { double ocdux = ocd * ux;
44 rx = x() * ( cd + ocdux * ux ) +
45 y() * ( ocdux * uy - sd * uz ) +
46 z() * ( ocdux * uz + sd * uy ) ;
47 }
48
49 { double ocduy = ocd * uy;
50 ry = y() * ( cd + ocduy * uy ) +
51 z() * ( ocduy * uz - sd * ux ) +
52 x() * ( ocduy * ux + sd * uz ) ;
53 }
54
55 { double ocduz = ocd * uz;
56 rz = z() * ( cd + ocduz * uz ) +
57 x() * ( ocduz * ux - sd * uy ) +
58 y() * ( ocduz * uy + sd * ux ) ;
59 }
60
61 set(rx, ry, rz);
62 return *this;
63} /* rotate */
64
65
66//-****************************
67// rotate by three euler angles
68//-****************************
69
70
72 double theta1,
73 double psi1) {
74
75 double rx;
76 double ry;
77 double rz;
78
79 double sinPhi = std::sin( phi1 ), cosPhi = std::cos( phi1 );
80 double sinTheta = std::sin( theta1 ), cosTheta1 = std::cos( theta1 );
81 double sinPsi = std::sin( psi1 ), cosPsi = std::cos( psi1 );
82
83 rx = (cosPsi * cosPhi - cosTheta1 * sinPsi * sinPhi) * x() +
84 (cosPsi * sinPhi + cosTheta1 * sinPsi * cosPhi) * y() +
85 (sinPsi * sinTheta) * z() ;
86
87 ry = (- sinPsi * cosPhi - cosTheta1 * cosPsi * sinPhi) * x() +
88 (- sinPsi * sinPhi + cosTheta1 * cosPsi * cosPhi) * y() +
89 (cosPsi * sinTheta) * z() ;
90
91 rz = (sinTheta * sinPhi) * x() +
92 (- sinTheta * cosPhi) * y() +
93 (cosTheta1) * z() ;
94
95 set(rx, ry, rz);
96 return *this;
97
98} /* rotate */
99
100
101//-*******************
102// rotate(HepAxisAngle)
103// rotate(HepEulerAngles)
104//-*******************
105
107 return rotate( ax.getAxis(), ax.delta() );
108}
109
111 return rotate( ex.phi(), ex.theta(), ex.psi() );
112}
113
114
115//-***********************
116// rotationOf(HepAxisAngle)
117// rotationOf(HepEulerAngles)
118// and coordinate axis rotations
119//-***********************
120
121Hep3Vector rotationOf (const Hep3Vector & vec, const HepAxisAngle & ax) {
122 Hep3Vector vv(vec);
123 return vv.rotate (ax);
124}
125
127 const Hep3Vector & axis, double ddelta) {
128 Hep3Vector vv(vec);
129 return vv.rotate(axis, ddelta);
130}
131
133 Hep3Vector vv(vec);
134 return vv.rotate (ex);
135}
136
138 double phi, double theta, double psi) {
139 Hep3Vector vv(vec);
140 return vv.rotate(phi, theta, psi);
141}
142
143Hep3Vector rotationXOf (const Hep3Vector & vec, double ddelta) {
144 Hep3Vector vv(vec);
145 return vv.rotateX (ddelta);
146}
147
148Hep3Vector rotationYOf (const Hep3Vector & vec, double ddelta) {
149 Hep3Vector vv(vec);
150 return vv.rotateY (ddelta);
151}
152
153Hep3Vector rotationZOf (const Hep3Vector & vec, double ddelta) {
154 Hep3Vector vv(vec);
155 return vv.rotateZ (ddelta);
156}
157
158} // namespace CLHEP
Hep3Vector & rotateY(double)
Definition: ThreeVector.cc:97
double z() const
Hep3Vector & rotateX(double)
Definition: ThreeVector.cc:87
double getZ() const
double x() const
Hep3Vector & rotateZ(double)
Definition: ThreeVector.cc:107
double y() const
double mag() const
void set(double x, double y, double z)
double getX() const
Hep3Vector & rotate(double, const Hep3Vector &)
Definition: ThreeVectorR.cc:24
double getY() const
double delta() const
Hep3Vector getAxis() const
double phi() const
double theta() const
double psi() const
Definition: DoubConv.h:17
HepLorentzVector rotationYOf(const HepLorentzVector &vec, double delta)
HepLorentzVector rotationXOf(const HepLorentzVector &vec, double delta)
HepLorentzVector rotationZOf(const HepLorentzVector &vec, double delta)
HepLorentzVector rotationOf(const HepLorentzVector &vec, const Hep3Vector &axis, double delta)