| [1371] | 1 | //   3-D Geometry | 
|---|
|  | 2 | //        B. Revenu, G. Le Meur   2000 | 
|---|
|  | 3 | // DAPNIA/SPP (Saclay) / CEA    LAL - IN2P3/CNRS  (Orsay) | 
|---|
|  | 4 |  | 
|---|
| [764] | 5 | #ifndef VECTOR3D_H_SEEN | 
|---|
|  | 6 | #define VECTOR3D_H_SEEN | 
|---|
|  | 7 |  | 
|---|
|  | 8 | #include <math.h> | 
|---|
|  | 9 | #include <iostream.h> | 
|---|
|  | 10 | #include <stdio.h> | 
|---|
|  | 11 | #include <string.h> | 
|---|
|  | 12 | #ifdef __MWERKS__ | 
|---|
|  | 13 | #include "unixmac.h" | 
|---|
|  | 14 | #endif | 
|---|
|  | 15 | #include "longlat.h" | 
|---|
|  | 16 |  | 
|---|
|  | 17 | /* | 
|---|
|  | 18 | Geometrie en dimension 3. | 
|---|
|  | 19 | Tous les calculs sont faits en radians | 
|---|
|  | 20 | et en coordonnees spheriques theta,phi | 
|---|
|  | 21 | pour les rotations (angles d'Euler) ma source est | 
|---|
|  | 22 | "Classical Mechanics" 2nd edition, H. Goldstein, Addison Wesley | 
|---|
|  | 23 | */ | 
|---|
|  | 24 | /*!    3-D geometry. | 
|---|
|  | 25 |  | 
|---|
|  | 26 | All computations are made with angles in radians and with spherical | 
|---|
|  | 27 | coordinates theta, phi. | 
|---|
|  | 28 |  | 
|---|
|  | 29 | Concerning Euler's angles, the reference is : | 
|---|
|  | 30 |  | 
|---|
|  | 31 | "Classical Mechanics" 2nd edition, H. Goldstein, Addison Wesley | 
|---|
|  | 32 | */ | 
|---|
|  | 33 |  | 
|---|
| [1371] | 34 | namespace SOPHYA { | 
|---|
|  | 35 |  | 
|---|
| [764] | 36 | class Vector3d | 
|---|
|  | 37 | { | 
|---|
|  | 38 |  | 
|---|
|  | 39 | public: | 
|---|
|  | 40 |  | 
|---|
|  | 41 | Vector3d(); | 
|---|
|  | 42 | Vector3d(double x, double y, double z); | 
|---|
|  | 43 | Vector3d(double theta, double phi); | 
|---|
|  | 44 | Vector3d(const LongLat&); | 
|---|
|  | 45 | Vector3d(const Vector3d&); | 
|---|
|  | 46 |  | 
|---|
|  | 47 | //   To manipulate the vector | 
|---|
|  | 48 | virtual void Setxyz(double x, double y, double z); | 
|---|
|  | 49 | virtual void SetThetaPhi(double theta,  double phi); | 
|---|
|  | 50 | virtual void ThetaPhi2xyz(); | 
|---|
|  | 51 | virtual void xyz2ThetaPhi(); | 
|---|
|  | 52 |  | 
|---|
|  | 53 | // Acces to coordinates | 
|---|
|  | 54 | inline double Theta() const {return _theta;} | 
|---|
|  | 55 | inline double Phi() const {return _phi;} | 
|---|
|  | 56 | inline double X() const {return _x;} | 
|---|
|  | 57 | inline double Y() const {return _y;} | 
|---|
|  | 58 | inline double Z() const {return _z;} | 
|---|
|  | 59 |  | 
|---|
|  | 60 | virtual Vector3d& Normalize(); | 
|---|
|  | 61 | virtual double Norm() const; | 
|---|
|  | 62 |  | 
|---|
|  | 63 | // produit scalaire | 
|---|
|  | 64 | virtual double Psc(const Vector3d&) const; | 
|---|
|  | 65 |  | 
|---|
|  | 66 | // ecart angulaire entre 2 vecteurs dans [0,Pi] | 
|---|
|  | 67 | /*!   angular gap between 2 vectors in [0,Pi] */ | 
|---|
|  | 68 | virtual double SepAngle(const Vector3d&) const; | 
|---|
|  | 69 |  | 
|---|
|  | 70 | // produit vectoriel | 
|---|
|  | 71 | /*!    vector product */ | 
|---|
|  | 72 | virtual Vector3d Vect(const Vector3d&) const; | 
|---|
|  | 73 |  | 
|---|
|  | 74 | // vecteur perpendiculaire de meme phi | 
|---|
|  | 75 | /*!    perpendicular vector, with equal phi */ | 
|---|
|  | 76 | virtual Vector3d VperpPhi() const; | 
|---|
|  | 77 |  | 
|---|
|  | 78 | // vecteur perpendiculaire de meme theta | 
|---|
|  | 79 | /*!    perpendicular vector with equal theta */ | 
|---|
|  | 80 | virtual Vector3d VperpTheta() const; | 
|---|
|  | 81 |  | 
|---|
|  | 82 | virtual Vector3d ETheta() const; | 
|---|
|  | 83 | virtual Vector3d EPhi() const; | 
|---|
|  | 84 |  | 
|---|
|  | 85 | // rotations d'Euler | 
|---|
|  | 86 | /*!    Euler's rotations */ | 
|---|
|  | 87 | // rotations d Euler | 
|---|
|  | 88 | virtual Vector3d Euler(double, double, double) const; | 
|---|
|  | 89 |  | 
|---|
|  | 90 | // rotation inverse | 
|---|
|  | 91 | /*!    inverse rotation */ | 
|---|
|  | 92 | Vector3d InvEuler(double, double, double) const; | 
|---|
|  | 93 |  | 
|---|
|  | 94 | // rotation d'angle phi autour d'un axe omega (regle du tire-bouchon) | 
|---|
|  | 95 | /*!    rotation of angle phi around an axis omega (Maxwell's rule) */ | 
|---|
| [792] | 96 | Vector3d Rotate(const Vector3d& omega,double phi) const; | 
|---|
| [764] | 97 |  | 
|---|
|  | 98 | /*virtual*/ Vector3d& operator=(const Vector3d&); // $CHECK$ EA 101299 | 
|---|
|  | 99 | virtual Vector3d& operator+=(const Vector3d&); | 
|---|
|  | 100 | virtual Vector3d& operator-=(const Vector3d&); | 
|---|
|  | 101 | virtual Vector3d operator+(const Vector3d&) const; | 
|---|
|  | 102 | virtual Vector3d operator-(const Vector3d&) const; | 
|---|
|  | 103 |  | 
|---|
|  | 104 | virtual Vector3d& operator+=(double); | 
|---|
|  | 105 | virtual Vector3d& operator/=(double); | 
|---|
|  | 106 | virtual Vector3d& operator*=(double); | 
|---|
|  | 107 |  | 
|---|
|  | 108 | virtual Vector3d operator+(double) const; | 
|---|
|  | 109 | virtual Vector3d operator-(double) const; | 
|---|
|  | 110 | virtual Vector3d operator*(double) const; | 
|---|
|  | 111 | virtual Vector3d operator/(double) const; | 
|---|
|  | 112 |  | 
|---|
|  | 113 | /*!    vector product */ | 
|---|
|  | 114 | virtual Vector3d operator^(const Vector3d&) const; // produit vectoriel | 
|---|
|  | 115 | /*!    dot product */ | 
|---|
|  | 116 | virtual double operator*(const Vector3d&) const; // produit scalaire | 
|---|
|  | 117 |  | 
|---|
|  | 118 | bool operator==(const Vector3d&); | 
|---|
|  | 119 |  | 
|---|
|  | 120 | virtual void Print(ostream& os) const; | 
|---|
|  | 121 |  | 
|---|
|  | 122 | protected: | 
|---|
|  | 123 |  | 
|---|
|  | 124 | double _x; | 
|---|
|  | 125 | double _y; | 
|---|
|  | 126 | double _z; | 
|---|
|  | 127 | double _theta; | 
|---|
|  | 128 | double _phi; | 
|---|
|  | 129 |  | 
|---|
|  | 130 | }; | 
|---|
|  | 131 |  | 
|---|
|  | 132 | inline ostream& operator<<(ostream& s, const Vector3d& v) | 
|---|
|  | 133 | { | 
|---|
|  | 134 | v.Print(s); | 
|---|
|  | 135 | return s; | 
|---|
|  | 136 | } | 
|---|
|  | 137 |  | 
|---|
|  | 138 | // fonctions globales | 
|---|
|  | 139 |  | 
|---|
|  | 140 | inline Vector3d operator*(double d, const Vector3d& v) | 
|---|
|  | 141 | { | 
|---|
|  | 142 | return v*d; | 
|---|
|  | 143 | } | 
|---|
|  | 144 |  | 
|---|
|  | 145 | inline Vector3d operator+(double d, const Vector3d& v) | 
|---|
|  | 146 | { | 
|---|
|  | 147 | return v+d; | 
|---|
|  | 148 | } | 
|---|
|  | 149 |  | 
|---|
| [1371] | 150 | } // namespace SOPHYA | 
|---|
|  | 151 |  | 
|---|
| [764] | 152 | #endif | 
|---|
|  | 153 |  | 
|---|
|  | 154 |  | 
|---|