Geant4  10.03
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 
14 #include "CLHEP/Vector/AxisAngle.h"
15 
16 namespace CLHEP {
17 
18 double HepAxisAngle::tolerance = Hep3Vector::ToleranceTicks * 1.0e-08;
19 
20 static void ZMpvAxisAngleRep( const HepAxisAngle & aa, double array[] ) {
21 
22  double sinDelta = std::sin( aa.delta() );
23  double cosDelta = std::cos( aa.delta() );
24  double oneMinusCosDelta = 1.0 - cosDelta;
25 
26  double uX = aa.getAxis().getX();
27  double uY = aa.getAxis().getY();
28  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 
45 double 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 
64 bool HepAxisAngle::isNear( const AA & aa, Scalar epsilon ) const {
65 
66  return distance( aa ) <= epsilon * epsilon;
67 
68 } // HepAxisAngle::isNear()
69 
70 
71 double 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 
85 std::ostream & operator<<(std::ostream & os, const HepAxisAngle & aa) {
86  os << '(' << aa.axis() << ", " << aa.delta() << ')';
87  return os;
88 } // operator<<()
89 
90 
91 void ZMinputAxisAngle ( std::istream & is,
92  double & x, double & y, double & z,
93  double & delta );
94 
95 std::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
static void ZMpvAxisAngleRep(const HepAxisAngle &aa, double array[])
Definition: AxisAngle.cc:20
void ZMinputAxisAngle(std::istream &is, double &x, double &y, double &z, double &delta)
Definition: ZMinput.cc:156
std::istream & operator>>(std::istream &is, HepAxisAngle &aa)
Definition: AxisAngle.cc:95
std::ostream & operator<<(std::ostream &os, const HepAxisAngle &aa)
Definition: AxisAngle.cc:85
double epsilon(double density, double temperature)