Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
AxisAngle.cc
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// AxisAngle.cc
4//
5// History:
6// 23-Jan-1998 WEB Initial draft
7// 13-Mar-1998 WEB Corrected ZMpvAxisAngleRep
8// 15-Jun-1998 WEB Added namespace support
9// 26-Jul-2000 MF CLHEP version
10// 12-Apr-2001 MF NaN-proofing
11//
12// ----------------------------------------------------------------------
13
15
16namespace CLHEP {
17
19
20static void ZMpvAxisAngleRep( const HepAxisAngle & aa, double array[] ) {
21
22 register double sinDelta = std::sin( aa.delta() );
23 register double cosDelta = std::cos( aa.delta() );
24 register double oneMinusCosDelta = 1.0 - cosDelta;
25
26 register double uX = aa.getAxis().getX();
27 register double uY = aa.getAxis().getY();
28 register double uZ = aa.getAxis().getZ();
29
30 array[0] = oneMinusCosDelta * uX * uX + cosDelta;
31 array[1] = oneMinusCosDelta * uX * uY - sinDelta * uZ;
32 array[2] = oneMinusCosDelta * uX * uZ + sinDelta * uY;
33
34 array[3] = oneMinusCosDelta * uY * uX + sinDelta * uZ;
35 array[4] = oneMinusCosDelta * uY * uY + cosDelta;
36 array[5] = oneMinusCosDelta * uY * uZ - sinDelta * uX;
37
38 array[6] = oneMinusCosDelta * uZ * uX - sinDelta * uY;
39 array[7] = oneMinusCosDelta * uZ * uY + sinDelta * uX;
40 array[8] = oneMinusCosDelta * uZ * uZ + cosDelta;
41
42} // ZMpvAxisAngleRep
43
44
45double HepAxisAngle::distance( const AA & aa ) const {
46
47 double thisRep[9];
48 double aaRep[9];
49
50 ZMpvAxisAngleRep( *this, thisRep );
51 ZMpvAxisAngleRep( aa, aaRep );
52
53 double sum = 0.0;
54 for ( int i = 0; i < 9; i++ ) {
55 sum += thisRep[i] * aaRep[i];
56 }
57
58 double d = 3.0 - sum; // NaN-proofing:
59 return (d >= 0) ? d : 0; // std::sqrt(distance) is used in howNear()
60
61} // HepAxisAngle::distance()
62
63
64bool HepAxisAngle::isNear( const AA & aa, Scalar epsilon ) const {
65
66 return distance( aa ) <= epsilon * epsilon;
67
68} // HepAxisAngle::isNear()
69
70
71double HepAxisAngle::howNear( const AA & aa ) const {
72
73 return std::sqrt( distance( aa ) );
74
75} // HepAxisAngle::howNear()
76
77
78//-********************
79//
80// Global methods
81//
82//-********************
83
84
85std::ostream & operator<<(std::ostream & os, const HepAxisAngle & aa) {
86 os << '(' << aa.axis() << ", " << aa.delta() << ')';
87 return os;
88} // operator<<()
89
90
91void ZMinputAxisAngle ( std::istream & is,
92 double & x, double & y, double & z,
93 double & delta );
94
95std::istream & operator>>(std::istream & is, HepAxisAngle & aa) {
96 Hep3Vector axis;
97 double delta;
98 double x,y,z;
99 ZMinputAxisAngle ( is, x, y, z, delta );
100 axis.set(x,y,z);
101 aa.set ( axis, delta );
102 return is;
103} // operator>>()
104
105} // namespace CLHEP
void set(double x, double y, double z)
bool isNear(const AA &aa, Scalar epsilon=tolerance) const
Definition: AxisAngle.cc:64
double distance(const HepAxisAngle &aa) const
Definition: AxisAngle.cc:45
double delta() const
double howNear(const AA &aa) const
Definition: AxisAngle.cc:71
static Scalar tolerance
Definition: AxisAngle.h:43
Hep3Vector axis() const
AA & set(const Hep3Vector axis, Scalar delta)
Definition: DoubConv.h:17
std::istream & operator>>(std::istream &is, HepRandom &dist)
Definition: Random.cc:120
void ZMinputAxisAngle(std::istream &is, double &x, double &y, double &z, double &delta)
Definition: ZMinput.cc:156
std::ostream & operator<<(std::ostream &os, const HepRandom &dist)
Definition: Random.cc:116