source: trunk/CLHEP/src/RotationX.cc@ 23

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

first commit

File size: 5.1 KB
Line 
1// -*- C++ -*-
2// ---------------------------------------------------------------------------
3//
4// This file is a part of the CLHEP - a Class Library for High Energy Physics.
5//
6// This is the implementation of methods of the HepRotationX class which
7// were introduced when ZOOM PhysicsVectors was merged in.
8//
9
10#ifdef GNUPRAGMA
11#pragma implementation
12#endif
13
14#include "CLHEP/Vector/defs.h"
15#include "CLHEP/Vector/RotationX.h"
16#include "CLHEP/Vector/AxisAngle.h"
17#include "CLHEP/Vector/EulerAngles.h"
18#include "CLHEP/Vector/LorentzRotation.h"
19#include "CLHEP/Units/PhysicalConstants.h"
20
21#include <cmath>
22#include <stdlib.h>
23#include <iostream>
24
25using std::abs;
26
27namespace CLHEP {
28
29static inline double safe_acos (double x) {
30 if (abs(x) <= 1.0) return acos(x);
31 return ( (x>0) ? 0 : CLHEP::pi );
32}
33
34HepRotationX::HepRotationX(double delta) :
35 d(proper(delta)), s(sin(delta)), c(cos(delta))
36{}
37
38HepRotationX & HepRotationX::set ( double delta ) {
39 d = proper(delta);
40 s = sin(d);
41 c = cos(d);
42 return *this;
43}
44
45double HepRotationX::phi() const {
46 if ( (d > 0) && (d < CLHEP::pi) ) {
47 return CLHEP::pi;
48 } else {
49 return 0.0;
50 }
51} // HepRotationX::phi()
52
53double HepRotationX::theta() const {
54 return fabs( d );
55} // HepRotationX::theta()
56
57double HepRotationX::psi() const {
58 if ( (d > 0) && (d < CLHEP::pi) ) {
59 return CLHEP::pi;
60 } else {
61 return 0.0;
62 }
63} // HepRotationX::psi()
64
65HepEulerAngles HepRotationX::eulerAngles() const {
66 return HepEulerAngles( phi(), theta(), psi() );
67} // HepRotationX::eulerAngles()
68
69
70// From the defining code in the implementation of CLHEP (in Rotation.cc)
71// it is clear that thetaX, phiX form the polar angles in the original
72// coordinate system of the new X axis (and similarly for phiY and phiZ).
73//
74// This code is taken directly from the original CLHEP. However, there are as
75// shown opportunities for significant speed improvement.
76
77double HepRotationX::phiX() const {
78 return (yx() == 0.0 && xx() == 0.0) ? 0.0 : atan2(yx(),xx());
79 // or ---- return 0;
80}
81
82double HepRotationX::phiY() const {
83 return (yy() == 0.0 && xy() == 0.0) ? 0.0 : atan2(yy(),xy());
84 // or ---- return (yy() == 0.0) ? 0.0 : atan2(yy(),xy());
85}
86
87double HepRotationX::phiZ() const {
88 return (yz() == 0.0 && xz() == 0.0) ? 0.0 : atan2(yz(),xz());
89 // or ---- return (yz() == 0.0) ? 0.0 : atan2(yz(),xz());
90}
91
92double HepRotationX::thetaX() const {
93 return safe_acos(zx());
94 // or ---- return CLHEP::halfpi;
95}
96
97double HepRotationX::thetaY() const {
98 return safe_acos(zy());
99}
100
101double HepRotationX::thetaZ() const {
102 return safe_acos(zz());
103 // or ---- return d;
104}
105
106void HepRotationX::setDelta ( double delta ) {
107 set(delta);
108}
109
110void HepRotationX::decompose
111 (HepAxisAngle & rotation, Hep3Vector & boost) const {
112 boost.set(0,0,0);
113 rotation = axisAngle();
114}
115
116void HepRotationX::decompose
117 (Hep3Vector & boost, HepAxisAngle & rotation) const {
118 boost.set(0,0,0);
119 rotation = axisAngle();
120}
121
122void HepRotationX::decompose
123 (HepRotation & rotation, HepBoost & boost) const {
124 boost.set(0,0,0);
125 rotation = HepRotation(*this);
126}
127
128void HepRotationX::decompose
129 (HepBoost & boost, HepRotation & rotation) const {
130 boost.set(0,0,0);
131 rotation = HepRotation(*this);
132}
133
134double HepRotationX::distance2( const HepRotationX & r ) const {
135 double answer = 2.0 * ( 1.0 - ( s * r.s + c * r.c ) ) ;
136 return (answer >= 0) ? answer : 0;
137}
138
139double HepRotationX::distance2( const HepRotation & r ) const {
140 double sum = r.xx() +
141 yy() * r.yy() + yz() * r.yz()
142 + zy() * r.zy() + zz() * r.zz();
143 double answer = 3.0 - sum;
144 return (answer >= 0 ) ? answer : 0;
145}
146
147double HepRotationX::distance2( const HepLorentzRotation & lt ) const {
148 HepAxisAngle a;
149 Hep3Vector b;
150 lt.decompose(b, a);
151 double bet = b.beta();
152 double bet2 = bet*bet;
153 HepRotation r(a);
154 return bet2/(1-bet2) + distance2(r);
155}
156
157double HepRotationX::distance2( const HepBoost & lt ) const {
158 return distance2( HepLorentzRotation(lt));
159}
160
161double HepRotationX::howNear( const HepRotationX & r ) const {
162 return sqrt(distance2(r));
163}
164double HepRotationX::howNear( const HepRotation & r ) const {
165 return sqrt(distance2(r));
166}
167double HepRotationX::howNear( const HepBoost & b ) const {
168 return sqrt(distance2(b));
169}
170double HepRotationX::howNear( const HepLorentzRotation & lt ) const {
171 return sqrt(distance2(lt));
172}
173bool HepRotationX::isNear(const HepRotationX & r,double epsilon)const{
174 return (distance2(r) <= epsilon*epsilon);
175}
176bool HepRotationX::isNear(const HepRotation & r,double epsilon) const{
177 return (distance2(r) <= epsilon*epsilon);
178}
179bool HepRotationX::isNear( const HepBoost & lt,double epsilon) const {
180 return (distance2(lt) <= epsilon*epsilon);
181}
182
183bool HepRotationX::isNear( const HepLorentzRotation & lt,
184 double epsilon ) const {
185 return (distance2(lt) <= epsilon*epsilon);
186}
187
188double HepRotationX::norm2() const {
189 return 2.0 - 2.0 * c;
190}
191
192std::ostream & HepRotationX::print( std::ostream & os ) const {
193 os << "\nRotation about X (" << d <<
194 ") [cos d = " << c << " sin d = " << s << "]\n";
195 return os;
196}
197
198} // namespace CLHEP
199
Note: See TracBrowser for help on using the repository browser.