CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

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/defs.h"
16#include "CLHEP/Vector/ThreeVector.h"
17#include "CLHEP/Vector/AxisAngle.h"
18#include "CLHEP/Vector/EulerAngles.h"
19#include "CLHEP/Vector/ZMxpv.h"
20
21namespace CLHEP {
22
23//-************************
24// rotate about axis
25//-************************
26
28 double ddelta) {
29 double r1 = axis.mag();
30 if ( r1 == 0 ) {
31 ZMthrowA (ZMxpvZeroVector(
32 "Attempt to rotate around a zero vector axis! "));
33 return *this;
34 }
35 register double scale=1.0/r1;
36 register double ux = scale*axis.getX();
37 register double uy = scale*axis.getY();
38 register double uz = scale*axis.getZ();
39 double cd = std::cos(ddelta);
40 double sd = std::sin(ddelta);
41 register double ocd = 1 - cd;
42 double rx;
43 double ry;
44 double rz;
45
46 { register double ocdux = ocd * ux;
47 rx = dx * ( cd + ocdux * ux ) +
48 dy * ( ocdux * uy - sd * uz ) +
49 dz * ( ocdux * uz + sd * uy ) ;
50 }
51
52 { register double ocduy = ocd * uy;
53 ry = dy * ( cd + ocduy * uy ) +
54 dz * ( ocduy * uz - sd * ux ) +
55 dx * ( ocduy * ux + sd * uz ) ;
56 }
57
58 { register double ocduz = ocd * uz;
59 rz = dz * ( cd + ocduz * uz ) +
60 dx * ( ocduz * ux - sd * uy ) +
61 dy * ( ocduz * uy + sd * ux ) ;
62 }
63
64 dx = rx;
65 dy = ry;
66 dz = rz;
67
68 return *this;
69} /* rotate */
70
71
72//-****************************
73// rotate by three euler angles
74//-****************************
75
76
78 double theta1,
79 double psi1) {
80
81 double rx;
82 double ry;
83 double rz;
84
85 register double sinPhi = std::sin( phi1 ), cosPhi = std::cos( phi1 );
86 register double sinTheta = std::sin( theta1 ), cosTheta1 = std::cos( theta1 );
87 register double sinPsi = std::sin( psi1 ), cosPsi = std::cos( psi1 );
88
89 rx = (cosPsi * cosPhi - cosTheta1 * sinPsi * sinPhi) * dx +
90 (cosPsi * sinPhi + cosTheta1 * sinPsi * cosPhi) * dy +
91 (sinPsi * sinTheta) * dz ;
92
93 ry = (- sinPsi * cosPhi - cosTheta1 * cosPsi * sinPhi) * dx +
94 (- sinPsi * sinPhi + cosTheta1 * cosPsi * cosPhi) * dy +
95 (cosPsi * sinTheta) * dz ;
96
97 rz = (sinTheta * sinPhi) * dx +
98 (- sinTheta * cosPhi) * dy +
99 (cosTheta1) * dz ;
100
101 dx = rx;
102 dy = ry;
103 dz = rz;
104
105 return *this;
106
107} /* rotate */
108
109
110
111//-*******************
112// rotate(HepAxisAngle)
113// rotate(HepEulerAngles)
114//-*******************
115
117 return rotate( ax.getAxis(), ax.delta() );
118}
119
121 return rotate( ex.phi(), ex.theta(), ex.psi() );
122}
123
124
125//-***********************
126// rotationOf(HepAxisAngle)
127// rotationOf(HepEulerAngles)
128// and coordinate axis rotations
129//-***********************
130
131Hep3Vector rotationOf (const Hep3Vector & vec, const HepAxisAngle & ax) {
132 Hep3Vector vv(vec);
133 return vv.rotate (ax);
134}
135
137 const Hep3Vector & axis, double ddelta) {
138 Hep3Vector vv(vec);
139 return vv.rotate(axis, ddelta);
140}
141
143 Hep3Vector vv(vec);
144 return vv.rotate (ex);
145}
146
148 double phi, double theta, double psi) {
149 Hep3Vector vv(vec);
150 return vv.rotate(phi, theta, psi);
151}
152
153Hep3Vector rotationXOf (const Hep3Vector & vec, double ddelta) {
154 Hep3Vector vv(vec);
155 return vv.rotateX (ddelta);
156}
157
158Hep3Vector rotationYOf (const Hep3Vector & vec, double ddelta) {
159 Hep3Vector vv(vec);
160 return vv.rotateY (ddelta);
161}
162
163Hep3Vector rotationZOf (const Hep3Vector & vec, double ddelta) {
164 Hep3Vector vv(vec);
165 return vv.rotateZ (ddelta);
166}
167
168} // namespace CLHEP
169
#define ZMthrowA(A)
Hep3Vector & rotateY(double)
Definition: ThreeVector.cc:134
Hep3Vector & rotateX(double)
Definition: ThreeVector.cc:124
double getZ() const
Hep3Vector & rotateZ(double)
Definition: ThreeVector.cc:144
double mag() const
double getX() const
Hep3Vector & rotate(double, const Hep3Vector &)
Definition: ThreeVectorR.cc:29
double getY() const
double delta() const
Hep3Vector getAxis() const
double phi() const
double theta() const
double psi() const
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)