source: trunk/CLHEP/src/AxisAngle.cc@ 13

Last change on this file since 13 was 4, checked in by Pavel Demin, 16 years ago

first commit

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