source: Sophya/trunk/SophyaLib/Samba/unitvec.h@ 254

Last change on this file since 254 was 228, checked in by ansari, 26 years ago

Creation du module DPC/Samba Reza 13/04/99

File size: 1.9 KB
Line 
1#ifndef UNITVEC_H_SEEN
2#define UNIITVEC_H_SEEN
3
4#include <math.h>
5#include <iostream.h>
6
7
8
9// Classe pour faire des vecteurs normes x,y,z a partir de Teta,Phi
10// et l inverse. On peut calculer le produit scalaire et les vecteurs
11// perpendiculaires.
12// Exemple:
13// UnitVector u1(0.5, 0.7); // Vers Teta=0.5 Phi = 0.7 Rad.
14// UnitVector u2(1.,2.,1.); // Vecteur norme parallele a (x=1., y=2., z=1.)
15// u2.Teta(); // Direction teta de u2
16// u1.psc(u2); // u1 prod. scalaire u2
17// UnitVector vp1 = u2.vperp(); // Vecteur perpendiculaire a u1 , meme phi (ou a 180 deg)
18// UnitVector vp2 = u2.vperp2(); // Vecteur perpendiculaire a u1 , a phi+90 deg
19
20//
21class UnitVector {
22public:
23 UnitVector(double teta=0., double phi=0.)
24 { set(teta, phi); }
25 UnitVector(double vx, double vy, double vz)
26 { setxyz(vx, vy, vz); }
27
28 inline void set(double teta, double phi)
29 { t=teta; p=phi; z = cos(teta); x = sin(teta)*cos(phi); y = sin(teta)*sin(phi); }
30 inline void setxyz(double vx, double vy, double vz)
31 { double r = sqrt(vx*vx+vy*vy+vz*vz); x = vx/r; y = vy/r; z = vz/r;
32 t = acos(z); p = atan2(y,x); }
33
34 inline double psc(UnitVector& u) { return(x*u.x+y*u.y+z*u.z); }
35
36 inline double Teta() { return(t); }
37 inline double Phi() { return(p); }
38 inline double X() { return(x); }
39 inline double Y() { return(y); }
40 inline double Z() { return(z); }
41
42 inline UnitVector vperp() {double tp, pp; pp = p;
43 tp = t+0.5*M_PI; if (tp > M_PI) { tp = tp-M_PI; pp += M_PI*0.5; }
44 return(UnitVector(tp, pp)); }
45 inline UnitVector vperp2() {double tp, pp; tp = M_PI*0.5; pp = p + 0.5*M_PI;
46 return(UnitVector(tp, pp)); }
47
48 inline friend ostream& operator << (ostream& s, UnitVector const& u)
49 { s << "UnitVector: X,Y,Z= (" << u.x << "," << u.y << "," << u.z
50 << ") Teta,Phi= " << u.t << "," << u.p << endl ; return(s); }
51
52 double x,y,z;
53 double t,p;
54};
55
56
57#endif
Note: See TracBrowser for help on using the repository browser.