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