00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifdef GNUPRAGMA
00011 #pragma implementation
00012 #endif
00013
00014 #include "CLHEP/Vector/RotationZ.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 HepRotationZ::HepRotationZ(double ddelta) :
00032 its_d(proper(ddelta)), its_s(std::sin(ddelta)), its_c(std::cos(ddelta))
00033 {}
00034
00035 HepRotationZ & HepRotationZ::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 HepRotationZ::phi() const {
00043 return - its_d/2.0;
00044 }
00045
00046 double HepRotationZ::theta() const {
00047 return 0.0 ;
00048 }
00049
00050 double HepRotationZ::psi() const {
00051 return - its_d/2.0;
00052 }
00053
00054 HepEulerAngles HepRotationZ::eulerAngles() const {
00055 return HepEulerAngles( phi(), theta(), psi() );
00056 }
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 double HepRotationZ::phiX() const {
00067 return (yx() == 0.0 && xx() == 0.0) ? 0.0 : std::atan2(yx(),xx());
00068
00069 }
00070
00071 double HepRotationZ::phiY() const {
00072 return (yy() == 0.0 && xy() == 0.0) ? 0.0 : std::atan2(yy(),xy());
00073 }
00074
00075 double HepRotationZ::phiZ() const {
00076 return (yz() == 0.0 && xz() == 0.0) ? 0.0 : std::atan2(yz(),xz());
00077
00078 }
00079
00080 double HepRotationZ::thetaX() const {
00081 return safe_acos(zx());
00082
00083 }
00084
00085 double HepRotationZ::thetaY() const {
00086 return safe_acos(zy());
00087
00088 }
00089
00090 double HepRotationZ::thetaZ() const {
00091 return safe_acos(zz());
00092
00093 }
00094
00095 void HepRotationZ::setDelta ( double ddelta ) {
00096 set(ddelta);
00097 }
00098
00099 void HepRotationZ::decompose
00100 (HepAxisAngle & rotation, Hep3Vector & boost) const {
00101 boost.set(0,0,0);
00102 rotation = axisAngle();
00103 }
00104
00105 void HepRotationZ::decompose
00106 (Hep3Vector & boost, HepAxisAngle & rotation) const {
00107 boost.set(0,0,0);
00108 rotation = axisAngle();
00109 }
00110
00111 void HepRotationZ::decompose
00112 (HepRotation & rotation, HepBoost & boost) const {
00113 boost.set(0,0,0);
00114 rotation = HepRotation(*this);
00115 }
00116
00117 void HepRotationZ::decompose
00118 (HepBoost & boost, HepRotation & rotation) const {
00119 boost.set(0,0,0);
00120 rotation = HepRotation(*this);
00121 }
00122
00123 double HepRotationZ::distance2( const HepRotationZ & r ) const {
00124 double answer = 2.0 * ( 1.0 - ( its_s * r.its_s + its_c * r.its_c ) ) ;
00125 return (answer >= 0) ? answer : 0;
00126 }
00127
00128 double HepRotationZ::distance2( const HepRotation & r ) const {
00129 double sum = xx() * r.xx() + xy() * r.xy()
00130 + yx() * r.yx() + yy() * r.yy()
00131 + r.zz();
00132 double answer = 3.0 - sum;
00133 return (answer >= 0 ) ? answer : 0;
00134 }
00135
00136 double HepRotationZ::distance2( const HepLorentzRotation & lt ) const {
00137 HepAxisAngle a;
00138 Hep3Vector b;
00139 lt.decompose(b, a);
00140 double bet = b.beta();
00141 double bet2 = bet*bet;
00142 HepRotation r(a);
00143 return bet2/(1-bet2) + distance2(r);
00144 }
00145
00146 double HepRotationZ::distance2( const HepBoost & lt ) const {
00147 return distance2( HepLorentzRotation(lt));
00148 }
00149
00150 double HepRotationZ::howNear( const HepRotationZ & r ) const {
00151 return std::sqrt(distance2(r));
00152 }
00153 double HepRotationZ::howNear( const HepRotation & r ) const {
00154 return std::sqrt(distance2(r));
00155 }
00156 double HepRotationZ::howNear( const HepBoost & lt ) const {
00157 return std::sqrt(distance2(lt));
00158 }
00159 double HepRotationZ::howNear( const HepLorentzRotation & lt ) const {
00160 return std::sqrt(distance2(lt));
00161 }
00162 bool HepRotationZ::isNear(const HepRotationZ & r,double epsilon)const {
00163 return (distance2(r) <= epsilon*epsilon);
00164 }
00165 bool HepRotationZ::isNear(const HepRotation & r,double epsilon)const {
00166 return (distance2(r) <= epsilon*epsilon);
00167 }
00168 bool HepRotationZ::isNear( const HepBoost & lt,double epsilon) const {
00169 return (distance2(lt) <= epsilon*epsilon);
00170 }
00171 bool HepRotationZ::isNear( const HepLorentzRotation & lt,
00172 double epsilon) const {
00173 return (distance2(lt) <= epsilon*epsilon);
00174 }
00175
00176 double HepRotationZ::norm2() const {
00177 return 2.0 - 2.0 * its_c;
00178 }
00179
00180 std::ostream & HepRotationZ::print( std::ostream & os ) const {
00181 os << "\nRotation about Z (" << its_d <<
00182 ") [cos d = " << its_c << " sin d = " << its_s << "]\n";
00183 return os;
00184 }
00185
00186 }
00187