AxisAngle.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------
00002 //
00003 // AxisAngle.cc
00004 //
00005 // History:
00006 //   23-Jan-1998  WEB  Initial draft
00007 //   13-Mar-1998  WEB  Corrected ZMpvAxisAngleRep
00008 //   15-Jun-1998  WEB  Added namespace support
00009 //   26-Jul-2000  MF  CLHEP version
00010 //   12-Apr-2001  MF  NaN-proofing
00011 //
00012 // ----------------------------------------------------------------------
00013 
00014 #include "CLHEP/Vector/AxisAngle.h"
00015 
00016 namespace CLHEP  {
00017 
00018 double HepAxisAngle::tolerance = Hep3Vector::ToleranceTicks * 1.0e-08;
00019 
00020 static void ZMpvAxisAngleRep( const HepAxisAngle & aa, double array[] ) {
00021 
00022   register double sinDelta = std::sin( aa.delta() );
00023   register double cosDelta = std::cos( aa.delta() );
00024   register double oneMinusCosDelta = 1.0 - cosDelta;
00025 
00026   register double uX = aa.getAxis().getX();
00027   register double uY = aa.getAxis().getY();
00028   register double uZ = aa.getAxis().getZ();
00029 
00030   array[0] = oneMinusCosDelta * uX * uX  +  cosDelta;
00031   array[1] = oneMinusCosDelta * uX * uY  -  sinDelta * uZ;
00032   array[2] = oneMinusCosDelta * uX * uZ  +  sinDelta * uY;
00033 
00034   array[3] = oneMinusCosDelta * uY * uX  +  sinDelta * uZ;
00035   array[4] = oneMinusCosDelta * uY * uY  +  cosDelta;
00036   array[5] = oneMinusCosDelta * uY * uZ  -  sinDelta * uX;
00037 
00038   array[6] = oneMinusCosDelta * uZ * uX  -  sinDelta * uY;
00039   array[7] = oneMinusCosDelta * uZ * uY  +  sinDelta * uX;
00040   array[8] = oneMinusCosDelta * uZ * uZ  +  cosDelta;
00041 
00042 } // ZMpvAxisAngleRep
00043 
00044 
00045 double HepAxisAngle::distance( const AA & aa ) const  {
00046 
00047   double thisRep[9];
00048   double aaRep[9];
00049 
00050   ZMpvAxisAngleRep( *this, thisRep );
00051   ZMpvAxisAngleRep( aa,    aaRep );
00052 
00053   double sum = 0.0;
00054   for ( int i = 0; i < 9; i++ )  {
00055     sum += thisRep[i] * aaRep[i];
00056   }
00057 
00058   double d = 3.0 - sum;         // NaN-proofing: 
00059   return  (d >= 0) ? d : 0;             // std::sqrt(distance) is used in howNear()
00060 
00061 }  // HepAxisAngle::distance()
00062 
00063 
00064 bool HepAxisAngle::isNear( const AA & aa, Scalar epsilon ) const  {
00065 
00066   return  distance( aa ) <= epsilon * epsilon;
00067 
00068 }  // HepAxisAngle::isNear()
00069 
00070 
00071 double HepAxisAngle::howNear( const AA & aa ) const  {
00072 
00073   return  std::sqrt( distance( aa ) );
00074 
00075 }  // HepAxisAngle::howNear()
00076 
00077 
00078 //-********************
00079 //
00080 // Global methods
00081 //
00082 //-********************
00083 
00084 
00085 std::ostream & operator<<(std::ostream & os, const HepAxisAngle & aa) {
00086   os << '(' << aa.axis() << ", " << aa.delta() << ')';
00087   return  os;
00088 }  // operator<<()
00089 
00090 
00091 void ZMinputAxisAngle ( std::istream & is, 
00092                         double & x, double & y, double & z, 
00093                         double & delta );
00094 
00095 std::istream & operator>>(std::istream & is, HepAxisAngle & aa) {
00096   Hep3Vector axis;
00097   double delta;
00098   double x,y,z;
00099   ZMinputAxisAngle ( is, x, y, z, delta );
00100   axis.set(x,y,z);
00101   aa.set ( axis, delta );
00102   return  is;
00103 }  // operator>>()
00104 
00105 }  // namespace CLHEP

Generated on Mon May 27 17:47:34 2013 for Geant4 by  doxygen 1.4.7