00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef SGGeod_H
00019 #define SGGeod_H
00020
00021 #include <simgear/constants.h>
00022
00023 #ifndef NO_OPENSCENEGRAPH_INTERFACE
00024 #include <osg/Matrix>
00025 #endif
00026
00027
00028
00030 class SGGeod {
00031 public:
00033 SGGeod(void);
00034
00036 static SGGeod fromRad(double lon, double lat);
00038 static SGGeod fromDeg(double lon, double lat);
00040 static SGGeod fromRadFt(double lon, double lat, double elevation);
00042 static SGGeod fromDegFt(double lon, double lat, double elevation);
00044 static SGGeod fromRadM(double lon, double lat, double elevation);
00046 static SGGeod fromDegM(double lon, double lat, double elevation);
00048 static SGGeod fromGeodM(const SGGeod& geod, double elevation);
00050 static SGGeod fromGeodFt(const SGGeod& geod, double elevation);
00054 static SGGeod fromCart(const SGVec3<double>& cart);
00057 static SGGeod fromGeoc(const SGGeoc& geoc);
00058
00060 double getLongitudeRad(void) const;
00062 void setLongitudeRad(double lon);
00063
00065 double getLongitudeDeg(void) const;
00067 void setLongitudeDeg(double lon);
00068
00070 double getLatitudeRad(void) const;
00072 void setLatitudeRad(double lat);
00073
00075 double getLatitudeDeg(void) const;
00077 void setLatitudeDeg(double lat);
00078
00080 double getElevationM(void) const;
00082 void setElevationM(double elevation);
00083
00085 double getElevationFt(void) const;
00087 void setElevationFt(double elevation);
00088
00089
00090 bool operator == ( const SGGeod & other ) const;
00091
00092 #ifndef NO_OPENSCENEGRAPH_INTERFACE
00093
00094
00095
00096 osg::Matrix makeSimulationFrameRelative() const;
00097 osg::Matrix makeSimulationFrame() const;
00098
00099
00100
00101
00102 osg::Matrix makeZUpFrameRelative() const;
00103 osg::Matrix makeZUpFrame() const;
00104 #endif
00105 private:
00109 SGGeod(double lon, double lat, double elevation);
00110
00119 double _lon;
00120 double _lat;
00121 double _elevation;
00122 };
00123
00124 inline
00125 SGGeod::SGGeod(void) :
00126 _lon(0), _lat(0), _elevation(0)
00127 {
00128 }
00129
00130 inline
00131 SGGeod::SGGeod(double lon, double lat, double elevation) :
00132 _lon(lon), _lat(lat), _elevation(elevation)
00133 {
00134 }
00135
00136 inline
00137 SGGeod
00138 SGGeod::fromRad(double lon, double lat)
00139 {
00140 #ifdef SG_GEOD_NATIVE_DEGREE
00141 return SGGeod(lon*SGD_RADIANS_TO_DEGREES, lat*SGD_RADIANS_TO_DEGREES, 0);
00142 #else
00143 return SGGeod(lon, lat, 0);
00144 #endif
00145 }
00146
00147 inline
00148 SGGeod
00149 SGGeod::fromDeg(double lon, double lat)
00150 {
00151 #ifdef SG_GEOD_NATIVE_DEGREE
00152 return SGGeod(lon, lat, 0);
00153 #else
00154 return SGGeod(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS, 0);
00155 #endif
00156 }
00157
00158 inline
00159 SGGeod
00160 SGGeod::fromRadFt(double lon, double lat, double elevation)
00161 {
00162 #ifdef SG_GEOD_NATIVE_DEGREE
00163 return SGGeod(lon*SGD_RADIANS_TO_DEGREES, lat*SGD_RADIANS_TO_DEGREES,
00164 elevation*SG_FEET_TO_METER);
00165 #else
00166 return SGGeod(lon, lat, elevation*SG_FEET_TO_METER);
00167 #endif
00168 }
00169
00170 inline
00171 SGGeod
00172 SGGeod::fromDegFt(double lon, double lat, double elevation)
00173 {
00174 #ifdef SG_GEOD_NATIVE_DEGREE
00175 return SGGeod(lon, lat, elevation*SG_FEET_TO_METER);
00176 #else
00177 return SGGeod(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS,
00178 elevation*SG_FEET_TO_METER);
00179 #endif
00180 }
00181
00182 inline
00183 SGGeod
00184 SGGeod::fromRadM(double lon, double lat, double elevation)
00185 {
00186 #ifdef SG_GEOD_NATIVE_DEGREE
00187 return SGGeod(lon*SGD_RADIANS_TO_DEGREES, lat*SGD_RADIANS_TO_DEGREES,
00188 elevation);
00189 #else
00190 return SGGeod(lon, lat, elevation);
00191 #endif
00192 }
00193
00194 inline
00195 SGGeod
00196 SGGeod::fromDegM(double lon, double lat, double elevation)
00197 {
00198 #ifdef SG_GEOD_NATIVE_DEGREE
00199 return SGGeod(lon, lat, elevation);
00200 #else
00201 return SGGeod(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS,
00202 elevation);
00203 #endif
00204 }
00205
00206 inline
00207 SGGeod
00208 SGGeod::fromGeodM(const SGGeod& geod, double elevation)
00209 {
00210 return SGGeod(geod._lon, geod._lat, elevation);
00211 }
00212
00213 inline
00214 SGGeod
00215 SGGeod::fromGeodFt(const SGGeod& geod, double elevation)
00216 {
00217 return SGGeod(geod._lon, geod._lat, elevation*SG_FEET_TO_METER);
00218 }
00219
00220 inline
00221 SGGeod
00222 SGGeod::fromCart(const SGVec3<double>& cart)
00223 {
00224 SGGeod geod;
00225 SGGeodesy::SGCartToGeod(cart, geod);
00226 return geod;
00227 }
00228
00229 inline
00230 SGGeod
00231 SGGeod::fromGeoc(const SGGeoc& geoc)
00232 {
00233 SGVec3<double> cart;
00234 SGGeodesy::SGGeocToCart(geoc, cart);
00235 SGGeod geod;
00236 SGGeodesy::SGCartToGeod(cart, geod);
00237 return geod;
00238 }
00239
00240 inline
00241 double
00242 SGGeod::getLongitudeRad(void) const
00243 {
00244 #ifdef SG_GEOD_NATIVE_DEGREE
00245 return _lon*SGD_DEGREES_TO_RADIANS;
00246 #else
00247 return _lon;
00248 #endif
00249 }
00250
00251 inline
00252 void
00253 SGGeod::setLongitudeRad(double lon)
00254 {
00255 #ifdef SG_GEOD_NATIVE_DEGREE
00256 _lon = lon*SGD_RADIANS_TO_DEGREES;
00257 #else
00258 _lon = lon;
00259 #endif
00260 }
00261
00262 inline
00263 double
00264 SGGeod::getLongitudeDeg(void) const
00265 {
00266 #ifdef SG_GEOD_NATIVE_DEGREE
00267 return _lon;
00268 #else
00269 return _lon*SGD_RADIANS_TO_DEGREES;
00270 #endif
00271 }
00272
00273 inline
00274 void
00275 SGGeod::setLongitudeDeg(double lon)
00276 {
00277 #ifdef SG_GEOD_NATIVE_DEGREE
00278 _lon = lon;
00279 #else
00280 _lon = lon*SGD_DEGREES_TO_RADIANS;
00281 #endif
00282 }
00283
00284 inline
00285 double
00286 SGGeod::getLatitudeRad(void) const
00287 {
00288 #ifdef SG_GEOD_NATIVE_DEGREE
00289 return _lat*SGD_DEGREES_TO_RADIANS;
00290 #else
00291 return _lat;
00292 #endif
00293 }
00294
00295 inline
00296 void
00297 SGGeod::setLatitudeRad(double lat)
00298 {
00299 #ifdef SG_GEOD_NATIVE_DEGREE
00300 _lat = lat*SGD_RADIANS_TO_DEGREES;
00301 #else
00302 _lat = lat;
00303 #endif
00304 }
00305
00306 inline
00307 double
00308 SGGeod::getLatitudeDeg(void) const
00309 {
00310 #ifdef SG_GEOD_NATIVE_DEGREE
00311 return _lat;
00312 #else
00313 return _lat*SGD_RADIANS_TO_DEGREES;
00314 #endif
00315 }
00316
00317 inline
00318 void
00319 SGGeod::setLatitudeDeg(double lat)
00320 {
00321 #ifdef SG_GEOD_NATIVE_DEGREE
00322 _lat = lat;
00323 #else
00324 _lat = lat*SGD_DEGREES_TO_RADIANS;
00325 #endif
00326 }
00327
00328 inline
00329 double
00330 SGGeod::getElevationM(void) const
00331 {
00332 return _elevation;
00333 }
00334
00335 inline
00336 void
00337 SGGeod::setElevationM(double elevation)
00338 {
00339 _elevation = elevation;
00340 }
00341
00342 inline
00343 double
00344 SGGeod::getElevationFt(void) const
00345 {
00346 return _elevation*SG_METER_TO_FEET;
00347 }
00348
00349 inline
00350 void
00351 SGGeod::setElevationFt(double elevation)
00352 {
00353 _elevation = elevation*SG_FEET_TO_METER;
00354 }
00355
00356 inline
00357 bool
00358 SGGeod::operator == ( const SGGeod & other ) const
00359 {
00360 return _lon == other._lon &&
00361 _lat == other._lat &&
00362 _elevation == other._elevation;
00363 }
00364
00366 template<typename char_type, typename traits_type>
00367 inline
00368 std::basic_ostream<char_type, traits_type>&
00369 operator<<(std::basic_ostream<char_type, traits_type>& s, const SGGeod& g)
00370 {
00371 return s << "lon = " << g.getLongitudeDeg()
00372 << "deg, lat = " << g.getLatitudeDeg()
00373 << "deg, elev = " << g.getElevationM()
00374 << "m";
00375 }
00376
00377 #endif