00001
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "CTBnum.hxx"
00015 #include "CTBmath.hxx"
00016
00070
00072
00073 template <class T>
00074 inline CTB3vec<T>::CTB3vec()
00075 {
00076 m_data[0] = 0;
00077 m_data[1] = 0;
00078 m_data[2] = 0;
00079 }
00080
00081
00083
00084 template <class T>
00085 inline CTB3vec<T>::CTB3vec(T rhs)
00086 {
00087 operator=(rhs);
00088 }
00089
00090
00092
00093 template <class T>
00094 inline CTB3vec<T>::CTB3vec(T x, T y, T z)
00095 {
00096 m_data[0] = x;
00097 m_data[1] = y;
00098 m_data[2] = z;
00099 }
00100
00101
00103
00104 template <class T>
00105 inline CTB3vec<T>::CTB3vec(const CTB3vec<T>& rhs)
00106 {
00107 operator=(rhs);
00108 }
00109
00110
00112
00113 template <class T>
00114 inline T& CTB3vec<T>::X()
00115 {
00116 return m_data[0];
00117 }
00118
00119
00121
00122 template <class T>
00123 inline const T& CTB3vec<T>::X() const
00124 {
00125 return m_data[0];
00126 }
00127
00128
00130
00131 template <class T>
00132 inline T& CTB3vec<T>::Y()
00133 {
00134 return m_data[1];
00135 }
00136
00137
00139
00140 template <class T>
00141 inline const T& CTB3vec<T>::Y() const
00142 {
00143 return m_data[1];
00144 }
00145
00146
00148
00149 template <class T>
00150 inline T& CTB3vec<T>::Z()
00151 {
00152 return m_data[2];
00153 }
00154
00155
00157
00158 template <class T>
00159 inline const T& CTB3vec<T>::Z() const
00160 {
00161 return m_data[2];
00162 }
00163
00164
00166
00167 template <class T>
00168 inline void CTB3vec<T>::X(T x)
00169 {
00170 m_data[0] = x;
00171 return;
00172 }
00173
00174
00176
00177 template <class T>
00178 inline void CTB3vec<T>::Y(T y)
00179 {
00180 m_data[1] = y;
00181 return;
00182 }
00183
00184
00186
00187 template <class T>
00188 inline void CTB3vec<T>::Z(T z)
00189 {
00190 m_data[2] = z;
00191 return;
00192 }
00193
00194
00196
00197 template <class T>
00198 inline T CTB3vec<T>::Length() const
00199 {
00200 return CTBsqrt(CTBabs2(m_data[0]) + CTBabs2(m_data[1]) + CTBabs2(m_data[2]));
00201 }
00202
00203
00205
00206 template <class T>
00207 inline T CTB3vec<T>::Dot(const CTB3vec<T>& rhs) const
00208 {
00209 return m_data[0]*rhs.m_data[0] +
00210 m_data[1]*rhs.m_data[1] +
00211 m_data[2]*rhs.m_data[2];
00212 }
00213
00214
00216
00217 template <class T>
00218 inline CTB3vec<T> CTB3vec<T>::Cross(const CTB3vec<T>& rhs) const
00219 {
00220 return CTB3vec<T>(Y()*rhs.Z() - Z()*rhs.Y(),
00221 Z()*rhs.X() - X()*rhs.Z(),
00222 X()*rhs.Y() - Y()*rhs.X());
00223 }
00224
00225
00227
00228 template <class T>
00229 inline CTB3vec<T> CTB3vec<T>::Project(const CTB3vec<T>& x,
00230 const CTB3vec<T>& y,
00231 const CTB3vec<T>& z) const
00232 {
00233 return CTB3vec<T>(Dot(x),Dot(y),Dot(z));
00234 }
00235
00236
00238
00239 template <class T>
00240 inline CTB3vec<T> CTB3vec<T>::UnProject(const CTB3vec<T>& x,
00241 const CTB3vec<T>& y,
00242 const CTB3vec<T>& z) const
00243 {
00244 return CTB3vec<T>(m_data[0]*x[0] + m_data[1]*y[0] + m_data[2]*z[0],
00245 m_data[0]*x[1] + m_data[1]*y[1] + m_data[2]*z[1],
00246 m_data[0]*x[2] + m_data[1]*y[2] + m_data[2]*z[2]);
00247 }
00248
00249
00251
00252 template <class T>
00253 inline T& CTB3vec<T>::operator[](CTBint i_ind)
00254 {
00255 return m_data[i_ind];
00256 }
00257
00258
00260
00261 template <class T>
00262 inline const T& CTB3vec<T>::operator[](CTBint i_ind) const
00263 {
00264 return m_data[i_ind];
00265 }
00266
00267
00269
00270 template <class T>
00271 inline CTB3vec<T>::operator T*()
00272 {
00273 return m_data;
00274 }
00275
00276
00278
00279 template <class T>
00280 inline CTB3vec<T>::operator const T*() const
00281 {
00282 return m_data;
00283 }
00284
00285
00287
00288 template <class T>
00289 inline CTB3vec<T> CTB3vec<T>::operator-() const
00290 {
00291 return CTB3vec<T>(-m_data[0],-m_data[1],-m_data[2]);
00292 }
00293
00294
00296
00297 template <class T>
00298 inline CTB3vec<T>& CTB3vec<T>::operator+=(const CTB3vec<T>& rhs)
00299 {
00300 m_data[0] += rhs.m_data[0];
00301 m_data[1] += rhs.m_data[1];
00302 m_data[2] += rhs.m_data[2];
00303 return *this;
00304 }
00305
00306
00308
00309 template <class T>
00310 inline CTB3vec<T>& CTB3vec<T>::operator-=(const CTB3vec<T>& rhs)
00311 {
00312 m_data[0] -= rhs.m_data[0];
00313 m_data[1] -= rhs.m_data[1];
00314 m_data[2] -= rhs.m_data[2];
00315 return *this;
00316 }
00317
00318
00320
00321 template <class T>
00322 inline CTB3vec<T>& CTB3vec<T>::operator*=(T rhs)
00323 {
00324 m_data[0] *= rhs;
00325 m_data[1] *= rhs;
00326 m_data[2] *= rhs;
00327 return *this;
00328 }
00329
00330
00332
00333 template <class T>
00334 inline CTB3vec<T>& CTB3vec<T>::operator/=(T rhs)
00335 {
00336 T rhs_inv = 1./rhs;
00337 m_data[0] *= rhs_inv;
00338 m_data[1] *= rhs_inv;
00339 m_data[2] *= rhs_inv;
00340 return *this;
00341 }
00342
00343
00345
00346 template <class T>
00347 inline CTB3vec<T>& CTB3vec<T>::operator=(T rhs)
00348 {
00349 m_data[0] = rhs;
00350 m_data[1] = rhs;
00351 m_data[2] = rhs;
00352 return *this;
00353 }
00354
00355
00357
00358 template <class T>
00359 inline CTB3vec<T>& CTB3vec<T>::operator=(const CTB3vec<T>& rhs)
00360 {
00361 m_data[0] = rhs.m_data[0];
00362 m_data[1] = rhs.m_data[1];
00363 m_data[2] = rhs.m_data[2];
00364 return *this;
00365 }
00366
00367
00373 template <class T>
00374 inline CTB3vec<T> operator+(const CTB3vec<T>& lhs, const CTB3vec<T>& rhs)
00375 {
00376 return CTB3vec<T>(lhs[0]+rhs[0], lhs[1]+rhs[1], lhs[2]+rhs[2]);
00377 }
00378
00379
00385 template <class T>
00386 inline CTB3vec<T> operator+(const CTB3vec<T>& lhs, T f_rhs)
00387 {
00388 return CTB3vec<T>(lhs[0]+f_rhs, lhs[1]+f_rhs, lhs[2]+f_rhs);
00389 }
00390
00391
00397 template <class T>
00398 inline CTB3vec<T> operator+(T f_lhs, const CTB3vec<T>& rhs)
00399 {
00400 return CTB3vec<T>(f_lhs+rhs[0], f_lhs+rhs[1], f_lhs+rhs[2]);
00401 }
00402
00403
00409 template <class T>
00410 inline CTB3vec<T> operator-(const CTB3vec<T>& lhs, const CTB3vec<T>& rhs)
00411 {
00412 return CTB3vec<T>(lhs[0]-rhs[0], lhs[1]-rhs[1], lhs[2]-rhs[2]);
00413 }
00414
00415
00421 template <class T>
00422 inline CTB3vec<T> operator-(const CTB3vec<T>& lhs, T f_rhs)
00423 {
00424 return CTB3vec<T>(lhs[0]-f_rhs, lhs[1]-f_rhs, lhs[2]-f_rhs);
00425 }
00426
00427
00433 template <class T>
00434 inline CTB3vec<T> operator-(T f_lhs, const CTB3vec<T>& rhs)
00435 {
00436 return CTB3vec<T>(f_lhs-rhs[0], f_lhs-rhs[1], f_lhs-rhs[2]);
00437 }
00438
00439
00445 template <class T>
00446 inline T operator*(const CTB3vec<T>& lhs, const CTB3vec<T>& rhs)
00447 {
00448 return lhs[0]*rhs[0] + lhs[1]*rhs[1] + lhs[2]*rhs[2];
00449 }
00450
00451
00457 template <class T>
00458 inline CTB3vec<T> operator*(const CTB3vec<T>& lhs, T f_rhs)
00459 {
00460 return CTB3vec<T>(lhs[0]*f_rhs, lhs[1]*f_rhs, lhs[2]*f_rhs);
00461 }
00462
00463
00469 template <class T>
00470 inline CTB3vec<T> operator*(T f_lhs, const CTB3vec<T>& rhs)
00471 {
00472 return CTB3vec<T>(f_lhs*rhs[0], f_lhs*rhs[1], f_lhs*rhs[2]);
00473 }
00474
00475
00481 template <class T>
00482 inline CTB3vec<T> operator/(const CTB3vec<T>& lhs, T f_rhs)
00483 {
00484 return CTB3vec<T>(lhs[0]/f_rhs, lhs[1]/f_rhs, lhs[2]/f_rhs);
00485 }
00486
00487
00493 template <class T>
00494 inline bool operator==(const CTB3vec<T>& lhs, const CTB3vec<T>& rhs)
00495 {
00496 return lhs[0] == rhs[0] && lhs[1] == rhs[1] && lhs[2] == rhs[2];
00497 }
00498
00499
00505 template <class T>
00506 inline bool operator==(const CTB3vec<T>& lhs, T f_rhs)
00507 {
00508 return lhs[0] == f_rhs && lhs[1] == f_rhs && lhs[2] == f_rhs;
00509 }
00510
00511
00517 template <class T>
00518 inline bool operator==(T f_lhs, const CTB3vec<T>& rhs)
00519 {
00520 return f_lhs == rhs[0] && f_lhs == rhs[1] && f_lhs == rhs[2];
00521 }
00522
00523
00529 template <class T>
00530 ostream& operator<<(ostream& os, const CTB3vec<T>& obj)
00531 {
00532 int i_width = os.width();
00533 os << setw(0)
00534 << "{" << setw(i_width) << obj[0]
00535 << "," << setw(i_width) << obj[1]
00536 << "," << setw(i_width) << obj[2] << "}";
00537 return os;
00538 }
00539
00540
00546 template <class T>
00547 T CTBabs(const CTB3vec<T>& vec)
00548 {
00549 return vec.Length();
00550 }
00551