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