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

Last change on this file since 3810 was 3786, checked in by ansari, 15 years ago

Ajout des fonctions inline de conversion d'angles, Reza 23/06/2010

File size: 5.1 KB
Line 
1// 3-D Geometry
2// B. Revenu, G. Le Meur 2000
3// R. Ansari 2006
4// DAPNIA/SPP (Saclay) / CEA LAL - IN2P3/CNRS (Orsay)
5
6#ifndef VECTOR3D_H_SEEN
7#define VECTOR3D_H_SEEN
8
9#include <math.h>
10#include <iostream>
11#include <stdio.h>
12#include <string.h>
13
14#include "longlat.h"
15
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
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
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
67 B. Revenu / G. Le Meur
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
82// To manipulate the vector
83 virtual void Setxyz(double x, double y, double z);
84 virtual void SetThetaPhi(double theta, double phi);
85 virtual void ThetaPhi2xyz();
86 virtual void xyz2ThetaPhi();
87
88// Acces to coordinates
89 inline double Theta() const {return _theta;}
90 inline double Phi() const {return _phi;}
91 inline double X() const {return _x;}
92 inline double Y() const {return _y;}
93 inline double Z() const {return _z;}
94
95 virtual Vector3d& Normalize();
96 virtual double Norm() const;
97
98 // produit scalaire
99 virtual double Psc(const Vector3d&) const;
100
101 // ecart angulaire entre 2 vecteurs dans [0,Pi]
102 //! angular gap between 2 vectors in [0,Pi]
103 virtual double SepAngle(const Vector3d&) const;
104
105 // produit vectoriel
106 //! return the vector product (*this)^v2
107 virtual Vector3d Vect(const Vector3d& v2) const;
108
109 // vecteur perpendiculaire de meme phi
110 //! return the perpendicular vector, with equal phi
111 virtual Vector3d VperpPhi() const;
112
113 // vecteur perpendiculaire de meme theta
114 //! return the perpendicular vector, with equal theta
115 virtual Vector3d VperpTheta() const;
116
117 virtual Vector3d ETheta() const;
118 virtual Vector3d EPhi() const;
119
120 // rotations d'Euler
121 //! Perform Euler's rotations
122 virtual Vector3d Euler(double, double, double) const;
123
124 // rotation inverse
125 //! perform inverse Euler rotation
126 Vector3d InvEuler(double, double, double) const;
127
128 // rotation d'angle phi autour d'un axe omega (regle du tire-bouchon)
129 //! perform rotation of angle phi around an axis omega (Maxwell's rule)
130 Vector3d Rotate(const Vector3d& omega,double phi) const;
131
132 /*virtual*/ Vector3d& operator=(const Vector3d&); // $CHECK$ EA 101299
133 virtual Vector3d& operator+=(const Vector3d&);
134 virtual Vector3d& operator-=(const Vector3d&);
135 virtual Vector3d operator+(const Vector3d&) const;
136 virtual Vector3d operator-(const Vector3d&) const;
137
138 virtual Vector3d& operator+=(double);
139 virtual Vector3d& operator/=(double);
140 virtual Vector3d& operator*=(double);
141
142 virtual Vector3d operator+(double) const;
143 virtual Vector3d operator-(double) const;
144 virtual Vector3d operator*(double) const;
145 virtual Vector3d operator/(double) const;
146
147 /*! vector product */
148 virtual Vector3d operator^(const Vector3d&) const; // produit vectoriel
149 /*! dot product */
150 virtual double operator*(const Vector3d&) const; // produit scalaire
151
152 bool operator==(const Vector3d&);
153
154 virtual void Print(ostream& os) const;
155
156 protected:
157
158 double _x;
159 double _y;
160 double _z;
161 double _theta;
162 double _phi;
163
164};
165
166inline ostream& operator<<(ostream& s, const Vector3d& v)
167{
168 v.Print(s);
169 return s;
170}
171
172// fonctions globales
173
174inline Vector3d operator*(double d, const Vector3d& v)
175{
176 return v*d;
177}
178
179inline Vector3d operator+(double d, const Vector3d& v)
180{
181 return v+d;
182}
183
184
185} // namespace SOPHYA
186
187#endif
188
189
Note: See TracBrowser for help on using the repository browser.