Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef Angle_H
00030 #define Angle_H
00031
00032 #include <math.h>
00033
00034 #include "Trace.h"
00035 #include "QGpCoreToolsDLLExport.h"
00036
00037 namespace QGpCoreTools {
00038
00039 class Point2D;
00040
00041 class QGPCORETOOLS_EXPORT Angle
00042 {
00043 public:
00044 inline Angle();
00045 Angle(double dx, double dy) {set(dx, dy);}
00046 inline Angle(double dx, double dy, double r) {set(dx,dy,r);}
00047 ~Angle() {}
00048
00049 inline Angle& operator=(const Angle& o);
00050 bool operator<(const Angle& o) const {return _rad<o._rad;}
00051 bool operator==(const Angle& o) const {return _rad==o._rad;}
00052 void operator+=(const Angle& o);
00053 bool isNull() const {return _rad==0.0;}
00054
00055 inline void set(double dx, double dy);
00056 inline void set(double dx, double dy, double r);
00057 void setDegreeAzimuth(double azimuth) {setDegrees(90.0-azimuth);}
00058 void setRadianAzimuth(double azimuth) {setRadians(0.5*M_PI-azimuth);}
00059 inline void setDegrees(double degrees);
00060 inline void setRadians(double radians);
00061
00062 inline void initDegrees();
00063 inline void initRadians();
00064
00065 double degrees() const {return _deg;}
00066 double radians() const {return _rad;}
00067 double cos() const {return _cos;}
00068 double sin() const {return _sin;}
00069 double tan() const {return _sin/_cos;}
00070 double cotan() const {return _cos/_sin;}
00071 inline void chSign();
00072 inline void mirror();
00073 void normalize();
00074
00075 static double degreesToDMS(double angle);
00076 static double DMSToDegrees(double angle);
00077 static double degreesToDM(double angle);
00078 static double DMToDegrees(double angle);
00079 static inline double radiansToDegrees(double angle);
00080 static inline double degreesToRadians(double angle);
00081 static inline double geographicToMath(double angle);
00082 static inline double mathToGeographic(double angle);
00083 private:
00084 double _deg;
00085 double _rad;
00086 double _cos;
00087 double _sin;
00088 };
00089
00090 inline double Angle::radiansToDegrees(double angle)
00091 {
00092 return angle*180.0/M_PI;
00093 }
00094
00095 inline double Angle::degreesToRadians(double angle)
00096 {
00097 return angle*M_PI/180.0;
00098 }
00099
00100 inline double Angle::geographicToMath(double angle)
00101 {
00102 angle=degreesToRadians(angle);
00103 return angle<=0.5*M_PI ? 0.5*M_PI-angle : 2.5*M_PI-angle;
00104 }
00105
00106 inline double Angle::mathToGeographic(double angle)
00107 {
00108 angle=radiansToDegrees(angle);
00109 return angle<=90.0 ? 90.0-angle : 450.0-angle;
00110 }
00111
00112 inline Angle::Angle()
00113 {
00114 TRACE;
00115 _deg=0.0;
00116 _rad=0.0;
00117 _cos=1.0;
00118 _sin=0.0;
00119 }
00120
00121 inline void Angle::set(double dx, double dy)
00122 {
00123 TRACE;
00124 _deg=0.0;
00125 _rad=0.0;
00126 double r=::sqrt(dx*dx+dy*dy);
00127 if(r>0.0) {
00128 _cos=dx/r;
00129 _sin=dy/r;
00130 } else {
00131 _cos=1.0;
00132 _sin=0.0;
00133 }
00134 }
00135
00136 inline void Angle::set(double dx, double dy, double r)
00137 {
00138 TRACE;
00139 _deg=0.0;
00140 _rad=0.0;
00141 if(r>0.0) {
00142 _cos=dx/r;
00143 _sin=dy/r;
00144 } else {
00145 _cos=1.0;
00146 _sin=0.0;
00147 }
00148 }
00149
00150 inline Angle& Angle::operator=(const Angle& o)
00151 {
00152 TRACE;
00153 _deg=o._deg;
00154 _rad=o._rad;
00155 _cos=o._cos;
00156 _sin=o._sin;
00157 return *this;
00158 }
00159
00160 inline void Angle::initDegrees()
00161 {
00162 TRACE;
00163 _deg=radiansToDegrees(_rad);
00164 }
00165
00166 inline void Angle::initRadians()
00167 {
00168 TRACE;
00169 _rad=::atan2(_sin, _cos);
00170 }
00171
00172 inline void Angle::setDegrees(double degrees)
00173 {
00174 TRACE;
00175 _deg=degrees;
00176 _rad=degreesToRadians(_deg);
00177 _cos=::cos(_rad);
00178 _sin=::sin(_rad);
00179 }
00180
00181 inline void Angle::setRadians(double radians)
00182 {
00183 TRACE;
00184 _rad=radians;
00185 _cos=::cos(_rad);
00186 _sin=::sin(_rad);
00187 }
00188
00189 inline void Angle::chSign()
00190 {
00191 TRACE;
00192 _deg=-_deg;
00193 _rad=-_rad;
00194 _sin=-_sin;
00195 }
00196
00197 inline void Angle::mirror()
00198 {
00199 TRACE;
00200 _cos=-_cos;
00201 _sin=-_sin;
00202 if(_deg>180.0) _deg-=180; else _deg+=180.0;
00203 if(_rad>M_PI) _rad-=M_PI; else _rad+=M_PI;
00204 }
00205
00206 }
00207
00208 #endif // ANGLE_H