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