Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
RotationX.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 HepRotationX class which
7// were introduced when ZOOM PhysicsVectors was merged in.
8//
9
10#ifdef GNUPRAGMA
11#pragma implementation
12#endif
13
19
20#include <cmath>
21#include <stdlib.h>
22#include <iostream>
23
24namespace CLHEP {
25
26static 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
32 its_d(proper(ddelta)), its_s(std::sin(ddelta)), its_c(std::cos(ddelta))
33{}
34
35HepRotationX & HepRotationX::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
42double HepRotationX::phi() const {
43 if ( (its_d > 0) && (its_d < CLHEP::pi) ) {
44 return CLHEP::pi;
45 } else {
46 return 0.0;
47 }
48} // HepRotationX::phi()
49
50double HepRotationX::theta() const {
51 return std::fabs( its_d );
52} // HepRotationX::theta()
53
54double HepRotationX::psi() const {
55 if ( (its_d > 0) && (its_d < CLHEP::pi) ) {
56 return CLHEP::pi;
57 } else {
58 return 0.0;
59 }
60} // HepRotationX::psi()
61
63 return HepEulerAngles( phi(), theta(), psi() );
64} // HepRotationX::eulerAngles()
65
66
67// From the defining code in the implementation of CLHEP (in Rotation.cc)
68// it is clear that thetaX, phiX form the polar angles in the original
69// coordinate system of the new X axis (and similarly for phiY and phiZ).
70//
71// This code is taken directly from the original CLHEP. However, there are as
72// shown opportunities for significant speed improvement.
73
74double HepRotationX::phiX() const {
75 return (yx() == 0.0 && xx() == 0.0) ? 0.0 : std::atan2(yx(),xx());
76 // or ---- return 0;
77}
78
79double HepRotationX::phiY() const {
80 return (yy() == 0.0 && xy() == 0.0) ? 0.0 : std::atan2(yy(),xy());
81 // or ---- return (yy() == 0.0) ? 0.0 : std::atan2(yy(),xy());
82}
83
84double HepRotationX::phiZ() const {
85 return (yz() == 0.0 && xz() == 0.0) ? 0.0 : std::atan2(yz(),xz());
86 // or ---- return (yz() == 0.0) ? 0.0 : std::atan2(yz(),xz());
87}
88
89double HepRotationX::thetaX() const {
90 return safe_acos(zx());
91 // or ---- return CLHEP::halfpi;
92}
93
94double HepRotationX::thetaY() const {
95 return safe_acos(zy());
96}
97
98double HepRotationX::thetaZ() const {
99 return safe_acos(zz());
100 // or ---- return d;
101}
102
103void HepRotationX::setDelta ( double ddelta ) {
104 set(ddelta);
105}
106
108 (HepAxisAngle & rotation, Hep3Vector & boost) const {
109 boost.set(0,0,0);
110 rotation = axisAngle();
111}
112
114 (Hep3Vector & boost, HepAxisAngle & rotation) const {
115 boost.set(0,0,0);
116 rotation = axisAngle();
117}
118
120 (HepRotation & rotation, HepBoost & boost) const {
121 boost.set(0,0,0);
122 rotation = HepRotation(*this);
123}
124
126 (HepBoost & boost, HepRotation & rotation) const {
127 boost.set(0,0,0);
128 rotation = HepRotation(*this);
129}
130
131double HepRotationX::distance2( const HepRotationX & r ) const {
132 double answer = 2.0 * ( 1.0 - ( its_s * r.its_s + its_c * r.its_c ) ) ;
133 return (answer >= 0) ? answer : 0;
134}
135
136double HepRotationX::distance2( const HepRotation & r ) const {
137 double sum = r.xx() +
138 yy() * r.yy() + yz() * r.yz()
139 + zy() * r.zy() + zz() * r.zz();
140 double answer = 3.0 - sum;
141 return (answer >= 0 ) ? answer : 0;
142}
143
144double HepRotationX::distance2( const HepLorentzRotation & lt ) const {
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
154double HepRotationX::distance2( const HepBoost & lt ) const {
155 return distance2( HepLorentzRotation(lt));
156}
157
158double HepRotationX::howNear( const HepRotationX & r ) const {
159 return std::sqrt(distance2(r));
160}
161double HepRotationX::howNear( const HepRotation & r ) const {
162 return std::sqrt(distance2(r));
163}
164double HepRotationX::howNear( const HepBoost & b ) const {
165 return std::sqrt(distance2(b));
166}
167double HepRotationX::howNear( const HepLorentzRotation & lt ) const {
168 return std::sqrt(distance2(lt));
169}
170bool HepRotationX::isNear(const HepRotationX & r,double epsilon)const{
171 return (distance2(r) <= epsilon*epsilon);
172}
173bool HepRotationX::isNear(const HepRotation & r,double epsilon) const{
174 return (distance2(r) <= epsilon*epsilon);
175}
176bool HepRotationX::isNear( const HepBoost & lt,double epsilon) const {
177 return (distance2(lt) <= epsilon*epsilon);
178}
179
181 double epsilon ) const {
182 return (distance2(lt) <= epsilon*epsilon);
183}
184
185double HepRotationX::norm2() const {
186 return 2.0 - 2.0 * its_c;
187}
188
189std::ostream & HepRotationX::print( std::ostream & os ) const {
190 os << "\nRotation about X (" << its_d <<
191 ") [cos d = " << its_c << " sin d = " << its_s << "]\n";
192 return os;
193}
194
195} // namespace CLHEP
196
double beta() const
Definition: SpaceVectorP.cc:30
void set(double x, double y, double z)
HepBoost & set(double betaX, double betaY, double betaZ)
Definition: Boost.cc:21
void decompose(Hep3Vector &boost, HepAxisAngle &rotation) const
double phiX() const
Definition: RotationX.cc:74
double xy() const
double thetaZ() const
Definition: RotationX.cc:98
double xx() const
double phiY() const
Definition: RotationX.cc:79
double yz() const
static double proper(double delta)
double zy() const
HepRotationX & set(double delta)
Definition: RotationX.cc:35
HepEulerAngles eulerAngles() const
Definition: RotationX.cc:62
double psi() const
Definition: RotationX.cc:54
double howNear(const HepRotationX &r) const
Definition: RotationX.cc:158
void setDelta(double delta)
Definition: RotationX.cc:103
double yy() const
double phi() const
Definition: RotationX.cc:42
double thetaY() const
Definition: RotationX.cc:94
double xz() const
double phiZ() const
Definition: RotationX.cc:84
double thetaX() const
Definition: RotationX.cc:89
void decompose(HepAxisAngle &rotation, Hep3Vector &boost) const
Definition: RotationX.cc:108
HepAxisAngle axisAngle() const
std::ostream & print(std::ostream &os) const
Definition: RotationX.cc:189
bool isNear(const HepRotationX &r, double epsilon=Hep4RotationInterface::tolerance) const
Definition: RotationX.cc:170
double theta() const
Definition: RotationX.cc:50
double zz() const
double distance2(const HepRotationX &r) const
Definition: RotationX.cc:131
double norm2() const
Definition: RotationX.cc:185
double yx() const
double zx() const
double zz() const
double yz() const
double zy() const
double xx() const
double yy() const
Definition: DoubConv.h:17