Geant4 11.1.1
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
16
17#include <cmath>
18#include <ostream>
19
20namespace CLHEP {
21
23
24static void ZMpvAxisAngleRep( const HepAxisAngle & aa, double array[] ) {
25
26 double sinDelta = std::sin( aa.delta() );
27 double cosDelta = std::cos( aa.delta() );
28 double oneMinusCosDelta = 1.0 - cosDelta;
29
30 double uX = aa.getAxis().getX();
31 double uY = aa.getAxis().getY();
32 double uZ = aa.getAxis().getZ();
33
34 array[0] = oneMinusCosDelta * uX * uX + cosDelta;
35 array[1] = oneMinusCosDelta * uX * uY - sinDelta * uZ;
36 array[2] = oneMinusCosDelta * uX * uZ + sinDelta * uY;
37
38 array[3] = oneMinusCosDelta * uY * uX + sinDelta * uZ;
39 array[4] = oneMinusCosDelta * uY * uY + cosDelta;
40 array[5] = oneMinusCosDelta * uY * uZ - sinDelta * uX;
41
42 array[6] = oneMinusCosDelta * uZ * uX - sinDelta * uY;
43 array[7] = oneMinusCosDelta * uZ * uY + sinDelta * uX;
44 array[8] = oneMinusCosDelta * uZ * uZ + cosDelta;
45
46} // ZMpvAxisAngleRep
47
48
49double HepAxisAngle::distance( const AA & aa ) const {
50
51 double thisRep[9];
52 double aaRep[9];
53
54 ZMpvAxisAngleRep( *this, thisRep );
55 ZMpvAxisAngleRep( aa, aaRep );
56
57 double sum = 0.0;
58 for ( int i = 0; i < 9; i++ ) {
59 sum += thisRep[i] * aaRep[i];
60 }
61
62 double d = 3.0 - sum; // NaN-proofing:
63 return (d >= 0) ? d : 0; // std::sqrt(distance) is used in howNear()
64
65} // HepAxisAngle::distance()
66
67
68bool HepAxisAngle::isNear( const AA & aa, Scalar epsilon ) const {
69
70 return distance( aa ) <= epsilon * epsilon;
71
72} // HepAxisAngle::isNear()
73
74
75double HepAxisAngle::howNear( const AA & aa ) const {
76
77 return std::sqrt( distance( aa ) );
78
79} // HepAxisAngle::howNear()
80
81
82//-********************
83//
84// Global methods
85//
86//-********************
87
88
89std::ostream & operator<<(std::ostream & os, const HepAxisAngle & aa) {
90 os << '(' << aa.axis() << ", " << aa.delta() << ')';
91 return os;
92} // operator<<()
93
94
95void ZMinputAxisAngle ( std::istream & is,
96 double & x, double & y, double & z,
97 double & delta );
98
99std::istream & operator>>(std::istream & is, HepAxisAngle & aa) {
100 Hep3Vector axis;
101 double delta;
102 double x,y,z;
103 ZMinputAxisAngle ( is, x, y, z, delta );
104 axis.set(x,y,z);
105 aa.set ( axis, delta );
106 return is;
107} // operator>>()
108
109} // namespace CLHEP
G4double epsilon(G4double density, G4double temperature)
void set(double x, double y, double z)
bool isNear(const AA &aa, Scalar epsilon=tolerance) const
Definition: AxisAngle.cc:68
double distance(const HepAxisAngle &aa) const
Definition: AxisAngle.cc:49
double delta() const
double howNear(const AA &aa) const
Definition: AxisAngle.cc:75
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:223
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:219