CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

EulerAngles.cc
Go to the documentation of this file.
1 // ----------------------------------------------------------------------
2 //
3 // EulerAngles.cc
4 //
5 // Methods for classes, and instances of globals, declared in EulerAngles.h
6 //
7 // History:
8 //
9 // 04-Dec-1997 MF Stub with just PI
10 // 12-Jan-1998 WEB PI now found in ZMutility; used ZMutility headers
11 // where available
12 // 16-Mar-1998 WEB Corrected ZMpvEulerAnglesRep
13 // 15-Jun-1998 WEB Added namespace support
14 // 26-Jul-2000 MF CLHEP version
15 // 12-Apr-2001 MF NaN-proofing
16 // 19-Nov-2001 MF Correction to ZMpvEulerAnglesRep, which was affecting
17 // .isNear(). array[3] had been incorrect.
18 // Note - the correct form was used in all other places
19 // including Rotation.set(phi, theta, psi).
20 //
21 // ----------------------------------------------------------------------
22 
23 
24 #include "CLHEP/Vector/defs.h"
25 #include "CLHEP/Vector/EulerAngles.h"
26 
27 #include "CLHEP/Vector/ThreeVector.h"
28 
29 #include <iostream>
30 
31 namespace CLHEP {
32 
33 //-*************
34 // static consts
35 //-*************
36 
38 
39 //-*******************
40 // measure of distance
41 //-*******************
42 
43 
44 static void ZMpvEulerAnglesRep ( const HepEulerAngles & ex, double array[] ) {
45 
46  register double sinPhi = std::sin( ex.phi() ) , cosPhi = std::cos( ex.phi() );
47  register double sinTheta = std::sin( ex.theta() ), cosTheta = std::cos( ex.theta() );
48  register double sinPsi = std::sin( ex.psi() ) , cosPsi = std::cos( ex.psi() );
49 
50  array[0] = cosPsi * cosPhi - sinPsi * cosTheta * sinPhi;
51  array[1] = cosPsi * sinPhi + sinPsi * cosTheta * cosPhi;
52  array[2] = sinPsi * sinTheta;
53 
54  array[3] = - sinPsi * cosPhi - cosPsi * cosTheta * sinPhi;
55  array[4] = - sinPsi * sinPhi + cosPsi * cosTheta * cosPhi;
56  array[5] = cosPsi * sinTheta;
57 
58  array[6] = sinTheta * sinPhi;
59  array[7] = - sinTheta * cosPhi;
60  array[8] = cosTheta;
61 
62 } // ZMpvEulerAnglesRep
63 
64 
65 double HepEulerAngles::distance( const EA & ex ) const {
66 
67  double thisRep[9];
68  double exRep[9];
69 
70  ZMpvEulerAnglesRep ( *this, thisRep );
71  ZMpvEulerAnglesRep ( ex, exRep );
72 
73  double sum = 0.0;
74  for (int i = 0; i < 9; i++) {
75  sum += thisRep[i] * exRep[i];
76  }
77 
78  double d = 3.0 - sum; // NaN-proofing:
79  return (d >= 0) ? d : 0; // std::sqrt(distance) is used in howNear()
80 
81 } // HepEulerAngles::distance()
82 
83 
84 bool HepEulerAngles::isNear( const EA & ex, double epsilon ) const {
85 
86  return distance( ex ) <= epsilon*epsilon ;
87 
88 } // HepEulerAngles::isNear()
89 
90 
91 double HepEulerAngles::howNear( const EA & ex ) const {
92 
93  return std::sqrt( distance( ex ) );
94 
95 } // HepEulerAngles::howNear()
96 
97 //-**************
98 // Global Methods
99 //-**************
100 
101 std::ostream & operator<<(std::ostream & os, const HepEulerAngles & ea)
102 {
103  os << "(" << ea.phi() << ", " << ea.theta() << ", " << ea.psi() << ")";
104  return os;
105 } // operator<<()
106 
107 void ZMinput3doubles ( std::istream & is, const char * type,
108  double & x, double & y, double & z );
109 
110 std::istream & operator>>(std::istream & is, HepEulerAngles & ea) {
111  double thePhi;
112  double theTheta;
113  double thePsi;
114  ZMinput3doubles ( is, "HepEulerAngle", thePhi , theTheta , thePsi );
115  ea.set ( thePhi , theTheta , thePsi );
116  return is;
117 } // operator>>()
118 
119 } // namespace CLHEP
120 
121 
CLHEP::HepEulerAngles::theta
double theta() const
is
HepRotation and so forth isNear() norm2() rectify() static Rotation row1 row4(To avoid bloat in the code pulled in for programs which don 't use all these features, we split the implementation .cc files. Only isNear() goes into the original Rotation.cc) --------------------------------------- HepAxisAngle and HepEulerAngles classes --------------------------------------- These classes are very useful and simple structures for holding the result of a nice intuituve decomposition of a rotation there is no longer much content in the distinct ZOOM PhysicsVectors library The only content left in the library is the object files representing the various Exception objects When we build the CLHEP classes for the ZOOM we will set up so as to use ZOOM SpaceVector is(but we can disable namespace usage and most of our users do so at this point). What I do is leave Hep3Vector in the global namespace
CLHEP::HepEulerAngles::set
EA & set(double phi, double theta, double psi)
CLHEP::HepEulerAngles::phi
double phi() const
CLHEP::HepEulerAngles::distance
double distance(const HepEulerAngles &ex) const
Definition: EulerAngles.cc:65
CLHEP::HepEulerAngles::isNear
bool isNear(const EA &ea, double epsilon=tolerance) const
Definition: EulerAngles.cc:84
CLHEP
Definition: ClhepVersion.h:13
type
Signatures of Hep3Vector::rotate For equivalent ZOOM axis There is no harm in leaving this axis CLHEP has implemented a first forming an identity then rotating that by axis and I leave the CLHEP code alone people are of course free to use the ZOOM originated method with signature which I believe will be faster Return types for rotateZ CLHEP and PhysicsVectors each have these three and they are identical except that the ZOOM version returns a reference to while in CLHEP they return void Having methods that alter an object return a reference to that object is convenient for certain chained and costs nothing I don t wish to potentially break ZOOM user code for no good so I have made these CLHEP method conform to this convention There are a couple of other CLHEP rotate and which use the void return type
Definition: minorMergeIssues.doc:113
CLHEP::Hep3Vector::ToleranceTicks
@ ToleranceTicks
Definition: Geometry/CLHEP/Vector/ThreeVector.h:299
CLHEP::operator>>
std::istream & operator>>(std::istream &is, HepAxisAngle &aa)
Definition: AxisAngle.cc:96
CLHEP::HepEulerAngles::tolerance
static double tolerance
Definition: Geometry/CLHEP/Vector/EulerAngles.h:36
i
long i
Definition: JamesRandomSeeding.txt:27
CLHEP::ZMinput3doubles
void ZMinput3doubles(std::istream &is, const char *type, double &x, double &y, double &z)
Definition: ZMinput.cc:37
CLHEP::operator<<
std::ostream & operator<<(std::ostream &os, const HepAxisAngle &aa)
Definition: AxisAngle.cc:86
CLHEP::HepEulerAngles
Definition: Geometry/CLHEP/Vector/EulerAngles.h:32
CLHEP::HepEulerAngles::psi
double psi() const
x
any side effects of that construction would occur twice The semantics of throw x
Definition: whyZMthrowRethrows.txt:37
CLHEP::HepEulerAngles::howNear
double howNear(const EA &ea) const
Definition: EulerAngles.cc:91