source: trunk/CLHEP/Vector/Rotation.icc@ 20

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

first commit

File size: 11.4 KB
Line 
1// -*- C++ -*-
2// $Id: Rotation.icc,v 1.1 2008-06-04 14:14:59 demin Exp $
3// ---------------------------------------------------------------------------
4//
5// This file is a part of the CLHEP - a Class Library for High Energy Physics.
6//
7// This is the definitions of the inline member functions of the
8// HepRotation class
9//
10
11namespace CLHEP {
12
13// Put commonly used accessors as early as possible to avoid inlining misses:
14
15inline double HepRotation::xx() const { return rxx; }
16inline double HepRotation::xy() const { return rxy; }
17inline double HepRotation::xz() const { return rxz; }
18inline double HepRotation::yx() const { return ryx; }
19inline double HepRotation::yy() const { return ryy; }
20inline double HepRotation::yz() const { return ryz; }
21inline double HepRotation::zx() const { return rzx; }
22inline double HepRotation::zy() const { return rzy; }
23inline double HepRotation::zz() const { return rzz; }
24
25inline HepRep3x3 HepRotation::rep3x3() const {
26 return HepRep3x3 ( rxx, rxy, rxz,
27 ryx, ryy, ryz,
28 rzx, rzy, rzz );
29}
30
31inline double HepRotation::xt() const { return 0.0; }
32inline double HepRotation::yt() const { return 0.0; }
33inline double HepRotation::zt() const { return 0.0; }
34inline double HepRotation::tx() const { return 0.0; }
35inline double HepRotation::ty() const { return 0.0; }
36inline double HepRotation::tz() const { return 0.0; }
37inline double HepRotation::tt() const { return 1.0; }
38
39inline HepRep4x4 HepRotation::rep4x4() const {
40 return HepRep4x4 ( rxx, rxy, rxz, 0.0,
41 ryx, ryy, ryz, 0.0,
42 rzx, rzy, rzz, 0.0,
43 0.0, 0.0, 0.0, 1.0 );
44}
45
46// Ctors etc:
47
48inline HepRotation::HepRotation() : rxx(1.0), rxy(0.0), rxz(0.0),
49 ryx(0.0), ryy(1.0), ryz(0.0),
50 rzx(0.0), rzy(0.0), rzz(1.0) {}
51
52inline HepRotation::HepRotation(const HepRotation & m) :
53 rxx(m.rxx), rxy(m.rxy), rxz(m.rxz),
54 ryx(m.ryx), ryy(m.ryy), ryz(m.ryz),
55 rzx(m.rzx), rzy(m.rzy), rzz(m.rzz) {}
56
57inline HepRotation::HepRotation
58 (double mxx, double mxy, double mxz,
59 double myx, double myy, double myz,
60 double mzx, double mzy, double mzz) :
61 rxx(mxx), rxy(mxy), rxz(mxz),
62 ryx(myx), ryy(myy), ryz(myz),
63 rzx(mzx), rzy(mzy), rzz(mzz) {}
64
65inline HepRotation::HepRotation ( const HepRep3x3 & m ) :
66 rxx(m.xx_), rxy(m.xy_), rxz(m.xz_),
67 ryx(m.yx_), ryy(m.yy_), ryz(m.yz_),
68 rzx(m.zx_), rzy(m.zy_), rzz(m.zz_) {}
69
70inline HepRotation::HepRotation(const HepRotationX & rx) :
71 rxx(1.0), rxy(0.0), rxz(0.0),
72 ryx(0.0), ryy(rx.yy()), ryz(rx.yz()),
73 rzx(0.0), rzy(rx.zy()), rzz(rx.zz()) {}
74
75inline HepRotation::HepRotation(const HepRotationY & ry) :
76 rxx(ry.xx()), rxy(0.0), rxz(ry.xz()),
77 ryx(0.0), ryy(1.0), ryz(0.0),
78 rzx(ry.zx()), rzy(0.0), rzz(ry.zz()) {}
79
80inline HepRotation::HepRotation(const HepRotationZ & rz) :
81 rxx(rz.xx()), rxy(rz.xy()), rxz(0.0),
82 ryx(rz.yx()), ryy(rz.yy()), ryz(0.0),
83 rzx(0.0), rzy(0.0), rzz(1.0) {}
84
85inline HepRotation::~HepRotation() {}
86
87// More accessors:
88
89inline HepRotation::HepRotation_row::HepRotation_row
90(const HepRotation & r, int i) : rr(r), ii(i) {}
91
92inline double HepRotation::HepRotation_row::operator [] (int jj) const {
93 return rr(ii,jj);
94}
95
96inline
97const HepRotation::HepRotation_row HepRotation::operator [] (int i) const {
98 return HepRotation_row(*this, i);
99}
100
101inline Hep3Vector HepRotation::colX() const
102 { return Hep3Vector ( rxx, ryx, rzx ); }
103inline Hep3Vector HepRotation::colY() const
104 { return Hep3Vector ( rxy, ryy, rzy ); }
105inline Hep3Vector HepRotation::colZ() const
106 { return Hep3Vector ( rxz, ryz, rzz ); }
107
108inline Hep3Vector HepRotation::rowX() const
109 { return Hep3Vector ( rxx, rxy, rxz ); }
110inline Hep3Vector HepRotation::rowY() const
111 { return Hep3Vector ( ryx, ryy, ryz ); }
112inline Hep3Vector HepRotation::rowZ() const
113 { return Hep3Vector ( rzx, rzy, rzz ); }
114
115inline HepLorentzVector HepRotation::col1() const
116 { return HepLorentzVector (colX(), 0); }
117inline HepLorentzVector HepRotation::col2() const
118 { return HepLorentzVector (colY(), 0); }
119inline HepLorentzVector HepRotation::col3() const
120 { return HepLorentzVector (colZ(), 0); }
121inline HepLorentzVector HepRotation::col4() const
122 { return HepLorentzVector (0,0,0,1); }
123inline HepLorentzVector HepRotation::row1() const
124 { return HepLorentzVector (rowX(), 0); }
125inline HepLorentzVector HepRotation::row2() const
126 { return HepLorentzVector (rowY(), 0); }
127inline HepLorentzVector HepRotation::row3() const
128 { return HepLorentzVector (rowZ(), 0); }
129inline HepLorentzVector HepRotation::row4() const
130 { return HepLorentzVector (0,0,0,1); }
131
132inline double HepRotation::getPhi () const { return phi(); }
133inline double HepRotation::getTheta() const { return theta(); }
134inline double HepRotation::getPsi () const { return psi(); }
135inline double HepRotation::getDelta() const { return delta(); }
136inline Hep3Vector HepRotation::getAxis () const { return axis(); }
137
138inline HepRotation & HepRotation::operator = (const HepRotation & m) {
139 rxx = m.rxx;
140 rxy = m.rxy;
141 rxz = m.rxz;
142 ryx = m.ryx;
143 ryy = m.ryy;
144 ryz = m.ryz;
145 rzx = m.rzx;
146 rzy = m.rzy;
147 rzz = m.rzz;
148 return *this;
149}
150
151inline HepRotation & HepRotation::set(const HepRep3x3 & m) {
152 rxx = m.xx_;
153 rxy = m.xy_;
154 rxz = m.xz_;
155 ryx = m.yx_;
156 ryy = m.yy_;
157 ryz = m.yz_;
158 rzx = m.zx_;
159 rzy = m.zy_;
160 rzz = m.zz_;
161 return *this;
162}
163
164inline HepRotation & HepRotation::set(const HepRotationX & r) {
165 return (set (r.rep3x3()));
166}
167inline HepRotation & HepRotation::set(const HepRotationY & r) {
168 return (set (r.rep3x3()));
169}
170inline HepRotation & HepRotation::set(const HepRotationZ & r) {
171 return (set (r.rep3x3()));
172}
173
174inline HepRotation & HepRotation::operator= (const HepRotationX & r) {
175 return (set (r.rep3x3()));
176}
177inline HepRotation & HepRotation::operator= (const HepRotationY & r) {
178 return (set (r.rep3x3()));
179}
180inline HepRotation & HepRotation::operator= (const HepRotationZ & r) {
181 return (set (r.rep3x3()));
182}
183
184inline Hep3Vector HepRotation::operator * (const Hep3Vector & p) const {
185 return Hep3Vector(rxx*p.x() + rxy*p.y() + rxz*p.z(),
186 ryx*p.x() + ryy*p.y() + ryz*p.z(),
187 rzx*p.x() + rzy*p.y() + rzz*p.z());
188// This is identical to the code in the CLHEP 1.6 version
189}
190
191inline Hep3Vector HepRotation::operator () (const Hep3Vector & p) const {
192 register double x = p.x();
193 register double y = p.y();
194 register double z = p.z();
195 return Hep3Vector(rxx*x + rxy*y + rxz*z,
196 ryx*x + ryy*y + ryz*z,
197 rzx*x + rzy*y + rzz*z);
198}
199
200inline HepLorentzVector
201HepRotation::operator () (const HepLorentzVector & w) const {
202 return HepLorentzVector( operator() (w.vect()), w.t() );
203}
204
205inline HepLorentzVector HepRotation::operator *
206 (const HepLorentzVector & p) const {
207 return operator()(p);
208}
209
210inline HepRotation HepRotation::operator* (const HepRotation & r) const {
211 return HepRotation(rxx*r.rxx + rxy*r.ryx + rxz*r.rzx,
212 rxx*r.rxy + rxy*r.ryy + rxz*r.rzy,
213 rxx*r.rxz + rxy*r.ryz + rxz*r.rzz,
214 ryx*r.rxx + ryy*r.ryx + ryz*r.rzx,
215 ryx*r.rxy + ryy*r.ryy + ryz*r.rzy,
216 ryx*r.rxz + ryy*r.ryz + ryz*r.rzz,
217 rzx*r.rxx + rzy*r.ryx + rzz*r.rzx,
218 rzx*r.rxy + rzy*r.ryy + rzz*r.rzy,
219 rzx*r.rxz + rzy*r.ryz + rzz*r.rzz );
220}
221
222inline HepRotation HepRotation::operator * (const HepRotationX & rx) const {
223 double yy = rx.yy();
224 double yz = rx.yz();
225 double zy = -yz;
226 double zz = yy;
227 return HepRotation(
228 rxx, rxy*yy + rxz*zy, rxy*yz + rxz*zz,
229 ryx, ryy*yy + ryz*zy, ryy*yz + ryz*zz,
230 rzx, rzy*yy + rzz*zy, rzy*yz + rzz*zz );
231}
232
233inline HepRotation HepRotation::operator * (const HepRotationY & ry) const {
234 double xx = ry.xx();
235 double xz = ry.xz();
236 double zx = -xz;
237 double zz = xx;
238 return HepRotation(
239 rxx*xx + rxz*zx, rxy, rxx*xz + rxz*zz,
240 ryx*xx + ryz*zx, ryy, ryx*xz + ryz*zz,
241 rzx*xx + rzz*zx, rzy, rzx*xz + rzz*zz );
242}
243
244inline HepRotation HepRotation::operator * (const HepRotationZ & rz) const {
245 double xx = rz.xx();
246 double xy = rz.xy();
247 double yx = -xy;
248 double yy = xx;
249 return HepRotation(
250 rxx*xx + rxy*yx, rxx*xy + rxy*yy, rxz,
251 ryx*xx + ryy*yx, ryx*xy + ryy*yy, ryz,
252 rzx*xx + rzy*yx, rzx*xy + rzy*yy, rzz );
253}
254
255
256inline HepRotation & HepRotation::operator *= (const HepRotation & r) {
257 return *this = (*this) * (r);
258}
259
260inline HepRotation & HepRotation::operator *= (const HepRotationX & r) {
261 return *this = (*this) * (r); }
262inline HepRotation & HepRotation::operator *= (const HepRotationY & r) {
263 return *this = (*this) * (r); }
264inline HepRotation & HepRotation::operator *= (const HepRotationZ & r) {
265 return *this = (*this) * (r); }
266
267inline HepRotation & HepRotation::transform(const HepRotation & r) {
268 return *this = r * (*this);
269}
270
271inline HepRotation & HepRotation::transform(const HepRotationX & r) {
272 return *this = r * (*this); }
273inline HepRotation & HepRotation::transform(const HepRotationY & r) {
274 return *this = r * (*this); }
275inline HepRotation & HepRotation::transform(const HepRotationZ & r) {
276 return *this = r * (*this); }
277
278inline HepRotation HepRotation::inverse() const {
279 return HepRotation( rxx, ryx, rzx,
280 rxy, ryy, rzy,
281 rxz, ryz, rzz );
282}
283
284inline HepRotation inverseOf (const HepRotation & r) {
285 return r.inverse();
286}
287
288inline HepRotation & HepRotation::invert() {
289 return *this=inverse();
290}
291
292inline HepRotation & HepRotation::rotate
293 (double delta, const Hep3Vector * p) {
294 return rotate(delta, *p);
295}
296
297inline bool HepRotation::operator== ( const HepRotation & r ) const {
298 return ( rxx==r.rxx && rxy==r.rxy && rxz==r.rxz &&
299 ryx==r.ryx && ryy==r.ryy && ryz==r.ryz &&
300 rzx==r.rzx && rzy==r.rzy && rzz==r.rzz );
301}
302inline bool HepRotation::operator!= ( const HepRotation & r ) const {
303 return ! operator==(r);
304}
305inline bool HepRotation::operator< ( const HepRotation & r ) const
306 { return compare(r)< 0; }
307inline bool HepRotation::operator<=( const HepRotation & r ) const
308 { return compare(r)<=0; }
309inline bool HepRotation::operator>=( const HepRotation & r ) const
310 { return compare(r)>=0; }
311inline bool HepRotation::operator> ( const HepRotation & r ) const
312 { return compare(r)> 0; }
313
314inline double HepRotation::getTolerance() {
315 return Hep4RotationInterface::tolerance;
316}
317inline double HepRotation::setTolerance(double tol) {
318 return Hep4RotationInterface::setTolerance(tol);
319}
320
321inline HepRotation operator * (const HepRotationX & rx, const HepRotation & r){
322 HepRep3x3 m = r.rep3x3();
323 double c = rx.yy();
324 double s = rx.zy();
325 return HepRotation ( m.xx_, m.xy_, m.xz_,
326 c*m.yx_-s*m.zx_, c*m.yy_-s*m.zy_, c*m.yz_-s*m.zz_,
327 s*m.yx_+c*m.zx_, s*m.yy_+c*m.zy_, s*m.yz_+c*m.zz_ );
328}
329
330inline HepRotation operator * (const HepRotationY & ry, const HepRotation & r){
331 HepRep3x3 m = r.rep3x3();
332 double c = ry.xx();
333 double s = ry.xz();
334 return HepRotation ( c*m.xx_+s*m.zx_, c*m.xy_+s*m.zy_, c*m.xz_+s*m.zz_,
335 m.yx_, m.yy_, m.yz_,
336 -s*m.xx_+c*m.zx_,-s*m.xy_+c*m.zy_,-s*m.xz_+c*m.zz_ );
337}
338
339inline HepRotation operator * (const HepRotationZ & rz, const HepRotation & r){
340 HepRep3x3 m = r.rep3x3();
341 double c = rz.xx();
342 double s = rz.yx();
343 return HepRotation ( c*m.xx_-s*m.yx_, c*m.xy_-s*m.yy_, c*m.xz_-s*m.yz_,
344 s*m.xx_+c*m.yx_, s*m.xy_+c*m.yy_, s*m.xz_+c*m.yz_,
345 m.zx_, m.zy_, m.zz_ );
346}
347
348} // namespace CLHEP
Note: See TracBrowser for help on using the repository browser.