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/ThreeVector.h"
00016 #include "CLHEP/Vector/AxisAngle.h"
00017 #include "CLHEP/Vector/EulerAngles.h"
00018 
00019 namespace CLHEP  {
00020 
00021 //-************************
00022 // rotate about axis
00023 //-************************
00024 
00025 Hep3Vector & Hep3Vector::rotate (const Hep3Vector & axis,
00026                                    double ddelta) {
00027   double r1 = axis.mag();
00028   if ( r1 == 0 ) {
00029     std::cerr << "Hep3Vector::rotate() - "
00030       << "Attempt to rotate around a zero vector axis! " << std::endl;
00031     return *this;
00032   }
00033   register double scale=1.0/r1;
00034   register double ux = scale*axis.getX();
00035   register double uy = scale*axis.getY();
00036   register double uz = scale*axis.getZ();
00037   double cd = std::cos(ddelta);
00038   double sd = std::sin(ddelta);
00039   register double ocd = 1 - cd;
00040   double rx;
00041   double ry;
00042   double rz;
00043 
00044   { register double  ocdux = ocd * ux;
00045     rx = dx * ( cd + ocdux * ux           ) +
00046          dy * (      ocdux * uy - sd * uz ) +
00047          dz * (      ocdux * uz + sd * uy ) ;
00048   }
00049 
00050   { register double  ocduy = ocd * uy;
00051     ry = dy * ( cd + ocduy * uy           ) +
00052          dz * (      ocduy * uz - sd * ux ) +
00053          dx * (      ocduy * ux + sd * uz ) ;
00054   }
00055 
00056   { register double  ocduz = ocd * uz;
00057     rz = dz * ( cd + ocduz * uz           ) +
00058          dx * (      ocduz * ux - sd * uy ) +
00059          dy * (      ocduz * uy + sd * ux ) ;
00060   }
00061 
00062   dx = rx;
00063   dy = ry;
00064   dz = rz;
00065 
00066   return *this;
00067 } /* rotate */
00068 
00069 //-****************************
00070 // rotate by three euler angles
00071 //-****************************
00072 
00073 
00074 Hep3Vector & Hep3Vector::rotate (double phi1, 
00075                                  double theta1, 
00076                                  double psi1)  {
00077 
00078   double rx;
00079   double ry;
00080   double rz;
00081 
00082   register double sinPhi   = std::sin( phi1   ), cosPhi   = std::cos( phi1   );
00083   register double sinTheta = std::sin( theta1 ), cosTheta1 = std::cos( theta1 );
00084   register double sinPsi   = std::sin( psi1   ), cosPsi   = std::cos( psi1   );
00085 
00086   rx =  (cosPsi * cosPhi   - cosTheta1 * sinPsi * sinPhi)   * dx  +
00087         (cosPsi * sinPhi   + cosTheta1 * sinPsi * cosPhi)   * dy  +
00088         (sinPsi * sinTheta)                                * dz  ;
00089 
00090   ry =  (- sinPsi * cosPhi - cosTheta1 * cosPsi * sinPhi)   * dx  +
00091         (- sinPsi * sinPhi + cosTheta1 * cosPsi * cosPhi)   * dy  +
00092         (cosPsi * sinTheta)                                * dz  ;
00093 
00094   rz =  (sinTheta * sinPhi)                                * dx  +
00095         (- sinTheta * cosPhi)                              * dy  +
00096         (cosTheta1)                                        * dz  ;
00097 
00098   dx = rx;
00099   dy = ry;
00100   dz = rz;
00101 
00102   return *this;
00103 
00104 } /* rotate */
00105 
00106 
00107 //-*******************
00108 // rotate(HepAxisAngle)
00109 // rotate(HepEulerAngles)
00110 //-*******************
00111 
00112 Hep3Vector & Hep3Vector::rotate (const HepAxisAngle & ax ) {
00113   return rotate( ax.getAxis(), ax.delta() );
00114 }
00115 
00116 Hep3Vector & Hep3Vector::rotate (const HepEulerAngles & ex ) {
00117   return rotate( ex.phi(), ex.theta(), ex.psi() );
00118 }
00119 
00120 
00121 //-***********************
00122 // rotationOf(HepAxisAngle)
00123 // rotationOf(HepEulerAngles)
00124 // and coordinate axis rotations
00125 //-***********************
00126 
00127 Hep3Vector rotationOf (const Hep3Vector & vec, const HepAxisAngle & ax) {
00128   Hep3Vector vv(vec);
00129   return vv.rotate (ax);
00130 }
00131 
00132 Hep3Vector rotationOf (const Hep3Vector & vec,
00133                        const Hep3Vector & axis, double ddelta) {
00134   Hep3Vector vv(vec);
00135   return vv.rotate(axis, ddelta);
00136 }
00137 
00138 Hep3Vector rotationOf (const Hep3Vector & vec, const HepEulerAngles & ex) {
00139   Hep3Vector vv(vec);
00140   return vv.rotate (ex);
00141 }
00142 
00143 Hep3Vector rotationOf (const Hep3Vector & vec,
00144                        double phi, double theta, double psi) {
00145   Hep3Vector vv(vec);
00146   return vv.rotate(phi, theta, psi);
00147 }
00148 
00149 Hep3Vector rotationXOf (const Hep3Vector & vec, double ddelta) {
00150   Hep3Vector vv(vec);
00151   return vv.rotateX (ddelta);
00152 }
00153 
00154 Hep3Vector rotationYOf (const Hep3Vector & vec, double ddelta) {
00155   Hep3Vector vv(vec);
00156   return vv.rotateY (ddelta);
00157 }
00158 
00159 Hep3Vector rotationZOf (const Hep3Vector & vec, double ddelta) {
00160   Hep3Vector vv(vec);
00161   return vv.rotateZ (ddelta);
00162 }
00163 
00164 }  // namespace CLHEP

Generated on Mon May 27 17:50:35 2013 for Geant4 by  doxygen 1.4.7