source: Sophya/trunk/SophyaLib/SkyMap/vector3d.h@ 4042

Last change on this file since 4042 was 3866, checked in by ansari, 15 years ago

Ajout destructeur virtuel Vector3d,UnitVector, Reza 12/08/2010

File size: 5.1 KB
RevLine 
[1371]1// 3-D Geometry
2// B. Revenu, G. Le Meur 2000
[2973]3// R. Ansari 2006
[1371]4// DAPNIA/SPP (Saclay) / CEA LAL - IN2P3/CNRS (Orsay)
5
[764]6#ifndef VECTOR3D_H_SEEN
7#define VECTOR3D_H_SEEN
8
9#include <math.h>
[2322]10#include <iostream>
[764]11#include <stdio.h>
12#include <string.h>
[3206]13
[764]14#include "longlat.h"
15
[2973]16
17namespace SOPHYA {
18
19//! Class to ease angle conversions (radian <> degree <> arcmin <> arcsec)
20class Angle {
21public:
22 enum AngleUnit { Radian, Degree, ArcMin, ArcSec };
23 //! Constructor with specification of angle value in radian
24 Angle(double val=0.) { _angrad = val; }
25 //! Constructor with specification of angle value and unit
26 Angle(double val, Angle::AngleUnit un);
27 //! Copy constructor
28 Angle(Angle const& a) { _angrad = a._angrad; }
29
30 //! Conversion to radian
31 inline double ToRadian() const { return _angrad; }
32 //! Conversion to degree
33 inline double ToDegree() const { return _angrad*_rad2deg; }
34 //! Conversion to arcmin
35 inline double ToArcMin() const { return _angrad*_rad2min; }
36 //! Conversion to arcsec
37 inline double ToArcSec() const { return _angrad*_rad2sec; }
38
39 //! return the angle value in radian
40 inline operator double () const { return _angrad; }
41
42protected:
43 double _angrad; // angle in radians
44
45 static double _deg2rad; // deg -> radian conversion factor
46 static double _rad2deg; // rad -> degree conversion factor
47 static double _rad2min; // rad -> arcmin conversion factor
48 static double _rad2sec; // rad -> arcmin conversion factor
49
50};
51
[3786]52//! Angle conversion: Radian to degree
53inline double RadianToDegree(double ar)
54{ return Angle(ar).ToDegree(); }
55//! Angle conversion: Degree to radian
56inline double DegreeToRadian(double ad)
57{ return Angle(ad,Angle::Degree).ToRadian(); }
58//! Angle conversion: Arcminute to radian
59inline double ArcminToRadian(double aam)
60{ return Angle(aam,Angle::ArcMin).ToRadian(); }
61
[764]62/*
63 Geometrie en dimension 3.
64 Tous les calculs sont faits en radians
65 et en coordonnees spheriques theta,phi
66 pour les rotations (angles d'Euler) ma source est
[2973]67 B. Revenu / G. Le Meur
[764]68 "Classical Mechanics" 2nd edition, H. Goldstein, Addison Wesley
69*/
70
71class Vector3d
72{
73
74 public:
75
76 Vector3d();
77 Vector3d(double x, double y, double z);
78 Vector3d(double theta, double phi);
79 Vector3d(const LongLat&);
80 Vector3d(const Vector3d&);
81
[3866]82 virtual ~Vector3d() { }
83
[764]84// To manipulate the vector
85 virtual void Setxyz(double x, double y, double z);
86 virtual void SetThetaPhi(double theta, double phi);
87 virtual void ThetaPhi2xyz();
88 virtual void xyz2ThetaPhi();
89
90// Acces to coordinates
91 inline double Theta() const {return _theta;}
92 inline double Phi() const {return _phi;}
93 inline double X() const {return _x;}
94 inline double Y() const {return _y;}
95 inline double Z() const {return _z;}
96
97 virtual Vector3d& Normalize();
98 virtual double Norm() const;
99
100 // produit scalaire
101 virtual double Psc(const Vector3d&) const;
102
103 // ecart angulaire entre 2 vecteurs dans [0,Pi]
[2973]104 //! angular gap between 2 vectors in [0,Pi]
[764]105 virtual double SepAngle(const Vector3d&) const;
106
107 // produit vectoriel
[2973]108 //! return the vector product (*this)^v2
109 virtual Vector3d Vect(const Vector3d& v2) const;
[764]110
111 // vecteur perpendiculaire de meme phi
[2973]112 //! return the perpendicular vector, with equal phi
[764]113 virtual Vector3d VperpPhi() const;
114
115 // vecteur perpendiculaire de meme theta
[2973]116 //! return the perpendicular vector, with equal theta
[764]117 virtual Vector3d VperpTheta() const;
118
119 virtual Vector3d ETheta() const;
120 virtual Vector3d EPhi() const;
121
122 // rotations d'Euler
[2973]123 //! Perform Euler's rotations
[764]124 virtual Vector3d Euler(double, double, double) const;
125
126 // rotation inverse
[2973]127 //! perform inverse Euler rotation
[764]128 Vector3d InvEuler(double, double, double) const;
129
130 // rotation d'angle phi autour d'un axe omega (regle du tire-bouchon)
[2973]131 //! perform rotation of angle phi around an axis omega (Maxwell's rule)
[792]132 Vector3d Rotate(const Vector3d& omega,double phi) const;
[764]133
134 /*virtual*/ Vector3d& operator=(const Vector3d&); // $CHECK$ EA 101299
135 virtual Vector3d& operator+=(const Vector3d&);
136 virtual Vector3d& operator-=(const Vector3d&);
137 virtual Vector3d operator+(const Vector3d&) const;
138 virtual Vector3d operator-(const Vector3d&) const;
139
140 virtual Vector3d& operator+=(double);
141 virtual Vector3d& operator/=(double);
142 virtual Vector3d& operator*=(double);
143
144 virtual Vector3d operator+(double) const;
145 virtual Vector3d operator-(double) const;
146 virtual Vector3d operator*(double) const;
147 virtual Vector3d operator/(double) const;
148
149 /*! vector product */
150 virtual Vector3d operator^(const Vector3d&) const; // produit vectoriel
151 /*! dot product */
152 virtual double operator*(const Vector3d&) const; // produit scalaire
153
154 bool operator==(const Vector3d&);
155
156 virtual void Print(ostream& os) const;
157
158 protected:
159
160 double _x;
161 double _y;
162 double _z;
163 double _theta;
164 double _phi;
165
166};
167
168inline ostream& operator<<(ostream& s, const Vector3d& v)
169{
170 v.Print(s);
171 return s;
172}
173
174// fonctions globales
175
176inline Vector3d operator*(double d, const Vector3d& v)
177{
178 return v*d;
179}
180
181inline Vector3d operator+(double d, const Vector3d& v)
182{
183 return v+d;
184}
185
[2973]186
[1371]187} // namespace SOPHYA
188
[764]189#endif
190
191
Note: See TracBrowser for help on using the repository browser.