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

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

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