Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RotationY.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // ---------------------------------------------------------------------------
3 //
4 // This file is a part of the CLHEP - a Class Library for High Energy Physics.
5 //
6 // This is the implementation of methods of the HepRotationY class which
7 // were introduced when ZOOM PhysicsVectors was merged in.
8 //
9 
10 #ifdef GNUPRAGMA
11 #pragma implementation
12 #endif
13 
14 #include "CLHEP/Vector/RotationY.h"
15 #include "CLHEP/Vector/AxisAngle.h"
19 
20 #include <cmath>
21 #include <stdlib.h>
22 #include <iostream>
23 
24 namespace CLHEP {
25 
26 static inline double safe_acos (double x) {
27  if (std::abs(x) <= 1.0) return std::acos(x);
28  return ( (x>0) ? 0 : CLHEP::pi );
29 }
30 
31 HepRotationY::HepRotationY(double ddelta) :
32  its_d(proper(ddelta)), its_s(std::sin(ddelta)), its_c(std::cos(ddelta))
33 {}
34 
35 HepRotationY & HepRotationY::set ( double ddelta ) {
36  its_d = proper(ddelta);
37  its_s = std::sin(its_d);
38  its_c = std::cos(its_d);
39  return *this;
40 }
41 
42 double HepRotationY::phi() const {
43  if ( its_d == 0 ) {
44  return 0;
45  } else if ( (its_d < 0) || (its_d == CLHEP::pi) ) {
46  return +CLHEP::halfpi;
47  } else {
48  return -CLHEP::halfpi;
49  }
50 } // HepRotationY::phi()
51 
52 double HepRotationY::theta() const {
53  return std::fabs( its_d );
54 } // HepRotationY::theta()
55 
56 double HepRotationY::psi() const {
57  if ( its_d == 0 ) {
58  return 0;
59  } else if ( (its_d < 0) || (its_d == CLHEP::pi) ) {
60  return -CLHEP::halfpi;
61  } else {
62  return +CLHEP::halfpi;
63  }
64 } // HepRotationY::psi()
65 
67  return HepEulerAngles( phi(), theta(), psi() );
68 } // HepRotationY::eulerAngles()
69 
70 
71 // From the defining code in the implementation of CLHEP (in Rotation.cc)
72 // it is clear that thetaX, phiX form the polar angles in the original
73 // coordinate system of the new X axis (and similarly for phiY and phiZ).
74 //
75 // This code is taken directly from the original CLHEP. However, there are as
76 // shown opportunities for significant speed improvement.
77 
78 double HepRotationY::phiX() const {
79  return (yx() == 0.0 && xx() == 0.0) ? 0.0 : std::atan2(yx(),xx());
80  // or ---- return 0;
81 }
82 
83 double HepRotationY::phiY() const {
84  return (yy() == 0.0 && xy() == 0.0) ? 0.0 : std::atan2(yy(),xy());
85  // or ---- return CLHEP::halfpi;
86 }
87 
88 double HepRotationY::phiZ() const {
89  return (yz() == 0.0 && xz() == 0.0) ? 0.0 : std::atan2(yz(),xz());
90  // or ---- return 0;
91 }
92 
93 double HepRotationY::thetaX() const {
94  return safe_acos(zx());
95 }
96 
97 double HepRotationY::thetaY() const {
98  return safe_acos(zy());
99  // or ---- return CLHEP::halfpi;
100 }
101 
102 double HepRotationY::thetaZ() const {
103  return safe_acos(zz());
104  // or ---- return d;
105 }
106 
107 void HepRotationY::setDelta ( double ddelta ) {
108  set(ddelta);
109 }
110 
112  (HepAxisAngle & rotation, Hep3Vector & boost) const {
113  boost.set(0,0,0);
114  rotation = axisAngle();
115 }
116 
118  (Hep3Vector & boost, HepAxisAngle & rotation) const {
119  boost.set(0,0,0);
120  rotation = axisAngle();
121 }
122 
124  (HepRotation & rotation, HepBoost & boost) const {
125  boost.set(0,0,0);
126  rotation = HepRotation(*this);
127 }
128 
130  (HepBoost & boost, HepRotation & rotation) const {
131  boost.set(0,0,0);
132  rotation = HepRotation(*this);
133 }
134 
135 double HepRotationY::distance2( const HepRotationY & r ) const {
136  double answer = 2.0 * ( 1.0 - ( its_s * r.its_s + its_c * r.its_c ) ) ;
137  return (answer >= 0) ? answer : 0;
138 }
139 
140 double HepRotationY::distance2( const HepRotation & r ) const {
141  double sum = xx() * r.xx() + xz() * r.xz()
142  + r.yy()
143  + zx() * r.zx() + zz() * r.zz();
144  double answer = 3.0 - sum;
145  return (answer >= 0 ) ? answer : 0;
146 }
147 
148 double HepRotationY::distance2( const HepLorentzRotation & lt ) const {
149  HepAxisAngle a;
150  Hep3Vector b;
151  lt.decompose(b, a);
152  double bet = b.beta();
153  double bet2 = bet*bet;
154  HepRotation r(a);
155  return bet2/(1-bet2) + distance2(r);
156 }
157 
158 double HepRotationY::distance2( const HepBoost & lt ) const {
159  return distance2( HepLorentzRotation(lt));
160 }
161 
162 double HepRotationY::howNear( const HepRotationY & r ) const {
163  return std::sqrt(distance2(r));
164 }
165 double HepRotationY::howNear( const HepRotation & r ) const {
166  return std::sqrt(distance2(r));
167 }
168 double HepRotationY::howNear( const HepBoost & lt ) const {
169  return std::sqrt(distance2(lt));
170 }
171 double HepRotationY::howNear( const HepLorentzRotation & lt ) const {
172  return std::sqrt(distance2(lt));
173 }
174 bool HepRotationY::isNear(const HepRotationY & r,double epsilon)const{
175  return (distance2(r) <= epsilon*epsilon);
176 }
177 bool HepRotationY::isNear(const HepRotation & r,double epsilon)const {
178  return (distance2(r) <= epsilon*epsilon);
179 }
180 bool HepRotationY::isNear( const HepBoost & lt,double epsilon) const {
181  return (distance2(lt) <= epsilon*epsilon);
182 }
184  double epsilon) const {
185  return (distance2(lt) <= epsilon*epsilon);
186 }
187 
188 double HepRotationY::norm2() const {
189  return 2.0 - 2.0 * its_c;
190 }
191 
192 std::ostream & HepRotationY::print( std::ostream & os ) const {
193  os << "\nRotation about Y (" << its_d <<
194  ") [cos d = " << its_c << " sin d = " << its_s << "]\n";
195  return os;
196 }
197 
198 } // namespace CLHEP
void set(double x, double y, double z)
double phi() const
Definition: RotationY.cc:42
double xx() const
double phiX() const
Definition: RotationY.cc:78
double howNear(const HepRotationY &r) const
Definition: RotationY.cc:162
double yy() const
double xy() const
double xx() const
double yy() const
double phiY() const
Definition: RotationY.cc:83
double xz() const
double psi() const
Definition: RotationY.cc:56
double thetaX() const
Definition: RotationY.cc:93
double zx() const
double norm2() const
Definition: RotationY.cc:188
double distance2(const HepRotationY &r) const
Definition: RotationY.cc:135
double xz() const
double yx() const
std::ostream & print(std::ostream &os) const
Definition: RotationY.cc:192
void decompose(HepAxisAngle &rotation, Hep3Vector &boost) const
Definition: RotationY.cc:112
static double proper(double delta)
double phiZ() const
Definition: RotationY.cc:88
double theta() const
Definition: RotationY.cc:52
double zy() const
void setDelta(double delta)
Definition: RotationY.cc:107
double beta() const
Definition: SpaceVectorP.cc:30
HepRotationY & set(double delta)
Definition: RotationY.cc:35
double zx() const
double thetaY() const
Definition: RotationY.cc:97
HepBoost & set(double betaX, double betaY, double betaZ)
Definition: Boost.cc:21
void decompose(Hep3Vector &boost, HepAxisAngle &rotation) const
bool isNear(const HepRotationY &r, double epsilon=Hep4RotationInterface::tolerance) const
Definition: RotationY.cc:174
double zz() const
HepEulerAngles eulerAngles() const
Definition: RotationY.cc:66
double yz() const
double zz() const
double thetaZ() const
Definition: RotationY.cc:102