CLHEP 2.0.4.7 Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

SpaceVectorR.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 // ---------------------------------------------------------------------------
00003 //
00004 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
00005 //
00006 // This is the implementation of the subset of those methods of the Hep3Vector 
00007 // class which originated from the ZOOM SpaceVector class *and* which involve
00008 // the concepts of rotation.
00009 //
00010 
00011 #ifdef GNUPRAGMA
00012 #pragma implementation
00013 #endif
00014 
00015 #include "CLHEP/Vector/defs.h"
00016 #include "CLHEP/Vector/ThreeVector.h"
00017 #include "CLHEP/Vector/AxisAngle.h"
00018 #include "CLHEP/Vector/EulerAngles.h"
00019 #include "CLHEP/Vector/ZMxpv.h"
00020 
00021 namespace CLHEP  {
00022 
00023 //-************************
00024 // rotate about axis
00025 //-************************
00026 
00027 Hep3Vector & Hep3Vector::rotate (const Hep3Vector & axis,
00028                                    double delta) {
00029   double r = axis.mag();
00030   if ( r == 0 ) {
00031     ZMthrowA (ZMxpvZeroVector(
00032       "Attempt to rotate around a zero vector axis! "));
00033     return *this;
00034   }
00035   register double scale=1.0/r;
00036   register double ux = scale*axis.getX();
00037   register double uy = scale*axis.getY();
00038   register double uz = scale*axis.getZ();
00039   double cd = cos(delta);
00040   double sd = sin(delta);
00041   register double ocd = 1 - cd;
00042   double rx;
00043   double ry;
00044   double rz;
00045 
00046   { register double  ocdux = ocd * ux;
00047     rx = dx * ( cd + ocdux * ux           ) +
00048          dy * (      ocdux * uy - sd * uz ) +
00049          dz * (      ocdux * uz + sd * uy ) ;
00050   }
00051 
00052   { register double  ocduy = ocd * uy;
00053     ry = dy * ( cd + ocduy * uy           ) +
00054          dz * (      ocduy * uz - sd * ux ) +
00055          dx * (      ocduy * ux + sd * uz ) ;
00056   }
00057 
00058   { register double  ocduz = ocd * uz;
00059     rz = dz * ( cd + ocduz * uz           ) +
00060          dx * (      ocduz * ux - sd * uy ) +
00061          dy * (      ocduz * uy + sd * ux ) ;
00062   }
00063 
00064   dx = rx;
00065   dy = ry;
00066   dz = rz;
00067 
00068   return *this;
00069 } /* rotate */
00070 
00071 
00072 //-****************************
00073 // rotate by three euler angles
00074 //-****************************
00075 
00076 
00077 Hep3Vector & Hep3Vector::rotate (double phi, 
00078                                  double theta, 
00079                                  double psi)  {
00080 
00081   double rx;
00082   double ry;
00083   double rz;
00084 
00085   register double sinPhi   = sin( phi   ), cosPhi   = cos( phi   );
00086   register double sinTheta = sin( theta ), cosTheta = cos( theta );
00087   register double sinPsi   = sin( psi   ), cosPsi   = cos( psi   );
00088 
00089   rx =  (cosPsi * cosPhi   - cosTheta * sinPsi * sinPhi)   * dx  +
00090         (cosPsi * sinPhi   + cosTheta * sinPsi * cosPhi)   * dy  +
00091         (sinPsi * sinTheta)                                * dz  ;
00092 
00093   ry =  (- sinPsi * cosPhi - cosTheta * cosPsi * sinPhi)   * dx  +
00094         (- sinPsi * sinPhi + cosTheta * cosPsi * cosPhi)   * dy  +
00095         (cosPsi * sinTheta)                                * dz  ;
00096 
00097   rz =  (sinTheta * sinPhi)                                * dx  +
00098         (- sinTheta * cosPhi)                              * dy  +
00099         (cosTheta)                                         * dz  ;
00100 
00101   dx = rx;
00102   dy = ry;
00103   dz = rz;
00104 
00105   return *this;
00106 
00107 } /* rotate */
00108 
00109 
00110 
00111 //-*******************
00112 // rotate(HepAxisAngle)
00113 // rotate(HepEulerAngles)
00114 //-*******************
00115 
00116 Hep3Vector & Hep3Vector::rotate (const HepAxisAngle & ax ) {
00117   return rotate( ax.getAxis(), ax.delta() );
00118 }
00119 
00120 Hep3Vector & Hep3Vector::rotate (const HepEulerAngles & ex ) {
00121   return rotate( ex.phi(), ex.theta(), ex.psi() );
00122 }
00123 
00124 
00125 //-***********************
00126 // rotationOf(HepAxisAngle)
00127 // rotationOf(HepEulerAngles)
00128 // and coordinate axis rotations
00129 //-***********************
00130 
00131 Hep3Vector rotationOf (const Hep3Vector & vec, const HepAxisAngle & ax) {
00132   Hep3Vector vv(vec);
00133   return vv.rotate (ax);
00134 }
00135 
00136 Hep3Vector rotationOf (const Hep3Vector & vec,
00137                        const Hep3Vector & axis, double delta) {
00138   Hep3Vector vv(vec);
00139   return vv.rotate(axis, delta);
00140 }
00141 
00142 Hep3Vector rotationOf (const Hep3Vector & vec, const HepEulerAngles & ex) {
00143   Hep3Vector vv(vec);
00144   return vv.rotate (ex);
00145 }
00146 
00147 Hep3Vector rotationOf (const Hep3Vector & vec,
00148                        double phi, double theta, double psi) {
00149   Hep3Vector vv(vec);
00150   return vv.rotate(phi, theta, psi);
00151 }
00152 
00153 Hep3Vector rotationXOf (const Hep3Vector & vec, double delta) {
00154   Hep3Vector vv(vec);
00155   return vv.rotateX (delta);
00156 }
00157 
00158 Hep3Vector rotationYOf (const Hep3Vector & vec, double delta) {
00159   Hep3Vector vv(vec);
00160   return vv.rotateY (delta);
00161 }
00162 
00163 Hep3Vector rotationZOf (const Hep3Vector & vec, double delta) {
00164   Hep3Vector vv(vec);
00165   return vv.rotateZ (delta);
00166 }
00167 
00168 }  // namespace CLHEP
00169 

Generated on Thu Jul 1 22:02:31 2010 for CLHEP by  doxygen 1.4.7