Changeset 2973 in Sophya for trunk/SophyaLib/SkyMap/vector3d.cc
- Timestamp:
- Jun 20, 2006, 6:01:49 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/SkyMap/vector3d.cc
r2615 r2973 1 // Classes Angle Vector3d 2 // B. Revenu , G. Le Meur 2000 3 // R. Ansari 2006 4 // LAL (Orsay) / IN2P3-CNRS DAPNIA/SPP (Saclay) / CEA 5 1 6 #include "sopnamsp.h" 2 7 #include "machdefs.h" … … 5 10 #include "vector3d.h" 6 11 #include "utilgeom.h" 7 //++ 8 // Class Vector3d 9 // 10 // include vector3d.h utilgeom.h longlat.h math.h 11 // 12 // 13 // 3-D geometry. 14 // All computations are made with angles in radians and with spherical 15 // coordinates theta, phi. 16 // 17 // Concerning Euler's angles, the reference is : 18 // 19 // "Classical Mechanics" 2nd edition, H. Goldstein, Addison Wesley 20 //-- 21 //++ 22 // Titre Constructors 23 //-- 24 //++ 12 13 // Class de conversion d'angles R. Ansari , Juin 2006 14 double Angle::_deg2rad = M_PI/180.; 15 double Angle::_rad2deg = 180./M_PI; 16 double Angle::_rad2min = 180./M_PI*60.; 17 double Angle::_rad2sec = 180./M_PI*3600.; 18 19 /*! 20 \class SOPHYA::Angle 21 \ingroup SkyMap 22 \brief Class to ease angle conversions (radian <> degree <> arcmin <> arcsec). 23 The angle value is kept in radians internally. 24 \code 25 // Example to convert 0.035 radians to arcsec 26 double vr = 0.035; 27 cout << "Angle rad= " << vr << " ->arcsec= " << Angle(vr).ToArcSec() << endl; 28 // Example to convert 2.3 arcmin to radian - we use the conversion operator 29 double vam = 2.3; 30 cout << "Angle arcmin= " << vam << " ->rad= " 31 << (double)Angle(vam, Angle::ArcMin) << endl; 32 \endcode 33 34 */ 35 36 Angle::Angle(double val, Angle::AngleUnit un) 37 { 38 switch (un) { 39 case Angle::Radian : 40 _angrad = val; 41 break; 42 case Angle::Degree : 43 _angrad = val*_deg2rad; 44 break; 45 case Angle::ArcMin : 46 _angrad = val/_rad2min; 47 break; 48 case Angle::ArcSec : 49 _angrad = val/_rad2sec; 50 break; 51 default: 52 _angrad = val; 53 break; 54 } 55 } 56 57 // 3-D Geometry 58 // B. Revenu, G. Le Meur 2000 59 // DAPNIA/SPP (Saclay) / CEA LAL - IN2P3/CNRS (Orsay) 60 61 /*! 62 \class SOPHYA::Vector3d 63 \ingroup SkyMap 64 \brief 3-D geometry. 65 All computations are made with angles in radians and with spherical 66 coordinates theta, phi. 67 Concerning Euler's angles, the reference is : 68 69 "Classical Mechanics" 2nd edition, H. Goldstein, Addison Wesley 70 */ 71 72 //! default constructor - unit vector along x direction 25 73 Vector3d::Vector3d() 26 //27 //--28 74 { 29 75 Setxyz(1.,0.,0.); 30 76 } 31 //++ 77 78 //! Constructor with specification of cartesian coordinates 32 79 Vector3d::Vector3d(double x, double y, double z) 33 //34 //--35 80 { 36 81 _x=x; … … 39 84 xyz2ThetaPhi(); 40 85 } 41 // ++86 //! Constructor: unit vector with direction (spherical coordinates) specification 42 87 Vector3d::Vector3d(double theta, double phi) 43 //44 //--45 88 { 46 89 // _theta=mod(theta,M_PI); // dans [0;pi] … … 55 98 ThetaPhi2xyz(); 56 99 } 57 //++ 100 101 //! Constructor: unit vector with longitude-latitude specification 58 102 Vector3d::Vector3d(const LongLat& ll) 59 //60 //--61 103 { 62 104 _theta=ll.Theta(); // dans [0;pi] … … 64 106 ThetaPhi2xyz(); 65 107 } 66 //++ 108 109 //! Copy constructor 67 110 Vector3d::Vector3d(const Vector3d& v) 68 //69 //--70 111 { 71 112 _x=v._x; … … 75 116 _phi=v._phi; 76 117 } 77 //++ 78 // Titre Public methods 79 //-- 80 //++ 81 void Vector3d::SetThetaPhi(double theta, double phi) 82 // 83 //-- 118 119 //! Set/changes the vector direction (result is a unit vector) 120 void Vector3d::SetThetaPhi(double theta, double phi) 84 121 { 85 122 _theta=mod(theta,M_PI); … … 87 124 ThetaPhi2xyz(); 88 125 } 89 //++ 126 127 //! Set/changes the vector specifying cartesian coordinates 90 128 void Vector3d::Setxyz(double x, double y, double z) 91 //92 //--93 129 { 94 130 _x=x; … … 125 161 } 126 162 } 127 // ++163 //! Normalize the vector (-> unit length) for non zero vectors 128 164 Vector3d& Vector3d::Normalize() 129 //130 //--131 165 { 132 166 double norm=this->Norm(); 133 167 if( norm != 0. ) (*this)/=norm; 134 else cerr << "Division par zero" << endl;168 //DEL else cerr << "Division par zero" << endl; 135 169 return *this; 136 170 } 137 //++ 171 172 //! Return the vector norm (length) 138 173 double Vector3d::Norm() const 139 //140 //--141 174 { 142 175 return sqrt(_x*_x+_y*_y+_z*_z); 143 176 } 144 //++ 177 178 //! Return the scalar (dot) product of the two vectors 145 179 double Vector3d::Psc(const Vector3d& v) const 146 //147 // dot product148 //--149 180 { 150 181 return _x*v._x+_y*v._y+_z*v._z;
Note:
See TracChangeset
for help on using the changeset viewer.