SGGeod.hxx

00001 // Copyright (C) 2006  Mathias Froehlich - Mathias.Froehlich@web.de
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Library General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2 of the License, or (at your option) any later version.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Library General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00016 //
00017 
00018 #ifndef SGGeod_H
00019 #define SGGeod_H
00020 
00021 #include <simgear/constants.h>
00022 
00023 // #define SG_GEOD_NATIVE_DEGREE
00024 
00026 class SGGeod {
00027 public:
00029   SGGeod(void);
00030 
00032   static SGGeod fromRad(double lon, double lat);
00034   static SGGeod fromDeg(double lon, double lat);
00036   static SGGeod fromRadFt(double lon, double lat, double elevation);
00038   static SGGeod fromDegFt(double lon, double lat, double elevation);
00040   static SGGeod fromRadM(double lon, double lat, double elevation);
00042   static SGGeod fromDegM(double lon, double lat, double elevation);
00046   static SGGeod fromCart(const SGVec3<double>& cart);
00049   static SGGeod fromGeoc(const SGGeoc& geoc);
00050 
00052   double getLongitudeRad(void) const;
00054   void setLongitudeRad(double lon);
00055 
00057   double getLongitudeDeg(void) const;
00059   void setLongitudeDeg(double lon);
00060 
00062   double getLatitudeRad(void) const;
00064   void setLatitudeRad(double lat);
00065 
00067   double getLatitudeDeg(void) const;
00069   void setLatitudeDeg(double lat);
00070 
00072   double getElevationM(void) const;
00074   void setElevationM(double elevation);
00075 
00077   double getElevationFt(void) const;
00079   void setElevationFt(double elevation);
00080 
00081 private:
00085   SGGeod(double lon, double lat, double elevation);
00086 
00094   double _lon;
00095   double _lat;
00096   double _elevation;
00097 };
00098 
00099 inline
00100 SGGeod::SGGeod(void) :
00101   _lon(0), _lat(0), _elevation(0)
00102 {
00103 }
00104 
00105 inline
00106 SGGeod::SGGeod(double lon, double lat, double elevation) :
00107   _lon(lon), _lat(lat), _elevation(elevation)
00108 {
00109 }
00110 
00111 inline
00112 SGGeod
00113 SGGeod::fromRad(double lon, double lat)
00114 {
00115 #ifdef SG_GEOD_NATIVE_DEGREE
00116   return SGGeod(lon*SGD_RADIANS_TO_DEGREES, lat*SGD_RADIANS_TO_DEGREES, 0);
00117 #else
00118   return SGGeod(lon, lat, 0);
00119 #endif
00120 }
00121 
00122 inline
00123 SGGeod
00124 SGGeod::fromDeg(double lon, double lat)
00125 {
00126 #ifdef SG_GEOD_NATIVE_DEGREE
00127   return SGGeod(lon, lat, 0);
00128 #else
00129   return SGGeod(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS, 0);
00130 #endif
00131 }
00132 
00133 inline
00134 SGGeod
00135 SGGeod::fromRadFt(double lon, double lat, double elevation)
00136 {
00137 #ifdef SG_GEOD_NATIVE_DEGREE
00138   return SGGeod(lon*SGD_RADIANS_TO_DEGREES, lat*SGD_RADIANS_TO_DEGREES,
00139                 elevation*SG_FEET_TO_METER);
00140 #else
00141   return SGGeod(lon, lat, elevation*SG_FEET_TO_METER);
00142 #endif
00143 }
00144 
00145 inline
00146 SGGeod
00147 SGGeod::fromDegFt(double lon, double lat, double elevation)
00148 {
00149 #ifdef SG_GEOD_NATIVE_DEGREE
00150   return SGGeod(lon, lat, elevation*SG_FEET_TO_METER);
00151 #else
00152   return SGGeod(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS,
00153                 elevation*SG_FEET_TO_METER);
00154 #endif
00155 }
00156 
00157 inline
00158 SGGeod
00159 SGGeod::fromRadM(double lon, double lat, double elevation)
00160 {
00161 #ifdef SG_GEOD_NATIVE_DEGREE
00162   return SGGeod(lon*SGD_RADIANS_TO_DEGREES, lat*SGD_RADIANS_TO_DEGREES,
00163                 elevation);
00164 #else
00165   return SGGeod(lon, lat, elevation);
00166 #endif
00167 }
00168 
00169 inline
00170 SGGeod
00171 SGGeod::fromDegM(double lon, double lat, double elevation)
00172 {
00173 #ifdef SG_GEOD_NATIVE_DEGREE
00174   return SGGeod(lon, lat, elevation);
00175 #else
00176   return SGGeod(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS,
00177                 elevation);
00178 #endif
00179 }
00180 
00181 inline
00182 SGGeod
00183 SGGeod::fromCart(const SGVec3<double>& cart)
00184 {
00185   SGGeod geod;
00186   SGGeodesy::SGCartToGeod(cart, geod);
00187   return geod;
00188 }
00189 
00190 inline
00191 SGGeod
00192 SGGeod::fromGeoc(const SGGeoc& geoc)
00193 {
00194   SGVec3<double> cart;
00195   SGGeodesy::SGGeocToCart(geoc, cart);
00196   SGGeod geod;
00197   SGGeodesy::SGCartToGeod(cart, geod);
00198   return geod;
00199 }
00200 
00201 inline
00202 double
00203 SGGeod::getLongitudeRad(void) const
00204 {
00205 #ifdef SG_GEOD_NATIVE_DEGREE
00206   return _lon*SGD_DEGREES_TO_RADIANS;
00207 #else
00208   return _lon;
00209 #endif
00210 }
00211 
00212 inline
00213 void
00214 SGGeod::setLongitudeRad(double lon)
00215 {
00216 #ifdef SG_GEOD_NATIVE_DEGREE
00217   _lon = lon*SGD_RADIANS_TO_DEGREES;
00218 #else
00219   _lon = lon;
00220 #endif
00221 }
00222 
00223 inline
00224 double
00225 SGGeod::getLongitudeDeg(void) const
00226 {
00227 #ifdef SG_GEOD_NATIVE_DEGREE
00228   return _lon;
00229 #else
00230   return _lon*SGD_RADIANS_TO_DEGREES;
00231 #endif
00232 }
00233 
00234 inline
00235 void
00236 SGGeod::setLongitudeDeg(double lon)
00237 {
00238 #ifdef SG_GEOD_NATIVE_DEGREE
00239   _lon = lon;
00240 #else
00241   _lon = lon*SGD_DEGREES_TO_RADIANS;
00242 #endif
00243 }
00244 
00245 inline
00246 double
00247 SGGeod::getLatitudeRad(void) const
00248 {
00249 #ifdef SG_GEOD_NATIVE_DEGREE
00250   return _lat*SGD_DEGREES_TO_RADIANS;
00251 #else
00252   return _lat;
00253 #endif
00254 }
00255 
00256 inline
00257 void
00258 SGGeod::setLatitudeRad(double lat)
00259 {
00260 #ifdef SG_GEOD_NATIVE_DEGREE
00261   _lat = lat*SGD_RADIANS_TO_DEGREES;
00262 #else
00263   _lat = lat;
00264 #endif
00265 }
00266 
00267 inline
00268 double
00269 SGGeod::getLatitudeDeg(void) const
00270 {
00271 #ifdef SG_GEOD_NATIVE_DEGREE
00272   return _lat;
00273 #else
00274   return _lat*SGD_RADIANS_TO_DEGREES;
00275 #endif
00276 }
00277 
00278 inline
00279 void
00280 SGGeod::setLatitudeDeg(double lat)
00281 {
00282 #ifdef SG_GEOD_NATIVE_DEGREE
00283   _lat = lat;
00284 #else
00285   _lat = lat*SGD_DEGREES_TO_RADIANS;
00286 #endif
00287 }
00288 
00289 inline
00290 double
00291 SGGeod::getElevationM(void) const
00292 {
00293   return _elevation;
00294 }
00295 
00296 inline
00297 void
00298 SGGeod::setElevationM(double elevation)
00299 {
00300   _elevation = elevation;
00301 }
00302 
00303 inline
00304 double
00305 SGGeod::getElevationFt(void) const
00306 {
00307   return _elevation*SG_METER_TO_FEET;
00308 }
00309 
00310 inline
00311 void
00312 SGGeod::setElevationFt(double elevation)
00313 {
00314   _elevation = elevation*SG_FEET_TO_METER;
00315 }
00316 
00318 template<typename char_type, typename traits_type>
00319 inline
00320 std::basic_ostream<char_type, traits_type>&
00321 operator<<(std::basic_ostream<char_type, traits_type>& s, const SGGeod& g)
00322 {
00323   return s << "lon = " << g.getLongitudeDeg()
00324            << "deg, lat = " << g.getLatitudeDeg()
00325            << "deg, elev = " << g.getElevationM()
00326            << "m";
00327 }
00328 
00329 #endif

Generated on Mon Dec 17 09:30:55 2007 for SimGear by  doxygen 1.5.1