1// -*- C++ -*- 2// $Id: Rotation.icc,v 1.2 2003/10/10 21:42:35 garren 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 & m1) : 53 rxx(m1.rxx), rxy(m1.rxy), rxz(m1.rxz), 54 ryx(m1.ryx), ryy(m1.ryy), ryz(m1.ryz), 55 rzx(m1.rzx), rzy(m1.rzy), rzz(m1.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 & m1 ) : 66 rxx(m1.xx_), rxy(m1.xy_), rxz(m1.xz_), 67 ryx(m1.yx_), ryy(m1.yy_), ryz(m1.yz_), 68 rzx(m1.zx_), rzy(m1.zy_), rzz(m1.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 & m1) { 139 rxx = m1.rxx; 140 rxy = m1.rxy; 141 rxz = m1.rxz; 142 ryx = m1.ryx; 143 ryy = m1.ryy; 144 ryz = m1.ryz; 145 rzx = m1.rzx; 146 rzy = m1.rzy; 147 rzz = m1.rzz; 148 return *this; 149} 150 151inline HepRotation & HepRotation::set(const HepRep3x3 & m1) { 152 rxx = m1.xx_; 153 rxy = m1.xy_; 154 rxz = m1.xz_; 155 ryx = m1.yx_; 156 ryy = m1.yy_; 157 ryz = m1.yz_; 158 rzx = m1.zx_; 159 rzy = m1.zy_; 160 rzz = m1.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 double x = p.x(); 193 double y = p.y(); 194 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 yy1 = rx.yy(); 224 double yz1 = rx.yz(); 225 double zy1 = -yz1; 226 double zz1 = yy1; 227 return HepRotation( 228 rxx, rxy*yy1 + rxz*zy1, rxy*yz1 + rxz*zz1, 229 ryx, ryy*yy1 + ryz*zy1, ryy*yz1 + ryz*zz1, 230 rzx, rzy*yy1 + rzz*zy1, rzy*yz1 + rzz*zz1 ); 231} 232 233inline HepRotation HepRotation::operator * (const HepRotationY & ry) const { 234 double xx1 = ry.xx(); 235 double xz1 = ry.xz(); 236 double zx1 = -xz1; 237 double zz1 = xx1; 238 return HepRotation( 239 rxx*xx1 + rxz*zx1, rxy, rxx*xz1 + rxz*zz1, 240 ryx*xx1 + ryz*zx1, ryy, ryx*xz1 + ryz*zz1, 241 rzx*xx1 + rzz*zx1, rzy, rzx*xz1 + rzz*zz1 ); 242} 243 244inline HepRotation HepRotation::operator * (const HepRotationZ & rz) const { 245 double xx1 = rz.xx(); 246 double xy1 = rz.xy(); 247 double yx1 = -xy1; 248 double yy1 = xx1; 249 return HepRotation( 250 rxx*xx1 + rxy*yx1, rxx*xy1 + rxy*yy1, rxz, 251 ryx*xx1 + ryy*yx1, ryx*xy1 + ryy*yy1, ryz, 252 rzx*xx1 + rzy*yx1, rzx*xy1 + rzy*yy1, 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 ddelta, const Hep3Vector * p) { 294 return rotate(ddelta, *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 mmm = r.rep3x3(); 323 double c = rx.yy(); 324 double ss = rx.zy(); 325 return HepRotation ( mmm.xx_, mmm.xy_, mmm.xz_, 326 c*mmm.yx_-ss*mmm.zx_, c*mmm.yy_-ss*mmm.zy_, c*mmm.yz_-ss*mmm.zz_, 327 ss*mmm.yx_+c*mmm.zx_, ss*mmm.yy_+c*mmm.zy_, ss*mmm.yz_+c*mmm.zz_ ); 328} 329 330inline HepRotation operator * (const HepRotationY & ry, const HepRotation & r){ 331 HepRep3x3 mmm = r.rep3x3(); 332 double c = ry.xx(); 333 double ss = ry.xz(); 334 return HepRotation ( c*mmm.xx_+ss*mmm.zx_, c*mmm.xy_+ss*mmm.zy_, c*mmm.xz_+ss*mmm.zz_, 335 mmm.yx_, mmm.yy_, mmm.yz_, 336 -ss*mmm.xx_+c*mmm.zx_,-ss*mmm.xy_+c*mmm.zy_,-ss*mmm.xz_+c*mmm.zz_ ); 337} 338 339inline HepRotation operator * (const HepRotationZ & rz, const HepRotation & r){ 340 HepRep3x3 mmm = r.rep3x3(); 341 double c = rz.xx(); 342 double ss = rz.yx(); 343 return HepRotation ( c*mmm.xx_-ss*mmm.yx_, c*mmm.xy_-ss*mmm.yy_, c*mmm.xz_-ss*mmm.yz_, 344 ss*mmm.xx_+c*mmm.yx_, ss*mmm.xy_+c*mmm.yy_, ss*mmm.xz_+c*mmm.yz_, 345 mmm.zx_, mmm.zy_, mmm.zz_ ); 346} 347 348} // namespace CLHEP 349