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

RotationA.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 those methods of the HepRotation class which
00007 // were introduced when ZOOM PhysicsVectors was merged in, and which involve 
00008 // the angle/axis representation of a Rotation.
00009 //
00010 
00011 #ifdef GNUPRAGMA
00012 #pragma implementation
00013 #endif
00014 
00015 #include "CLHEP/Vector/defs.h"
00016 #include "CLHEP/Vector/Rotation.h"
00017 #include "CLHEP/Units/PhysicalConstants.h"
00018 
00019 #include <iostream>
00020 #include <cmath>
00021 
00022 namespace CLHEP  {
00023 
00024 // ----------  Constructors and Assignment:
00025 
00026 // axis and angle
00027 
00028 HepRotation & HepRotation::set( const Hep3Vector & axis, double delta ) {
00029 
00030   register double sinDelta = sin(delta), cosDelta = cos(delta);
00031   register double oneMinusCosDelta = 1.0 - cosDelta;
00032 
00033   Hep3Vector u = axis.unit();
00034 
00035   register double uX = u.getX();
00036   register double uY = u.getY();
00037   register double uZ = u.getZ();
00038 
00039   rxx = oneMinusCosDelta * uX * uX  +  cosDelta;
00040   rxy = oneMinusCosDelta * uX * uY  -  sinDelta * uZ;
00041   rxz = oneMinusCosDelta * uX * uZ  +  sinDelta * uY;
00042 
00043   ryx = oneMinusCosDelta * uY * uX  +  sinDelta * uZ;
00044   ryy = oneMinusCosDelta * uY * uY  +  cosDelta;
00045   ryz = oneMinusCosDelta * uY * uZ  -  sinDelta * uX;
00046 
00047   rzx = oneMinusCosDelta * uZ * uX  -  sinDelta * uY;
00048   rzy = oneMinusCosDelta * uZ * uY  +  sinDelta * uX;
00049   rzz = oneMinusCosDelta * uZ * uZ  +  cosDelta;
00050 
00051   return  *this;
00052 
00053 } // HepRotation::set(axis, delta)
00054 
00055 HepRotation::HepRotation ( const Hep3Vector & axis, double delta ) 
00056 {
00057   set( axis, delta );
00058 }  
00059 HepRotation & HepRotation::set( const HepAxisAngle & ax ) {
00060   return  set ( ax.axis(), ax.delta() );
00061 }
00062 HepRotation::HepRotation ( const HepAxisAngle & ax ) 
00063 {
00064   set ( ax.axis(), ax.delta() );
00065 }
00066 
00067 
00068 
00069 double    HepRotation::delta() const {
00070 
00071   double cosdelta = (rxx + ryy + rzz - 1.0) / 2.0;
00072   if (cosdelta > 1.0) {
00073     return 0;
00074   } else if (cosdelta < -1.0) {
00075     return CLHEP::pi;
00076   } else {
00077     return  acos( cosdelta ); // Already safe due to the cosdelta > 1 check
00078   }
00079 
00080 } // delta()
00081 
00082 Hep3Vector HepRotation::axis () const {
00083 
00084   // Determine 2*sin(delta) times the u components (I call this uX, uY, Uz)
00085   // Normalization is not needed; it will be done when returning the 3-Vector
00086 
00087   double  Uz = ryx - rxy;
00088   double  Uy = rxz - rzx;
00089   double  Ux = rzy - ryz;
00090 
00091   if ( (Uz==0) && (Uy==0) && (Ux==0) ) {
00092     if        ( rzz>0 ) {
00093       return Hep3Vector(0,0,1);
00094     } else if ( ryy>0 ) {
00095       return Hep3Vector(0,1,0);
00096     } else {
00097       return Hep3Vector(1,0,0);
00098     }
00099   } else {
00100     return  Hep3Vector( Ux, Uy, Uz ).unit();
00101   }
00102 
00103 } // axis()
00104 
00105 HepAxisAngle HepRotation::axisAngle() const {
00106 
00107   return HepAxisAngle (axis(), delta());
00108 
00109 } // axisAngle() 
00110 
00111 
00112 void HepRotation::setAxis (const Hep3Vector & axis) {
00113   set ( axis, delta() );
00114 }
00115 
00116 void HepRotation::setDelta (double delta) {
00117   set ( axis(), delta );
00118 }
00119 
00120 }  // namespace CLHEP

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