| [658] | 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 | /*!    3-D geometry. 
 | 
|---|
 | 22 | 
 | 
|---|
 | 23 |     All computations are made with angles in radians and with spherical
 | 
|---|
 | 24 |     coordinates theta, phi.
 | 
|---|
 | 25 | 
 | 
|---|
 | 26 |     Concerning Euler's angles, the reference is :
 | 
|---|
 | 27 |  
 | 
|---|
 | 28 |     "Classical Mechanics" 2nd edition, H. Goldstein, Addison Wesley
 | 
|---|
 | 29 | */
 | 
|---|
 | 30 | 
 | 
|---|
 | 31 | class Vector3d 
 | 
|---|
 | 32 | {
 | 
|---|
 | 33 | 
 | 
|---|
 | 34 |  public:
 | 
|---|
 | 35 |   
 | 
|---|
 | 36 |   Vector3d();
 | 
|---|
 | 37 |   Vector3d(double x, double y, double z);
 | 
|---|
 | 38 |   Vector3d(double theta, double phi);
 | 
|---|
 | 39 |   Vector3d(const LongLat&);
 | 
|---|
 | 40 |   Vector3d(const Vector3d&);
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 | //   To manipulate the vector
 | 
|---|
 | 43 |   virtual void Setxyz(double x, double y, double z);
 | 
|---|
 | 44 |   virtual void SetThetaPhi(double theta,  double phi);
 | 
|---|
 | 45 |   virtual void ThetaPhi2xyz();
 | 
|---|
 | 46 |   virtual void xyz2ThetaPhi();
 | 
|---|
 | 47 | 
 | 
|---|
 | 48 | // Acces to coordinates
 | 
|---|
 | 49 |   inline double Theta() const {return _theta;}
 | 
|---|
 | 50 |   inline double Phi() const {return _phi;}
 | 
|---|
 | 51 |   inline double X() const {return _x;}
 | 
|---|
 | 52 |   inline double Y() const {return _y;}
 | 
|---|
 | 53 |   inline double Z() const {return _z;}
 | 
|---|
 | 54 | 
 | 
|---|
 | 55 |   virtual Vector3d& Normalize();
 | 
|---|
 | 56 |   virtual double Norm() const;
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 |   // produit scalaire
 | 
|---|
 | 59 |   virtual double Psc(const Vector3d&) const;
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 |   // ecart angulaire entre 2 vecteurs dans [0,Pi]
 | 
|---|
 | 62 |   /*!   angular gap between 2 vectors in [0,Pi] */
 | 
|---|
 | 63 |   virtual double SepAngle(const Vector3d&) const;
 | 
|---|
 | 64 | 
 | 
|---|
 | 65 |   // produit vectoriel
 | 
|---|
 | 66 |   /*!    vector product */
 | 
|---|
 | 67 |   virtual Vector3d Vect(const Vector3d&) const;
 | 
|---|
 | 68 | 
 | 
|---|
 | 69 |   // vecteur perpendiculaire de meme phi
 | 
|---|
 | 70 |   /*!    perpendicular vector, with equal phi */
 | 
|---|
 | 71 |   virtual Vector3d VperpPhi() const;
 | 
|---|
 | 72 | 
 | 
|---|
 | 73 |   // vecteur perpendiculaire de meme theta
 | 
|---|
 | 74 |   /*!    perpendicular vector with equal theta */
 | 
|---|
 | 75 |   virtual Vector3d VperpTheta() const;
 | 
|---|
 | 76 | 
 | 
|---|
 | 77 |   virtual Vector3d ETheta() const;
 | 
|---|
 | 78 |   virtual Vector3d EPhi() const;
 | 
|---|
 | 79 | 
 | 
|---|
 | 80 |   // rotations d'Euler
 | 
|---|
 | 81 |   /*!    Euler's rotations */
 | 
|---|
 | 82 |   // rotations d Euler
 | 
|---|
 | 83 |   virtual Vector3d Euler(double, double, double) const;
 | 
|---|
 | 84 | 
 | 
|---|
 | 85 |   // rotation inverse
 | 
|---|
 | 86 |   /*!    inverse rotation */
 | 
|---|
 | 87 |   Vector3d InvEuler(double, double, double) const;
 | 
|---|
 | 88 | 
 | 
|---|
 | 89 |   // rotation d'angle phi autour d'un axe omega (regle du tire-bouchon)
 | 
|---|
 | 90 |   /*!    rotation of angle phi around an axis omega (Maxwell's rule) */
 | 
|---|
 | 91 |   Vector3d Rotate(const Vector3d& omega,double phi);
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 |   virtual Vector3d& operator=(const Vector3d&);
 | 
|---|
 | 94 |   virtual Vector3d& operator+=(const Vector3d&);
 | 
|---|
 | 95 |   virtual Vector3d& operator-=(const Vector3d&);
 | 
|---|
 | 96 |   virtual Vector3d operator+(const Vector3d&) const;
 | 
|---|
 | 97 |   virtual Vector3d operator-(const Vector3d&) const;
 | 
|---|
 | 98 | 
 | 
|---|
 | 99 |   virtual Vector3d& operator+=(double);
 | 
|---|
 | 100 |   virtual Vector3d& operator/=(double);
 | 
|---|
 | 101 |   virtual Vector3d& operator*=(double);
 | 
|---|
 | 102 | 
 | 
|---|
 | 103 |   virtual Vector3d operator+(double) const;
 | 
|---|
 | 104 |   virtual Vector3d operator-(double) const;
 | 
|---|
 | 105 |   virtual Vector3d operator*(double) const;
 | 
|---|
 | 106 |   virtual Vector3d operator/(double) const;
 | 
|---|
 | 107 | 
 | 
|---|
 | 108 |   /*!    vector product */
 | 
|---|
 | 109 |   virtual Vector3d operator^(const Vector3d&) const; // produit vectoriel
 | 
|---|
 | 110 |   /*!    dot product */
 | 
|---|
 | 111 |   virtual double operator*(const Vector3d&) const; // produit scalaire
 | 
|---|
 | 112 | 
 | 
|---|
 | 113 |   bool operator==(const Vector3d&);
 | 
|---|
 | 114 |   
 | 
|---|
 | 115 |   virtual void Print(ostream& os) const;
 | 
|---|
 | 116 | 
 | 
|---|
 | 117 |  protected:
 | 
|---|
 | 118 | 
 | 
|---|
 | 119 |   double _x;
 | 
|---|
 | 120 |   double _y;
 | 
|---|
 | 121 |   double _z;
 | 
|---|
 | 122 |   double _theta;
 | 
|---|
 | 123 |   double _phi;
 | 
|---|
 | 124 | 
 | 
|---|
 | 125 | };
 | 
|---|
 | 126 | 
 | 
|---|
 | 127 | inline ostream& operator<<(ostream& s, const Vector3d& v) 
 | 
|---|
 | 128 | {  
 | 
|---|
 | 129 |   v.Print(s);  
 | 
|---|
 | 130 |   return s;  
 | 
|---|
 | 131 | }
 | 
|---|
 | 132 | 
 | 
|---|
 | 133 | // fonctions globales
 | 
|---|
 | 134 | 
 | 
|---|
 | 135 | inline Vector3d operator*(double d, const Vector3d& v) 
 | 
|---|
 | 136 | {
 | 
|---|
 | 137 |   return v*d;
 | 
|---|
 | 138 | }
 | 
|---|
 | 139 | 
 | 
|---|
 | 140 | inline Vector3d operator+(double d, const Vector3d& v) 
 | 
|---|
 | 141 | {
 | 
|---|
 | 142 |   return v+d;
 | 
|---|
 | 143 | }
 | 
|---|
 | 144 | 
 | 
|---|
 | 145 | #endif
 | 
|---|
 | 146 | 
 | 
|---|
 | 147 | 
 | 
|---|