This commit was generated by cvs2svn to compensate for changes in r2,
[u/mrichter/AliRoot.git] / PHOS / CLHEP / Vector / ThreeVector.icc
CommitLineData
fe4da5cc 1// -*- C++ -*-
2// $Id$
3// ---------------------------------------------------------------------------
4//
5// This file is a part of the CLHEP - a Class Library for High Energy Physics.
6//
7// This is the definitions of the inline member functions of the
8// Hep3Vector class.
9//
10
11#ifdef HEP_DEBUG_INLINE
12#define inline
13#endif
14
15inline Hep3Vector::Hep3Vector(HepDouble x, HepDouble y, HepDouble z)
16: dx(x), dy(y), dz(z) {}
17
18inline HepDouble Hep3Vector::x() const {
19 return dx;
20}
21
22inline HepDouble Hep3Vector::y() const {
23 return dy;
24}
25
26inline HepDouble Hep3Vector::z() const {
27 return dz;
28}
29
30inline void Hep3Vector::setX(HepDouble x) {
31 dx = x;
32}
33
34inline void Hep3Vector::setY(HepDouble y) {
35 dy = y;
36}
37
38inline void Hep3Vector::setZ(HepDouble z) {
39 dz = z;
40}
41
42inline Hep3Vector::Hep3Vector(const Hep3Vector & p)
43: dx(p.x()), dy(p.y()), dz(p.z()) {}
44
45inline Hep3Vector::~Hep3Vector() {}
46
47inline Hep3Vector & Hep3Vector::operator = (const Hep3Vector & p) {
48 dx = p.x();
49 dy = p.y();
50 dz = p.z();
51 return *this;
52}
53
54inline HepBoolean Hep3Vector::operator == (const Hep3Vector& v) const {
55 return (v.x()==x() && v.y()==y() && v.z()==z()) ? true : false;
56}
57
58inline HepBoolean Hep3Vector::operator != (const Hep3Vector& v) const {
59 return (v.x()!=x() || v.y()!=y() || v.z()!=z()) ? true : false;
60}
61
62inline Hep3Vector& Hep3Vector::operator += (const Hep3Vector & p) {
63 dx += p.x();
64 dy += p.y();
65 dz += p.z();
66 return *this;
67}
68
69inline Hep3Vector& Hep3Vector::operator -= (const Hep3Vector & p) {
70 dx -= p.x();
71 dy -= p.y();
72 dz -= p.z();
73 return *this;
74}
75
76inline Hep3Vector Hep3Vector::operator - () const {
77 return Hep3Vector(-dx, -dy, -dz);
78}
79
80inline Hep3Vector& Hep3Vector::operator *= (HepDouble a) {
81 dx *= a;
82 dy *= a;
83 dz *= a;
84 return *this;
85}
86
87inline HepDouble Hep3Vector::dot(const Hep3Vector & p) const {
88 return dx*p.x() + dy*p.y() + dz*p.z();
89}
90
91inline Hep3Vector Hep3Vector::cross(const Hep3Vector & p) const {
92 return Hep3Vector(dy*p.z()-p.y()*dz, dz*p.x()-p.z()*dx, dx*p.y()-p.x()*dy);
93}
94
95inline HepDouble Hep3Vector::mag2() const {
96 return dx*dx + dy*dy + dz*dz;
97}
98
99inline HepDouble Hep3Vector::mag() const {
100 return sqrt(mag2());
101}
102
103inline Hep3Vector Hep3Vector::unit() const {
104 HepDouble tot = mag2();
105 Hep3Vector p(*this);
106 return tot > 0.0 ? p *= (1.0/sqrt(tot)) : p;
107}
108
109inline Hep3Vector Hep3Vector::orthogonal() const {
110 HepDouble x = abs(dx), y = abs(dy), z = abs(dz);
111 if (x < y) {
112 return x < z ? Hep3Vector(0,dz,-dy) : Hep3Vector(dy,-dx,0);
113 }else{
114 return y < z ? Hep3Vector(-dz,0,dx) : Hep3Vector(dy,-dx,0);
115 }
116}
117
118inline HepDouble Hep3Vector::perp2() const {
119 return dx*dx + dy*dy;
120}
121
122inline HepDouble Hep3Vector::perp() const {
123 return sqrt(perp2());
124}
125
126inline HepDouble Hep3Vector::perp2(const Hep3Vector & p) const {
127 HepDouble tot = p.mag2();
128 return tot > 0.0 ? mag2()-sqr(dot(p))/tot : mag2();
129}
130
131inline HepDouble Hep3Vector::perp(const Hep3Vector & p) const {
132 return sqrt(perp2(p));
133}
134
135inline HepDouble Hep3Vector::phi() const {
136 return dx == 0.0 && dy == 0.0 ? 0.0 : atan2(dy,dx);
137}
138
139inline HepDouble Hep3Vector::theta() const {
140 return dx == 0.0 && dy == 0.0 && dz == 0.0 ? 0.0 : atan2(perp(),dz);
141}
142
143inline HepDouble Hep3Vector::cosTheta() const {
144 HepDouble ptot = mag();
145 return ptot == 0.0 ? 1.0 : dz/ptot;
146}
147
148inline HepDouble Hep3Vector::angle(const Hep3Vector & q) const {
149 HepDouble ptot2 = mag2()*q.mag2();
150 return ptot2 <= 0.0 ? 0.0 : acos(dot(q)/sqrt(ptot2));
151}
152
153inline void Hep3Vector::setMag(HepDouble ma){
154 HepDouble th = theta();
155 HepDouble ph = phi();
156
157 setX(ma*sin(th)*cos(ph));
158 setY(ma*sin(th)*sin(ph));
159 setZ(ma*cos(th));
160}
161
162inline void Hep3Vector::setTheta(HepDouble th){
163 HepDouble ma = mag();
164 HepDouble ph = phi();
165
166 setX(ma*sin(th)*cos(ph));
167 setY(ma*sin(th)*sin(ph));
168 setZ(ma*cos(th));
169}
170
171inline void Hep3Vector::setPhi(HepDouble ph){
172 HepDouble ma = mag();
173 HepDouble th = theta();
174
175 setX(ma*sin(th)*cos(ph));
176 setY(ma*sin(th)*sin(ph));
177 setZ(ma*cos(th));
178}
179
180inline Hep3Vector operator + (const Hep3Vector & a, const Hep3Vector & b) {
181 return Hep3Vector(a.x() + b.x(), a.y() + b.y(), a.z() + b.z());
182}
183
184inline Hep3Vector operator - (const Hep3Vector & a, const Hep3Vector & b) {
185 return Hep3Vector(a.x() - b.x(), a.y() - b.y(), a.z() - b.z());
186}
187
188inline Hep3Vector operator * (const Hep3Vector & p, HepDouble a) {
189 return Hep3Vector(a*p.x(), a*p.y(), a*p.z());
190}
191
192inline Hep3Vector operator * (HepDouble a, const Hep3Vector & p) {
193 return Hep3Vector(a*p.x(), a*p.y(), a*p.z());
194}
195
196inline HepDouble operator * (const Hep3Vector & a, const Hep3Vector & b) {
197 return a.dot(b);
198}
199
200#ifdef HEP_DEBUG_INLINE
201#undef inline
202#endif