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

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