EulerAngles.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------
00002 //
00003 // EulerAngles.cc
00004 //
00005 // Methods for classes, and instances of globals, declared in EulerAngles.h
00006 //
00007 // History:
00008 //
00009 // 04-Dec-1997  MF      Stub with just PI
00010 // 12-Jan-1998  WEB     PI now found in ZMutility; used ZMutility headers
00011 //                      where available
00012 // 16-Mar-1998  WEB     Corrected ZMpvEulerAnglesRep
00013 // 15-Jun-1998  WEB     Added namespace support
00014 // 26-Jul-2000  MF      CLHEP version
00015 // 12-Apr-2001  MF      NaN-proofing
00016 // 19-Nov-2001  MF      Correction to ZMpvEulerAnglesRep, which was affecting
00017 //                      .isNear().  array[3] had been incorrect.
00018 //                      Note - the correct form was used in all other places 
00019 //                      including Rotation.set(phi, theta, psi).
00020 //
00021 // ----------------------------------------------------------------------
00022 
00023 
00024 #include "CLHEP/Vector/EulerAngles.h"
00025 
00026 #include "CLHEP/Vector/ThreeVector.h"
00027 
00028 #include <iostream>
00029 
00030 namespace CLHEP  {
00031 
00032 //-*************
00033 // static consts
00034 //-*************
00035 
00036 double HepEulerAngles::tolerance = Hep3Vector::ToleranceTicks * 1.0e-8;
00037 
00038 //-*******************
00039 // measure of distance
00040 //-*******************
00041 
00042 
00043 static void ZMpvEulerAnglesRep ( const HepEulerAngles & ex, double array[] ) {
00044 
00045   register double sinPhi   = std::sin( ex.phi() )  , cosPhi   = std::cos( ex.phi() );
00046   register double sinTheta = std::sin( ex.theta() ), cosTheta = std::cos( ex.theta() );
00047   register double sinPsi   = std::sin( ex.psi() )  , cosPsi   = std::cos( ex.psi() );
00048 
00049   array[0] =   cosPsi * cosPhi   - sinPsi * cosTheta * sinPhi;
00050   array[1] =   cosPsi * sinPhi   + sinPsi * cosTheta * cosPhi;
00051   array[2] =   sinPsi * sinTheta;
00052 
00053   array[3] = - sinPsi * cosPhi - cosPsi * cosTheta * sinPhi;
00054   array[4] = - sinPsi * sinPhi   + cosPsi * cosTheta * cosPhi;
00055   array[5] =   cosPsi * sinTheta;
00056 
00057   array[6] =   sinTheta * sinPhi;
00058   array[7] = - sinTheta * cosPhi;
00059   array[8] =   cosTheta;
00060 
00061 } // ZMpvEulerAnglesRep
00062 
00063 
00064 double HepEulerAngles::distance( const EA & ex ) const  {
00065 
00066   double thisRep[9];
00067   double exRep[9];
00068 
00069   ZMpvEulerAnglesRep ( *this, thisRep );
00070   ZMpvEulerAnglesRep ( ex,    exRep );
00071 
00072   double sum = 0.0;
00073   for (int i = 0; i < 9; i++)  {
00074     sum += thisRep[i] * exRep[i];
00075   }
00076 
00077   double d = 3.0 - sum;         // NaN-proofing: 
00078   return  (d >= 0) ? d : 0;             // sqrt(distance) is used in howNear()
00079 
00080 }  // HepEulerAngles::distance()
00081 
00082 
00083 bool HepEulerAngles::isNear( const EA & ex, double epsilon ) const  {
00084 
00085   return  distance( ex ) <= epsilon*epsilon ;
00086 
00087 }  // HepEulerAngles::isNear()
00088 
00089 
00090 double HepEulerAngles::howNear( const EA & ex ) const  {
00091 
00092   return  std::sqrt( distance( ex ) );
00093 
00094 }  // HepEulerAngles::howNear()
00095 
00096 //-**************
00097 // Global Methods
00098 //-**************
00099 
00100 std::ostream & operator<<(std::ostream & os, const HepEulerAngles & ea)
00101 {
00102   os << "(" << ea.phi() << ", " << ea.theta() << ", " << ea.psi() << ")";
00103   return  os;
00104 }  // operator<<()
00105 
00106 void ZMinput3doubles ( std::istream & is, const char * type,
00107                        double & x, double & y, double & z );
00108 
00109 std::istream & operator>>(std::istream & is, HepEulerAngles & ea) {
00110   double thePhi;
00111   double theTheta;
00112   double thePsi;
00113   ZMinput3doubles ( is, "HepEulerAngle", thePhi , theTheta , thePsi );
00114   ea.set ( thePhi , theTheta , thePsi );
00115   return  is;
00116 }  // operator>>()
00117 
00118 }  // namespace CLHEP
00119 
00120 

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