1 | #ifndef VECTOR3D_H_SEEN
|
---|
2 | #define VECTOR3D_H_SEEN
|
---|
3 |
|
---|
4 | #include <math.h>
|
---|
5 | #include <iostream.h>
|
---|
6 | #include <stdio.h>
|
---|
7 | #include <string.h>
|
---|
8 | #ifdef __MWERKS__
|
---|
9 | #include "mwerksmath.h"
|
---|
10 | // #include "unixmac.h"
|
---|
11 | #endif
|
---|
12 | #include "longlat.h"
|
---|
13 |
|
---|
14 | /*
|
---|
15 | Geometrie en dimension 3.
|
---|
16 | Tous les calculs sont faits en radians
|
---|
17 | et en coordonnees spheriques theta,phi
|
---|
18 | pour les rotations (angles d'Euler) ma source est
|
---|
19 | "Classical Mechanics" 2nd edition, H. Goldstein, Addison Wesley
|
---|
20 | */
|
---|
21 |
|
---|
22 | class Vector3d
|
---|
23 | {
|
---|
24 |
|
---|
25 | public:
|
---|
26 |
|
---|
27 | Vector3d();
|
---|
28 | Vector3d(double x, double y, double z);
|
---|
29 | Vector3d(double theta, double phi);
|
---|
30 | Vector3d(const LongLat&);
|
---|
31 | Vector3d(const Vector3d&);
|
---|
32 |
|
---|
33 | void Setxyz(double x, double y, double z);
|
---|
34 | void SetThetaPhi(double theta, double phi);
|
---|
35 | void ThetaPhi2xyz();
|
---|
36 | void xyz2ThetaPhi();
|
---|
37 | double Theta() const {return _theta;}
|
---|
38 | double Phi() const {return _phi;}
|
---|
39 | double X() const {return _x;}
|
---|
40 | double Y() const {return _y;}
|
---|
41 | double Z() const {return _z;}
|
---|
42 |
|
---|
43 | Vector3d& Normalize();
|
---|
44 | double Norm() const;
|
---|
45 |
|
---|
46 | // produit scalaire
|
---|
47 | double Psc(const Vector3d&) const;
|
---|
48 |
|
---|
49 | // ecart angulaire entre 2 vecteurs dans [0,Pi]
|
---|
50 | double SepAngle(const Vector3d&) const;
|
---|
51 |
|
---|
52 | // produit vectoriel
|
---|
53 | Vector3d Vect(const Vector3d&) const;
|
---|
54 |
|
---|
55 | // vecteur perpendiculaire de meme phi
|
---|
56 | Vector3d VperpPhi() const;
|
---|
57 |
|
---|
58 | // vecteur perpendiculaire de meme theta
|
---|
59 | Vector3d VperpTheta() const;
|
---|
60 |
|
---|
61 | Vector3d ETheta() const;
|
---|
62 | Vector3d EPhi() const;
|
---|
63 |
|
---|
64 | // rotations d'Euler
|
---|
65 | Vector3d Euler(double, double, double) const;
|
---|
66 |
|
---|
67 | // rotation inverse
|
---|
68 | Vector3d InvEuler(double, double, double) const;
|
---|
69 |
|
---|
70 | // rotation d'angle phi autour d'un axe omega (regle du tire-bouchon)
|
---|
71 | Vector3d Rotate(const Vector3d& omega,double phi);
|
---|
72 |
|
---|
73 | virtual Vector3d& operator=(const Vector3d&);
|
---|
74 | virtual Vector3d& operator+=(const Vector3d&);
|
---|
75 | virtual Vector3d& operator-=(const Vector3d&);
|
---|
76 | virtual Vector3d operator+(const Vector3d&) const;
|
---|
77 | virtual Vector3d operator-(const Vector3d&) const;
|
---|
78 |
|
---|
79 | Vector3d& operator+=(double);
|
---|
80 | Vector3d& operator/=(double);
|
---|
81 | Vector3d& operator*=(double);
|
---|
82 |
|
---|
83 | Vector3d operator+(double) const;
|
---|
84 | Vector3d operator-(double) const;
|
---|
85 | Vector3d operator*(double) const;
|
---|
86 | Vector3d operator/(double) const;
|
---|
87 | Vector3d operator^(const Vector3d&) const; // produit vectoriel
|
---|
88 | double operator*(const Vector3d&) const; // produit scalaire
|
---|
89 | bool operator==(const Vector3d&);
|
---|
90 |
|
---|
91 | virtual void Print(ostream& os) const;
|
---|
92 |
|
---|
93 | protected:
|
---|
94 |
|
---|
95 | double _x;
|
---|
96 | double _y;
|
---|
97 | double _z;
|
---|
98 | double _theta;
|
---|
99 | double _phi;
|
---|
100 |
|
---|
101 | };
|
---|
102 |
|
---|
103 | inline ostream& operator<<(ostream& s, const Vector3d& v)
|
---|
104 | {
|
---|
105 | v.Print(s);
|
---|
106 | return s;
|
---|
107 | }
|
---|
108 |
|
---|
109 | // fonctions globales
|
---|
110 |
|
---|
111 | inline Vector3d operator*(double d, const Vector3d& v)
|
---|
112 | {
|
---|
113 | return v*d;
|
---|
114 | }
|
---|
115 |
|
---|
116 | inline Vector3d operator+(double d, const Vector3d& v)
|
---|
117 | {
|
---|
118 | return v+d;
|
---|
119 | }
|
---|
120 |
|
---|
121 | #endif
|
---|
122 |
|
---|
123 |
|
---|