00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef SGGeoc_H
00019 #define SGGeoc_H
00020
00021 #include <simgear/constants.h>
00022
00023
00024
00026 class SGGeoc {
00027 public:
00029 SGGeoc(void);
00030
00032 static SGGeoc fromRadFt(double lon, double lat, double radius);
00034 static SGGeoc fromDegFt(double lon, double lat, double radius);
00036 static SGGeoc fromRadM(double lon, double lat, double radius);
00038 static SGGeoc fromDegM(double lon, double lat, double radius);
00042 static SGGeoc fromCart(const SGVec3<double>& cart);
00045 static SGGeoc fromGeod(const SGGeod& geod);
00046
00048 double getLongitudeRad(void) const;
00050 void setLongitudeRad(double lon);
00051
00053 double getLongitudeDeg(void) const;
00055 void setLongitudeDeg(double lon);
00056
00058 double getLatitudeRad(void) const;
00060 void setLatitudeRad(double lat);
00061
00063 double getLatitudeDeg(void) const;
00065 void setLatitudeDeg(double lat);
00066
00068 double getRadiusM(void) const;
00070 void setRadiusM(double radius);
00071
00073 double getRadiusFt(void) const;
00075 void setRadiusFt(double radius);
00076
00077 SGGeoc advanceRadM(double course, double distance) const;
00078 static double courseRad(const SGGeoc& from, const SGGeoc& to);
00079 static double courseDeg(const SGGeoc& from, const SGGeoc& to);
00080 static double distanceM(const SGGeoc& from, const SGGeoc& to);
00081
00082
00083 bool operator == ( const SGGeoc & other ) const;
00084 private:
00088 SGGeoc(double lon, double lat, double radius);
00089
00097 double _lon;
00098 double _lat;
00099 double _radius;
00100 };
00101
00102 inline
00103 SGGeoc::SGGeoc(void) :
00104 _lon(0), _lat(0), _radius(0)
00105 {
00106 }
00107
00108 inline
00109 SGGeoc::SGGeoc(double lon, double lat, double radius) :
00110 _lon(lon), _lat(lat), _radius(radius)
00111 {
00112 }
00113
00114 inline
00115 SGGeoc
00116 SGGeoc::fromRadFt(double lon, double lat, double radius)
00117 {
00118 #ifdef SG_GEOC_NATIVE_DEGREE
00119 return SGGeoc(lon*SGD_RADIANS_TO_DEGREES, lat*SGD_RADIANS_TO_DEGREES,
00120 radius*SG_FEET_TO_METER);
00121 #else
00122 return SGGeoc(lon, lat, radius*SG_FEET_TO_METER);
00123 #endif
00124 }
00125
00126 inline
00127 SGGeoc
00128 SGGeoc::fromDegFt(double lon, double lat, double radius)
00129 {
00130 #ifdef SG_GEOC_NATIVE_DEGREE
00131 return SGGeoc(lon, lat, radius*SG_FEET_TO_METER);
00132 #else
00133 return SGGeoc(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS,
00134 radius*SG_FEET_TO_METER);
00135 #endif
00136 }
00137
00138 inline
00139 SGGeoc
00140 SGGeoc::fromRadM(double lon, double lat, double radius)
00141 {
00142 #ifdef SG_GEOC_NATIVE_DEGREE
00143 return SGGeoc(lon*SGD_RADIANS_TO_DEGREES, lat*SGD_RADIANS_TO_DEGREES,
00144 radius);
00145 #else
00146 return SGGeoc(lon, lat, radius);
00147 #endif
00148 }
00149
00150 inline
00151 SGGeoc
00152 SGGeoc::fromDegM(double lon, double lat, double radius)
00153 {
00154 #ifdef SG_GEOC_NATIVE_DEGREE
00155 return SGGeoc(lon, lat, radius);
00156 #else
00157 return SGGeoc(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS,
00158 radius);
00159 #endif
00160 }
00161
00162 inline
00163 SGGeoc
00164 SGGeoc::fromCart(const SGVec3<double>& cart)
00165 {
00166 SGGeoc geoc;
00167 SGGeodesy::SGCartToGeoc(cart, geoc);
00168 return geoc;
00169 }
00170
00171 inline
00172 SGGeoc
00173 SGGeoc::fromGeod(const SGGeod& geod)
00174 {
00175 SGVec3<double> cart;
00176 SGGeodesy::SGGeodToCart(geod, cart);
00177 SGGeoc geoc;
00178 SGGeodesy::SGCartToGeoc(cart, geoc);
00179 return geoc;
00180 }
00181
00182 inline
00183 double
00184 SGGeoc::getLongitudeRad(void) const
00185 {
00186 #ifdef SG_GEOC_NATIVE_DEGREE
00187 return _lon*SGD_DEGREES_TO_RADIANS;
00188 #else
00189 return _lon;
00190 #endif
00191 }
00192
00193 inline
00194 void
00195 SGGeoc::setLongitudeRad(double lon)
00196 {
00197 #ifdef SG_GEOC_NATIVE_DEGREE
00198 _lon = lon*SGD_RADIANS_TO_DEGREES;
00199 #else
00200 _lon = lon;
00201 #endif
00202 }
00203
00204 inline
00205 double
00206 SGGeoc::getLongitudeDeg(void) const
00207 {
00208 #ifdef SG_GEOC_NATIVE_DEGREE
00209 return _lon;
00210 #else
00211 return _lon*SGD_RADIANS_TO_DEGREES;
00212 #endif
00213 }
00214
00215 inline
00216 void
00217 SGGeoc::setLongitudeDeg(double lon)
00218 {
00219 #ifdef SG_GEOC_NATIVE_DEGREE
00220 _lon = lon;
00221 #else
00222 _lon = lon*SGD_DEGREES_TO_RADIANS;
00223 #endif
00224 }
00225
00226 inline
00227 double
00228 SGGeoc::getLatitudeRad(void) const
00229 {
00230 #ifdef SG_GEOC_NATIVE_DEGREE
00231 return _lat*SGD_DEGREES_TO_RADIANS;
00232 #else
00233 return _lat;
00234 #endif
00235 }
00236
00237 inline
00238 void
00239 SGGeoc::setLatitudeRad(double lat)
00240 {
00241 #ifdef SG_GEOC_NATIVE_DEGREE
00242 _lat = lat*SGD_RADIANS_TO_DEGREES;
00243 #else
00244 _lat = lat;
00245 #endif
00246 }
00247
00248 inline
00249 double
00250 SGGeoc::getLatitudeDeg(void) const
00251 {
00252 #ifdef SG_GEOC_NATIVE_DEGREE
00253 return _lat;
00254 #else
00255 return _lat*SGD_RADIANS_TO_DEGREES;
00256 #endif
00257 }
00258
00259 inline
00260 void
00261 SGGeoc::setLatitudeDeg(double lat)
00262 {
00263 #ifdef SG_GEOC_NATIVE_DEGREE
00264 _lat = lat;
00265 #else
00266 _lat = lat*SGD_DEGREES_TO_RADIANS;
00267 #endif
00268 }
00269
00270 inline
00271 double
00272 SGGeoc::getRadiusM(void) const
00273 {
00274 return _radius;
00275 }
00276
00277 inline
00278 void
00279 SGGeoc::setRadiusM(double radius)
00280 {
00281 _radius = radius;
00282 }
00283
00284 inline
00285 double
00286 SGGeoc::getRadiusFt(void) const
00287 {
00288 return _radius*SG_METER_TO_FEET;
00289 }
00290
00291 inline
00292 void
00293 SGGeoc::setRadiusFt(double radius)
00294 {
00295 _radius = radius*SG_FEET_TO_METER;
00296 }
00297
00298 inline
00299 SGGeoc
00300 SGGeoc::advanceRadM(double course, double distance) const
00301 {
00302 SGGeoc result;
00303 SGGeodesy::advanceRadM(*this, course, distance, result);
00304 return result;
00305 }
00306
00307 inline
00308 double
00309 SGGeoc::courseRad(const SGGeoc& from, const SGGeoc& to)
00310 {
00311 return SGGeodesy::courseRad(from, to);
00312 }
00313
00314 inline
00315 double
00316 SGGeoc::courseDeg(const SGGeoc& from, const SGGeoc& to)
00317 {
00318 return SGMiscd::rad2deg(courseRad(from, to));
00319 }
00320
00321 inline
00322 double
00323 SGGeoc::distanceM(const SGGeoc& from, const SGGeoc& to)
00324 {
00325 return SGGeodesy::distanceM(from, to);
00326 }
00327
00328 inline
00329 bool
00330 SGGeoc::operator == ( const SGGeoc & other ) const
00331 {
00332 return _lon == other._lon &&
00333 _lat == other._lat &&
00334 _radius == other._radius;
00335 }
00336
00338 template<typename char_type, typename traits_type>
00339 inline
00340 std::basic_ostream<char_type, traits_type>&
00341 operator<<(std::basic_ostream<char_type, traits_type>& s, const SGGeoc& g)
00342 {
00343 return s << "lon = " << g.getLongitudeDeg()
00344 << ", lat = " << g.getLatitudeDeg()
00345 << ", radius = " << g.getRadiusM();
00346 }
00347
00348 #endif