[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__
|
---|
| 9 | #include "mwerksmath.h"
|
---|
| 10 | // #include "unixmac.h"
|
---|
| 11 | #endif
|
---|
[262] | 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 | */
|
---|
[565] | 21 | /*! 3-D geometry.
|
---|
[262] | 22 |
|
---|
[565] | 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 |
|
---|
[262] | 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 |
|
---|
[518] | 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();
|
---|
[262] | 47 |
|
---|
[518] | 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;}
|
---|
[262] | 54 |
|
---|
[518] | 55 | virtual Vector3d& Normalize();
|
---|
| 56 | virtual double Norm() const;
|
---|
| 57 |
|
---|
[262] | 58 | // produit scalaire
|
---|
[518] | 59 | virtual double Psc(const Vector3d&) const;
|
---|
[262] | 60 |
|
---|
| 61 | // ecart angulaire entre 2 vecteurs dans [0,Pi]
|
---|
[565] | 62 | /*! angular gap between 2 vectors in [0,Pi] */
|
---|
[518] | 63 | virtual double SepAngle(const Vector3d&) const;
|
---|
[262] | 64 |
|
---|
| 65 | // produit vectoriel
|
---|
[565] | 66 | /*! vector product */
|
---|
[518] | 67 | virtual Vector3d Vect(const Vector3d&) const;
|
---|
[262] | 68 |
|
---|
| 69 | // vecteur perpendiculaire de meme phi
|
---|
[565] | 70 | /*! perpendicular vector, with equal phi */
|
---|
[518] | 71 | virtual Vector3d VperpPhi() const;
|
---|
[262] | 72 |
|
---|
| 73 | // vecteur perpendiculaire de meme theta
|
---|
[565] | 74 | /*! perpendicular vector with equal theta */
|
---|
[518] | 75 | virtual Vector3d VperpTheta() const;
|
---|
[262] | 76 |
|
---|
[518] | 77 | virtual Vector3d ETheta() const;
|
---|
| 78 | virtual Vector3d EPhi() const;
|
---|
[262] | 79 |
|
---|
[565] | 80 | // rotations d'Euler
|
---|
| 81 | /*! Euler's rotations */
|
---|
[518] | 82 | // rotations d Euler
|
---|
| 83 | virtual Vector3d Euler(double, double, double) const;
|
---|
[262] | 84 |
|
---|
| 85 | // rotation inverse
|
---|
[565] | 86 | /*! inverse rotation */
|
---|
[262] | 87 | Vector3d InvEuler(double, double, double) const;
|
---|
| 88 |
|
---|
[565] | 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) */
|
---|
[262] | 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 |
|
---|
[518] | 99 | virtual Vector3d& operator+=(double);
|
---|
| 100 | virtual Vector3d& operator/=(double);
|
---|
| 101 | virtual Vector3d& operator*=(double);
|
---|
[262] | 102 |
|
---|
[518] | 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 |
|
---|
[565] | 108 | /*! vector product */
|
---|
[518] | 109 | virtual Vector3d operator^(const Vector3d&) const; // produit vectoriel
|
---|
[565] | 110 | /*! dot product */
|
---|
[518] | 111 | virtual double operator*(const Vector3d&) const; // produit scalaire
|
---|
| 112 |
|
---|
[262] | 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 |
|
---|