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

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/defs.h"
00025 #include "CLHEP/Vector/EulerAngles.h"
00026 
00027 #include "CLHEP/Vector/ThreeVector.h"
00028 
00029 #include <iostream>
00030 
00031 namespace CLHEP  {
00032 
00033 //-*************
00034 // static consts
00035 //-*************
00036 
00037 double HepEulerAngles::tolerance = Hep3Vector::ToleranceTicks * 1.0e-8;
00038 
00039 //-*******************
00040 // measure of distance
00041 //-*******************
00042 
00043 
00044 static void ZMpvEulerAnglesRep ( const HepEulerAngles & ex, double array[] ) {
00045 
00046   register double sinPhi   = sin( ex.phi() )  , cosPhi   = cos( ex.phi() );
00047   register double sinTheta = sin( ex.theta() ), cosTheta = cos( ex.theta() );
00048   register double sinPsi   = sin( ex.psi() )  , cosPsi   = cos( ex.psi() );
00049 
00050   array[0] =   cosPsi * cosPhi   - sinPsi * cosTheta * sinPhi;
00051   array[1] =   cosPsi * sinPhi   + sinPsi * cosTheta * cosPhi;
00052   array[2] =   sinPsi * sinTheta;
00053 
00054   array[3] = - sinPsi * cosPhi - cosPsi * cosTheta * sinPhi;
00055   array[4] = - sinPsi * sinPhi   + cosPsi * cosTheta * cosPhi;
00056   array[5] =   cosPsi * sinTheta;
00057 
00058   array[6] =   sinTheta * sinPhi;
00059   array[7] = - sinTheta * cosPhi;
00060   array[8] =   cosTheta;
00061 
00062 } // ZMpvEulerAnglesRep
00063 
00064 
00065 double HepEulerAngles::distance( const EA & ex ) const  {
00066 
00067   double thisRep[9];
00068   double exRep[9];
00069 
00070   ZMpvEulerAnglesRep ( *this, thisRep );
00071   ZMpvEulerAnglesRep ( ex,    exRep );
00072 
00073   double sum = 0.0;
00074   for (int i = 0; i < 9; i++)  {
00075     sum += thisRep[i] * exRep[i];
00076   }
00077 
00078   double d = 3.0 - sum;         // NaN-proofing: 
00079   return  (d >= 0) ? d : 0;             // sqrt(distance) is used in howNear()
00080 
00081 }  // HepEulerAngles::distance()
00082 
00083 
00084 bool HepEulerAngles::isNear( const EA & ex, double epsilon ) const  {
00085 
00086   return  distance( ex ) <= epsilon*epsilon ;
00087 
00088 }  // HepEulerAngles::isNear()
00089 
00090 
00091 double HepEulerAngles::howNear( const EA & ex ) const  {
00092 
00093   return  sqrt( distance( ex ) );
00094 
00095 }  // HepEulerAngles::howNear()
00096 
00097 //-**************
00098 // Global Methods
00099 //-**************
00100 
00101 std::ostream & operator<<(std::ostream & os, const HepEulerAngles & ea)
00102 {
00103   os << "(" << ea.phi() << ", " << ea.theta() << ", " << ea.psi() << ")";
00104   return  os;
00105 }  // operator<<()
00106 
00107 void ZMinput3doubles ( std::istream & is, const char * type,
00108                        double & x, double & y, double & z );
00109 
00110 std::istream & operator>>(std::istream & is, HepEulerAngles & ea) {
00111   double thePhi;
00112   double theTheta;
00113   double thePsi;
00114   ZMinput3doubles ( is, "HepEulerAngle", thePhi , theTheta , thePsi );
00115   ea.set ( thePhi , theTheta , thePsi );
00116   return  is;
00117 }  // operator>>()
00118 
00119 }  // namespace CLHEP
00120 
00121 

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