CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
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 & aaxis, double ddelta ) { 00029 00030 register double sinDelta = std::sin(ddelta), cosDelta = std::cos(ddelta); 00031 register double oneMinusCosDelta = 1.0 - cosDelta; 00032 00033 Hep3Vector u = aaxis.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 & aaxis, double ddelta ) 00056 { 00057 set( aaxis, ddelta ); 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 std::acos( cosdelta ); // Already safe due to the cosdelta > 1 check 00078 } 00079 00080 } // delta() 00081 00082 Hep3Vector HepRotation::axis () const { 00083 00084 // Determine 2*std::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 & aaxis) { 00113 set ( aaxis, delta() ); 00114 } 00115 00116 void HepRotation::setDelta (double ddelta) { 00117 set ( axis(), ddelta ); 00118 } 00119 00120 } // namespace CLHEP