Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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
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
35HepRotationY & 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
42double 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
52double HepRotationY::theta() const {
53 return std::fabs( its_d );
54} // HepRotationY::theta()
55
56double 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
78double HepRotationY::phiX() const {
79 return (yx() == 0.0 && xx() == 0.0) ? 0.0 : std::atan2(yx(),xx());
80 // or ---- return 0;
81}
82
83double HepRotationY::phiY() const {
84 return (yy() == 0.0 && xy() == 0.0) ? 0.0 : std::atan2(yy(),xy());
85 // or ---- return CLHEP::halfpi;
86}
87
88double HepRotationY::phiZ() const {
89 return (yz() == 0.0 && xz() == 0.0) ? 0.0 : std::atan2(yz(),xz());
90 // or ---- return 0;
91}
92
93double HepRotationY::thetaX() const {
94 return safe_acos(zx());
95}
96
97double HepRotationY::thetaY() const {
98 return safe_acos(zy());
99 // or ---- return CLHEP::halfpi;
100}
101
102double HepRotationY::thetaZ() const {
103 return safe_acos(zz());
104 // or ---- return d;
105}
106
107void 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
135double 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
140double 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
148double 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
158double HepRotationY::distance2( const HepBoost & lt ) const {
159 return distance2( HepLorentzRotation(lt));
160}
161
162double HepRotationY::howNear( const HepRotationY & r ) const {
163 return std::sqrt(distance2(r));
164}
165double HepRotationY::howNear( const HepRotation & r ) const {
166 return std::sqrt(distance2(r));
167}
168double HepRotationY::howNear( const HepBoost & lt ) const {
169 return std::sqrt(distance2(lt));
170}
171double HepRotationY::howNear( const HepLorentzRotation & lt ) const {
172 return std::sqrt(distance2(lt));
173}
174bool HepRotationY::isNear(const HepRotationY & r,double epsilon)const{
175 return (distance2(r) <= epsilon*epsilon);
176}
177bool HepRotationY::isNear(const HepRotation & r,double epsilon)const {
178 return (distance2(r) <= epsilon*epsilon);
179}
180bool 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
188double HepRotationY::norm2() const {
189 return 2.0 - 2.0 * its_c;
190}
191
192std::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
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
void setDelta(double delta)
Definition: RotationY.cc:107
static double proper(double delta)
double phiZ() const
Definition: RotationY.cc:88
double zz() const
double yz() const
double theta() const
Definition: RotationY.cc:52
double yx() const
bool isNear(const HepRotationY &r, double epsilon=Hep4RotationInterface::tolerance) const
Definition: RotationY.cc:174
double howNear(const HepRotationY &r) const
Definition: RotationY.cc:162
double zy() const
double zx() const
double xx() const
double phi() const
Definition: RotationY.cc:42
void decompose(HepAxisAngle &rotation, Hep3Vector &boost) const
Definition: RotationY.cc:112
HepRotationY & set(double delta)
Definition: RotationY.cc:35
double xz() const
HepAxisAngle axisAngle() const
double thetaY() const
Definition: RotationY.cc:97
double distance2(const HepRotationY &r) const
Definition: RotationY.cc:135
std::ostream & print(std::ostream &os) const
Definition: RotationY.cc:192
double yy() const
double phiY() const
Definition: RotationY.cc:83
double psi() const
Definition: RotationY.cc:56
double xy() const
double thetaX() const
Definition: RotationY.cc:93
double thetaZ() const
Definition: RotationY.cc:102
double phiX() const
Definition: RotationY.cc:78
double norm2() const
Definition: RotationY.cc:188
HepEulerAngles eulerAngles() const
Definition: RotationY.cc:66
double zz() const
double zx() const
double xx() const
double yy() const
double xz() const
Definition: DoubConv.h:17