RotationX.cc

Go to the documentation of this file.
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 methods of the HepRotationX class which
00007 // were introduced when ZOOM PhysicsVectors was merged in.
00008 //
00009 
00010 #ifdef GNUPRAGMA
00011 #pragma implementation
00012 #endif
00013 
00014 #include "CLHEP/Vector/RotationX.h"
00015 #include "CLHEP/Vector/AxisAngle.h"
00016 #include "CLHEP/Vector/EulerAngles.h"
00017 #include "CLHEP/Vector/LorentzRotation.h"
00018 #include "CLHEP/Units/PhysicalConstants.h"
00019 
00020 #include <cmath>
00021 #include <stdlib.h>
00022 #include <iostream>
00023 
00024 namespace CLHEP  {
00025 
00026 static inline double safe_acos (double x) {
00027   if (std::abs(x) <= 1.0) return std::acos(x);
00028   return ( (x>0) ? 0 : CLHEP::pi );
00029 }
00030 
00031 HepRotationX::HepRotationX(double ddelta) : 
00032                 its_d(proper(ddelta)), its_s(std::sin(ddelta)), its_c(std::cos(ddelta))
00033 {}
00034 
00035 HepRotationX & HepRotationX::set ( double ddelta ) {
00036   its_d = proper(ddelta);
00037   its_s = std::sin(its_d);
00038   its_c = std::cos(its_d);
00039   return *this;
00040 }
00041 
00042 double  HepRotationX::phi() const {
00043   if ( (its_d > 0) && (its_d < CLHEP::pi) ) {
00044     return CLHEP::pi;
00045   } else {
00046     return 0.0;
00047   }
00048 }  // HepRotationX::phi()
00049 
00050 double  HepRotationX::theta() const {
00051   return  std::fabs( its_d );
00052 }  // HepRotationX::theta()
00053 
00054 double  HepRotationX::psi() const {
00055   if ( (its_d > 0) && (its_d < CLHEP::pi) ) {
00056     return CLHEP::pi;
00057   } else {
00058     return 0.0;
00059   }
00060 }  // HepRotationX::psi()
00061 
00062 HepEulerAngles HepRotationX::eulerAngles() const {
00063   return HepEulerAngles(  phi(), theta(),  psi() );
00064 }  // HepRotationX::eulerAngles()
00065 
00066 
00067 // From the defining code in the implementation of CLHEP (in Rotation.cc)
00068 // it is clear that thetaX, phiX form the polar angles in the original
00069 // coordinate system of the new X axis (and similarly for phiY and phiZ).
00070 //
00071 // This code is taken directly from the original CLHEP. However, there are as
00072 // shown opportunities for significant speed improvement.
00073 
00074 double HepRotationX::phiX() const {
00075   return (yx() == 0.0 && xx() == 0.0) ? 0.0 : std::atan2(yx(),xx());
00076                 // or ---- return 0;
00077 }
00078 
00079 double HepRotationX::phiY() const {
00080   return (yy() == 0.0 && xy() == 0.0) ? 0.0 : std::atan2(yy(),xy());
00081                 // or ----  return (yy() == 0.0) ? 0.0 : std::atan2(yy(),xy());
00082 }
00083 
00084 double HepRotationX::phiZ() const {
00085   return (yz() == 0.0 && xz() == 0.0) ? 0.0 : std::atan2(yz(),xz());
00086                 // or ----  return (yz() == 0.0) ? 0.0 : std::atan2(yz(),xz());
00087 }
00088 
00089 double HepRotationX::thetaX() const {
00090   return safe_acos(zx());
00091                 // or ----  return CLHEP::halfpi;
00092 }
00093 
00094 double HepRotationX::thetaY() const {
00095   return safe_acos(zy());
00096 }
00097 
00098 double HepRotationX::thetaZ() const {
00099   return safe_acos(zz());  
00100                 // or ---- return d;
00101 }
00102 
00103 void HepRotationX::setDelta ( double ddelta ) {
00104   set(ddelta);
00105 }
00106 
00107 void HepRotationX::decompose
00108         (HepAxisAngle & rotation, Hep3Vector & boost) const {
00109   boost.set(0,0,0);
00110   rotation = axisAngle();
00111 }
00112 
00113 void HepRotationX::decompose
00114         (Hep3Vector & boost, HepAxisAngle & rotation) const {
00115   boost.set(0,0,0);
00116   rotation = axisAngle();
00117 }
00118 
00119 void HepRotationX::decompose
00120         (HepRotation & rotation, HepBoost & boost) const {
00121   boost.set(0,0,0);
00122   rotation = HepRotation(*this);
00123 } 
00124 
00125 void HepRotationX::decompose
00126         (HepBoost & boost, HepRotation & rotation) const {
00127   boost.set(0,0,0);
00128   rotation = HepRotation(*this);
00129 }
00130 
00131 double HepRotationX::distance2( const HepRotationX & r  ) const {
00132   double answer = 2.0 * ( 1.0 - ( its_s * r.its_s + its_c * r.its_c ) ) ;
00133   return (answer >= 0) ? answer : 0;
00134 }
00135 
00136 double HepRotationX::distance2( const HepRotation & r  ) const {
00137   double sum =        r.xx() + 
00138                                   yy() * r.yy() + yz() * r.yz()
00139                                 + zy() * r.zy() + zz() * r.zz();
00140   double answer = 3.0 - sum;
00141   return (answer >= 0 ) ? answer : 0;
00142 }
00143 
00144 double HepRotationX::distance2( const HepLorentzRotation & lt  ) const {
00145   HepAxisAngle a; 
00146   Hep3Vector   b;
00147   lt.decompose(b, a);
00148   double bet = b.beta();
00149   double bet2 = bet*bet;
00150   HepRotation r(a);
00151   return bet2/(1-bet2) + distance2(r);
00152 }
00153 
00154 double HepRotationX::distance2( const HepBoost & lt ) const {
00155   return distance2( HepLorentzRotation(lt));
00156 }
00157 
00158 double HepRotationX::howNear( const HepRotationX & r ) const {
00159   return std::sqrt(distance2(r));
00160 }
00161 double HepRotationX::howNear( const HepRotation & r ) const {
00162   return std::sqrt(distance2(r));
00163 }
00164 double HepRotationX::howNear( const HepBoost & b ) const {
00165   return std::sqrt(distance2(b));
00166 }
00167 double HepRotationX::howNear( const HepLorentzRotation & lt ) const {
00168   return std::sqrt(distance2(lt));
00169 }
00170 bool HepRotationX::isNear(const HepRotationX & r,double epsilon)const{
00171   return (distance2(r) <= epsilon*epsilon);
00172 }
00173 bool HepRotationX::isNear(const HepRotation & r,double epsilon) const{
00174   return (distance2(r) <= epsilon*epsilon);
00175 }
00176 bool HepRotationX::isNear( const HepBoost & lt,double epsilon) const {
00177   return (distance2(lt) <= epsilon*epsilon);
00178 }
00179 
00180 bool HepRotationX::isNear( const HepLorentzRotation & lt,
00181                                      double epsilon ) const {
00182   return (distance2(lt) <= epsilon*epsilon);
00183 }
00184 
00185 double HepRotationX::norm2() const {
00186   return 2.0 - 2.0 * its_c;
00187 }
00188 
00189 std::ostream & HepRotationX::print( std::ostream & os ) const {
00190   os << "\nRotation about X (" << its_d << 
00191                 ") [cos d = " << its_c << " sin d = " << its_s << "]\n";
00192   return os;
00193 }
00194 
00195 }  // namespace CLHEP
00196 

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