Geant4 Cross Reference |
1 // -*- C++ -*- 1 2 // ------------------------------------------- 3 // 4 // This file is a part of the CLHEP - a Class 5 // 6 // This is the implementation of methods of th 7 // were introduced when ZOOM PhysicsVectors wa 8 // 9 10 #include "CLHEP/Vector/RotationY.h" 11 #include "CLHEP/Vector/AxisAngle.h" 12 #include "CLHEP/Vector/EulerAngles.h" 13 #include "CLHEP/Vector/LorentzRotation.h" 14 #include "CLHEP/Units/PhysicalConstants.h" 15 16 #include <cmath> 17 #include <stdlib.h> 18 #include <iostream> 19 20 namespace CLHEP { 21 22 static inline double safe_acos (double x) { 23 if (std::abs(x) <= 1.0) return std::acos(x); 24 return ( (x>0) ? 0 : CLHEP::pi ); 25 } 26 27 HepRotationY::HepRotationY(double ddelta) : 28 its_d(proper(ddelta)), its_s(std::sin(ddel 29 {} 30 31 HepRotationY & HepRotationY::set ( double ddel 32 its_d = proper(ddelta); 33 its_s = std::sin(its_d); 34 its_c = std::cos(its_d); 35 return *this; 36 } 37 38 double HepRotationY::phi() const { 39 if ( its_d == 0 ) { 40 return 0; 41 } else if ( (its_d < 0) || (its_d == CLHEP:: 42 return +CLHEP::halfpi; 43 } else { 44 return -CLHEP::halfpi; 45 } 46 } // HepRotationY::phi() 47 48 double HepRotationY::theta() const { 49 return std::fabs( its_d ); 50 } // HepRotationY::theta() 51 52 double HepRotationY::psi() const { 53 if ( its_d == 0 ) { 54 return 0; 55 } else if ( (its_d < 0) || (its_d == CLHEP:: 56 return -CLHEP::halfpi; 57 } else { 58 return +CLHEP::halfpi; 59 } 60 } // HepRotationY::psi() 61 62 HepEulerAngles HepRotationY::eulerAngles() con 63 return HepEulerAngles( phi(), theta(), ps 64 } // HepRotationY::eulerAngles() 65 66 67 // From the defining code in the implementatio 68 // it is clear that thetaX, phiX form the pola 69 // coordinate system of the new X axis (and si 70 // 71 // This code is taken directly from the origin 72 // shown opportunities for significant speed i 73 74 double HepRotationY::phiX() const { 75 return (yx() == 0.0 && xx() == 0.0) ? 0.0 : 76 // or ---- return 0; 77 } 78 79 double HepRotationY::phiY() const { 80 return (yy() == 0.0 && xy() == 0.0) ? 0.0 : 81 // or ---- return CLHEP::halfpi; 82 } 83 84 double HepRotationY::phiZ() const { 85 return (yz() == 0.0 && xz() == 0.0) ? 0.0 : 86 // or ---- return 0; 87 } 88 89 double HepRotationY::thetaX() const { 90 return safe_acos(zx()); 91 } 92 93 double HepRotationY::thetaY() const { 94 return safe_acos(zy()); 95 // or ---- return CLHEP::halfpi; 96 } 97 98 double HepRotationY::thetaZ() const { 99 return safe_acos(zz()); 100 // or ---- return d; 101 } 102 103 void HepRotationY::setDelta ( double ddelta ) 104 set(ddelta); 105 } 106 107 void HepRotationY::decompose 108 (HepAxisAngle & rotation, Hep3Vector & boost 109 boost.set(0,0,0); 110 rotation = axisAngle(); 111 } 112 113 void HepRotationY::decompose 114 (Hep3Vector & boost, HepAxisAngle & rotation 115 boost.set(0,0,0); 116 rotation = axisAngle(); 117 } 118 119 void HepRotationY::decompose 120 (HepRotation & rotation, HepBoost & bo 121 boost.set(0,0,0); 122 rotation = HepRotation(*this); 123 } 124 125 void HepRotationY::decompose 126 (HepBoost & boost, HepRotation & rotat 127 boost.set(0,0,0); 128 rotation = HepRotation(*this); 129 } 130 131 double HepRotationY::distance2( const HepRotat 132 double answer = 2.0 * ( 1.0 - ( its_s * r.it 133 return (answer >= 0) ? answer : 0; 134 } 135 136 double HepRotationY::distance2( const HepRotat 137 double sum = xx() * r.xx() + 138 + r.yy() 139 + zx() * r.zx() 140 double answer = 3.0 - sum; 141 return (answer >= 0 ) ? answer : 0; 142 } 143 144 double HepRotationY::distance2( const HepLoren 145 HepAxisAngle a; 146 Hep3Vector b; 147 lt.decompose(b, a); 148 double bet = b.beta(); 149 double bet2 = bet*bet; 150 HepRotation r(a); 151 return bet2/(1-bet2) + distance2(r); 152 } 153 154 double HepRotationY::distance2( const HepBoost 155 return distance2( HepLorentzRotation(lt)); 156 } 157 158 double HepRotationY::howNear( const HepRotatio 159 return std::sqrt(distance2(r)); 160 } 161 double HepRotationY::howNear( const HepRotatio 162 return std::sqrt(distance2(r)); 163 } 164 double HepRotationY::howNear( const HepBoost & 165 return std::sqrt(distance2(lt)); 166 } 167 double HepRotationY::howNear( const HepLorentz 168 return std::sqrt(distance2(lt)); 169 } 170 bool HepRotationY::isNear(const HepRotationY & 171 return (distance2(r) <= epsilon*epsilon); 172 } 173 bool HepRotationY::isNear(const HepRotation & 174 return (distance2(r) <= epsilon*epsilon); 175 } 176 bool HepRotationY::isNear( const HepBoost & lt 177 return (distance2(lt) <= epsilon*epsilon); 178 } 179 bool HepRotationY::isNear( const HepLorentzRot 180 double ep 181 return (distance2(lt) <= epsilon*epsilon); 182 } 183 184 double HepRotationY::norm2() const { 185 return 2.0 - 2.0 * its_c; 186 } 187 188 std::ostream & HepRotationY::print( std::ostre 189 os << "\nRotation about Y (" << its_d << 190 ") [cos d = " << its_c << " si 191 return os; 192 } 193 194 } // namespace CLHEP 195