source: trunk/CLHEP/src/RotationY.cc@ 5

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

first commit

File size: 5.2 KB
RevLine 
[4]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 HepRotationY 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/RotationY.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
34HepRotationY::HepRotationY(double delta) :
35 d(proper(delta)), s(sin(delta)), c(cos(delta))
36{}
37
38HepRotationY & HepRotationY::set ( double delta ) {
39 d = proper(delta);
40 s = sin(d);
41 c = cos(d);
42 return *this;
43}
44
45double HepRotationY::phi() const {
46 if ( d == 0 ) {
47 return 0;
48 } else if ( (d < 0) || (d == CLHEP::pi) ) {
49 return +CLHEP::halfpi;
50 } else {
51 return -CLHEP::halfpi;
52 }
53} // HepRotationY::phi()
54
55double HepRotationY::theta() const {
56 return fabs( d );
57} // HepRotationY::theta()
58
59double HepRotationY::psi() const {
60 if ( d == 0 ) {
61 return 0;
62 } else if ( (d < 0) || (d == CLHEP::pi) ) {
63 return -CLHEP::halfpi;
64 } else {
65 return +CLHEP::halfpi;
66 }
67} // HepRotationY::psi()
68
69HepEulerAngles HepRotationY::eulerAngles() const {
70 return HepEulerAngles( phi(), theta(), psi() );
71} // HepRotationY::eulerAngles()
72
73
74// From the defining code in the implementation of CLHEP (in Rotation.cc)
75// it is clear that thetaX, phiX form the polar angles in the original
76// coordinate system of the new X axis (and similarly for phiY and phiZ).
77//
78// This code is taken directly from the original CLHEP. However, there are as
79// shown opportunities for significant speed improvement.
80
81double HepRotationY::phiX() const {
82 return (yx() == 0.0 && xx() == 0.0) ? 0.0 : atan2(yx(),xx());
83 // or ---- return 0;
84}
85
86double HepRotationY::phiY() const {
87 return (yy() == 0.0 && xy() == 0.0) ? 0.0 : atan2(yy(),xy());
88 // or ---- return CLHEP::halfpi;
89}
90
91double HepRotationY::phiZ() const {
92 return (yz() == 0.0 && xz() == 0.0) ? 0.0 : atan2(yz(),xz());
93 // or ---- return 0;
94}
95
96double HepRotationY::thetaX() const {
97 return safe_acos(zx());
98}
99
100double HepRotationY::thetaY() const {
101 return safe_acos(zy());
102 // or ---- return CLHEP::halfpi;
103}
104
105double HepRotationY::thetaZ() const {
106 return safe_acos(zz());
107 // or ---- return d;
108}
109
110void HepRotationY::setDelta ( double delta ) {
111 set(delta);
112}
113
114void HepRotationY::decompose
115 (HepAxisAngle & rotation, Hep3Vector & boost) const {
116 boost.set(0,0,0);
117 rotation = axisAngle();
118}
119
120void HepRotationY::decompose
121 (Hep3Vector & boost, HepAxisAngle & rotation) const {
122 boost.set(0,0,0);
123 rotation = axisAngle();
124}
125
126void HepRotationY::decompose
127 (HepRotation & rotation, HepBoost & boost) const {
128 boost.set(0,0,0);
129 rotation = HepRotation(*this);
130}
131
132void HepRotationY::decompose
133 (HepBoost & boost, HepRotation & rotation) const {
134 boost.set(0,0,0);
135 rotation = HepRotation(*this);
136}
137
138double HepRotationY::distance2( const HepRotationY & r ) const {
139 double answer = 2.0 * ( 1.0 - ( s * r.s + c * r.c ) ) ;
140 return (answer >= 0) ? answer : 0;
141}
142
143double HepRotationY::distance2( const HepRotation & r ) const {
144 double sum = xx() * r.xx() + xz() * r.xz()
145 + r.yy()
146 + zx() * r.zx() + zz() * r.zz();
147 double answer = 3.0 - sum;
148 return (answer >= 0 ) ? answer : 0;
149}
150
151double HepRotationY::distance2( const HepLorentzRotation & lt ) const {
152 HepAxisAngle a;
153 Hep3Vector b;
154 lt.decompose(b, a);
155 double bet = b.beta();
156 double bet2 = bet*bet;
157 HepRotation r(a);
158 return bet2/(1-bet2) + distance2(r);
159}
160
161double HepRotationY::distance2( const HepBoost & lt ) const {
162 return distance2( HepLorentzRotation(lt));
163}
164
165double HepRotationY::howNear( const HepRotationY & r ) const {
166 return sqrt(distance2(r));
167}
168double HepRotationY::howNear( const HepRotation & r ) const {
169 return sqrt(distance2(r));
170}
171double HepRotationY::howNear( const HepBoost & lt ) const {
172 return sqrt(distance2(lt));
173}
174double HepRotationY::howNear( const HepLorentzRotation & lt ) const {
175 return sqrt(distance2(lt));
176}
177bool HepRotationY::isNear(const HepRotationY & r,double epsilon)const{
178 return (distance2(r) <= epsilon*epsilon);
179}
180bool HepRotationY::isNear(const HepRotation & r,double epsilon)const {
181 return (distance2(r) <= epsilon*epsilon);
182}
183bool HepRotationY::isNear( const HepBoost & lt,double epsilon) const {
184 return (distance2(lt) <= epsilon*epsilon);
185}
186bool HepRotationY::isNear( const HepLorentzRotation & lt,
187 double epsilon) const {
188 return (distance2(lt) <= epsilon*epsilon);
189}
190
191double HepRotationY::norm2() const {
192 return 2.0 - 2.0 * c;
193}
194
195std::ostream & HepRotationY::print( std::ostream & os ) const {
196 os << "\nRotation about Y (" << d <<
197 ") [cos d = " << c << " sin d = " << s << "]\n";
198 return os;
199}
200
201} // namespace CLHEP
Note: See TracBrowser for help on using the repository browser.