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