Geant4 Cross Reference |
1 // ------------------------------------------- 1 2 // 3 // EulerAngles.cc 4 // 5 // Methods for classes, and instances of globa 6 // 7 // History: 8 // 9 // 04-Dec-1997 MF Stub with just PI 10 // 12-Jan-1998 WEB PI now found in ZMutility; 11 // where available 12 // 16-Mar-1998 WEB Corrected ZMpvEulerAnglesR 13 // 15-Jun-1998 WEB Added namespace support 14 // 26-Jul-2000 MF CLHEP version 15 // 12-Apr-2001 MF NaN-proofing 16 // 19-Nov-2001 MF Correction to ZMpvEulerA 17 // .isNear(). array[3] had been incorrec 18 // Note - the correct form was used in al 19 // including Rotation.set(phi, theta, psi 20 // 21 // ------------------------------------------- 22 23 24 #include "CLHEP/Vector/EulerAngles.h" 25 26 #include "CLHEP/Vector/ThreeVector.h" 27 28 #include <cmath> 29 #include <iostream> 30 31 namespace CLHEP { 32 33 //-************* 34 // static consts 35 //-************* 36 37 double HepEulerAngles::tolerance = Hep3Vector: 38 39 //-******************* 40 // measure of distance 41 //-******************* 42 43 44 static void ZMpvEulerAnglesRep ( const HepEule 45 46 double sinPhi = std::sin( ex.phi() ) , co 47 double sinTheta = std::sin( ex.theta() ), co 48 double sinPsi = std::sin( ex.psi() ) , co 49 50 array[0] = cosPsi * cosPhi - sinPsi * co 51 array[1] = cosPsi * sinPhi + sinPsi * co 52 array[2] = sinPsi * sinTheta; 53 54 array[3] = - sinPsi * cosPhi - cosPsi * cosT 55 array[4] = - sinPsi * sinPhi + cosPsi * co 56 array[5] = cosPsi * sinTheta; 57 58 array[6] = sinTheta * sinPhi; 59 array[7] = - sinTheta * cosPhi; 60 array[8] = cosTheta; 61 62 } // ZMpvEulerAnglesRep 63 64 65 double HepEulerAngles::distance( const EA & ex 66 67 double thisRep[9]; 68 double exRep[9]; 69 70 ZMpvEulerAnglesRep ( *this, thisRep ); 71 ZMpvEulerAnglesRep ( ex, exRep ); 72 73 double sum = 0.0; 74 for (int i = 0; i < 9; i++) { 75 sum += thisRep[i] * exRep[i]; 76 } 77 78 double d = 3.0 - sum; // NaN-proofing: 79 return (d >= 0) ? d : 0; // sqrt(distance 80 81 } // HepEulerAngles::distance() 82 83 84 bool HepEulerAngles::isNear( const EA & ex, do 85 86 return distance( ex ) <= epsilon*epsilon ; 87 88 } // HepEulerAngles::isNear() 89 90 91 double HepEulerAngles::howNear( const EA & ex 92 93 return std::sqrt( distance( ex ) ); 94 95 } // HepEulerAngles::howNear() 96 97 //-************** 98 // Global Methods 99 //-************** 100 101 std::ostream & operator<<(std::ostream & os, c 102 { 103 os << "(" << ea.phi() << ", " << ea.theta() 104 return os; 105 } // operator<<() 106 107 void ZMinput3doubles ( std::istream & is, cons 108 double & x, double & y, 109 110 std::istream & operator>>(std::istream & is, H 111 double thePhi; 112 double theTheta; 113 double thePsi; 114 ZMinput3doubles ( is, "HepEulerAngle", thePh 115 ea.set ( thePhi , theTheta , thePsi ); 116 return is; 117 } // operator>>() 118 119 } // namespace CLHEP 120 121 122