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

Last change on this file since 3506 was 3206, checked in by ansari, 18 years ago

Suppression flags MWERKS (ancien compilo CodeWarrior pour MacOS8,9) , Reza 10/04/2007

File size: 4.7 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/*
53 Geometrie en dimension 3.
54 Tous les calculs sont faits en radians
55 et en coordonnees spheriques theta,phi
56 pour les rotations (angles d'Euler) ma source est
57 B. Revenu / G. Le Meur
58 "Classical Mechanics" 2nd edition, H. Goldstein, Addison Wesley
59*/
60
61class Vector3d
62{
63
64 public:
65
66 Vector3d();
67 Vector3d(double x, double y, double z);
68 Vector3d(double theta, double phi);
69 Vector3d(const LongLat&);
70 Vector3d(const Vector3d&);
71
72// To manipulate the vector
73 virtual void Setxyz(double x, double y, double z);
74 virtual void SetThetaPhi(double theta, double phi);
75 virtual void ThetaPhi2xyz();
76 virtual void xyz2ThetaPhi();
77
78// Acces to coordinates
79 inline double Theta() const {return _theta;}
80 inline double Phi() const {return _phi;}
81 inline double X() const {return _x;}
82 inline double Y() const {return _y;}
83 inline double Z() const {return _z;}
84
85 virtual Vector3d& Normalize();
86 virtual double Norm() const;
87
88 // produit scalaire
89 virtual double Psc(const Vector3d&) const;
90
91 // ecart angulaire entre 2 vecteurs dans [0,Pi]
92 //! angular gap between 2 vectors in [0,Pi]
93 virtual double SepAngle(const Vector3d&) const;
94
95 // produit vectoriel
96 //! return the vector product (*this)^v2
97 virtual Vector3d Vect(const Vector3d& v2) const;
98
99 // vecteur perpendiculaire de meme phi
100 //! return the perpendicular vector, with equal phi
101 virtual Vector3d VperpPhi() const;
102
103 // vecteur perpendiculaire de meme theta
104 //! return the perpendicular vector, with equal theta
105 virtual Vector3d VperpTheta() const;
106
107 virtual Vector3d ETheta() const;
108 virtual Vector3d EPhi() const;
109
110 // rotations d'Euler
111 //! Perform Euler's rotations
112 virtual Vector3d Euler(double, double, double) const;
113
114 // rotation inverse
115 //! perform inverse Euler rotation
116 Vector3d InvEuler(double, double, double) const;
117
118 // rotation d'angle phi autour d'un axe omega (regle du tire-bouchon)
119 //! perform rotation of angle phi around an axis omega (Maxwell's rule)
120 Vector3d Rotate(const Vector3d& omega,double phi) const;
121
122 /*virtual*/ Vector3d& operator=(const Vector3d&); // $CHECK$ EA 101299
123 virtual Vector3d& operator+=(const Vector3d&);
124 virtual Vector3d& operator-=(const Vector3d&);
125 virtual Vector3d operator+(const Vector3d&) const;
126 virtual Vector3d operator-(const Vector3d&) const;
127
128 virtual Vector3d& operator+=(double);
129 virtual Vector3d& operator/=(double);
130 virtual Vector3d& operator*=(double);
131
132 virtual Vector3d operator+(double) const;
133 virtual Vector3d operator-(double) const;
134 virtual Vector3d operator*(double) const;
135 virtual Vector3d operator/(double) const;
136
137 /*! vector product */
138 virtual Vector3d operator^(const Vector3d&) const; // produit vectoriel
139 /*! dot product */
140 virtual double operator*(const Vector3d&) const; // produit scalaire
141
142 bool operator==(const Vector3d&);
143
144 virtual void Print(ostream& os) const;
145
146 protected:
147
148 double _x;
149 double _y;
150 double _z;
151 double _theta;
152 double _phi;
153
154};
155
156inline ostream& operator<<(ostream& s, const Vector3d& v)
157{
158 v.Print(s);
159 return s;
160}
161
162// fonctions globales
163
164inline Vector3d operator*(double d, const Vector3d& v)
165{
166 return v*d;
167}
168
169inline Vector3d operator+(double d, const Vector3d& v)
170{
171 return v+d;
172}
173
174
175} // namespace SOPHYA
176
177#endif
178
179
Note: See TracBrowser for help on using the repository browser.