source: trunk/CLHEP/src/SpaceVectorR.cc@ 16

Last change on this file since 16 was 4, checked in by Pavel Demin, 16 years ago

first commit

File size: 4.1 KB
RevLine 
[4]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
27Hep3Vector & Hep3Vector::rotate (const Hep3Vector & axis,
28 double delta) {
29 double r = axis.mag();
30 if ( r == 0 ) {
31 ZMthrowA (ZMxpvZeroVector(
32 "Attempt to rotate around a zero vector axis! "));
33 return *this;
34 }
35 register double scale=1.0/r;
36 register double ux = scale*axis.getX();
37 register double uy = scale*axis.getY();
38 register double uz = scale*axis.getZ();
39 double cd = cos(delta);
40 double sd = sin(delta);
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//-****************************
74// rotate by three euler angles
75//-****************************
76
77
78Hep3Vector & Hep3Vector::rotate (double phi,
79 double theta,
80 double psi) {
81
82 double rx;
83 double ry;
84 double rz;
85
86 register double sinPhi = sin( phi ), cosPhi = cos( phi );
87 register double sinTheta = sin( theta ), cosTheta = cos( theta );
88 register double sinPsi = sin( psi ), cosPsi = cos( psi );
89
90 rx = (cosPsi * cosPhi - cosTheta * sinPsi * sinPhi) * dx +
91 (cosPsi * sinPhi + cosTheta * sinPsi * cosPhi) * dy +
92 (sinPsi * sinTheta) * dz ;
93
94 ry = (- sinPsi * cosPhi - cosTheta * cosPsi * sinPhi) * dx +
95 (- sinPsi * sinPhi + cosTheta * cosPsi * cosPhi) * dy +
96 (cosPsi * sinTheta) * dz ;
97
98 rz = (sinTheta * sinPhi) * dx +
99 (- sinTheta * cosPhi) * dy +
100 (cosTheta) * dz ;
101
102 dx = rx;
103 dy = ry;
104 dz = rz;
105
106 return *this;
107
108} /* rotate */
109
110
111
112
113//-*******************
114// rotate(HepAxisAngle)
115// rotate(HepEulerAngles)
116//-*******************
117
118Hep3Vector & Hep3Vector::rotate (const HepAxisAngle & ax ) {
119 return rotate( ax.getAxis(), ax.delta() );
120}
121
122Hep3Vector & Hep3Vector::rotate (const HepEulerAngles & ex ) {
123 return rotate( ex.phi(), ex.theta(), ex.psi() );
124}
125
126
127//-***********************
128// rotationOf(HepAxisAngle)
129// rotationOf(HepEulerAngles)
130// and coordinate axis rotations
131//-***********************
132
133Hep3Vector rotationOf (const Hep3Vector & vec, const HepAxisAngle & ax) {
134 Hep3Vector vv(vec);
135 return vv.rotate (ax);
136}
137
138Hep3Vector rotationOf (const Hep3Vector & vec,
139 const Hep3Vector & axis, double delta) {
140 Hep3Vector vv(vec);
141 return vv.rotate(axis, delta);
142}
143
144Hep3Vector rotationOf (const Hep3Vector & vec, const HepEulerAngles & ex) {
145 Hep3Vector vv(vec);
146 return vv.rotate (ex);
147}
148
149Hep3Vector rotationOf (const Hep3Vector & vec,
150 double phi, double theta, double psi) {
151 Hep3Vector vv(vec);
152 return vv.rotate(phi, theta, psi);
153}
154
155Hep3Vector rotationXOf (const Hep3Vector & vec, double delta) {
156 Hep3Vector vv(vec);
157 return vv.rotateX (delta);
158}
159
160Hep3Vector rotationYOf (const Hep3Vector & vec, double delta) {
161 Hep3Vector vv(vec);
162 return vv.rotateY (delta);
163}
164
165Hep3Vector rotationZOf (const Hep3Vector & vec, double delta) {
166 Hep3Vector vv(vec);
167 return vv.rotateZ (delta);
168}
169
170} // namespace CLHEP
171
Note: See TracBrowser for help on using the repository browser.