00001 #ifndef _SG_GEODESY_HXX
00002 #define _SG_GEODESY_HXX
00003
00004 #include <simgear/math/point3d.hxx>
00005 #include "SGMath.hxx"
00006
00007
00008
00009
00025 inline void sgGeodToGeoc(double lat_geod, double alt,
00026 double *sl_radius, double *lat_geoc)
00027 {
00028 SGVec3<double> cart;
00029 SGGeod geod = SGGeod::fromRadM(0, lat_geod, alt);
00030 SGGeodesy::SGGeodToCart(geod, cart);
00031 SGGeoc geoc;
00032 SGGeodesy::SGCartToGeoc(cart, geoc);
00033 *lat_geoc = geoc.getLatitudeRad();
00034 *sl_radius = SGGeodesy::SGGeodToSeaLevelRadius(geod);
00035 }
00036
00037
00046 inline void sgCartToGeod(const double* xyz, double* lat, double* lon, double* alt)
00047 {
00048 SGGeod geod;
00049 SGGeodesy::SGCartToGeod(SGVec3<double>(xyz), geod);
00050 *lat = geod.getLatitudeRad();
00051 *lon = geod.getLongitudeRad();
00052 *alt = geod.getElevationM();
00053 }
00054
00062 inline Point3D sgCartToGeod(const Point3D& p)
00063 {
00064 SGGeod geod;
00065 SGGeodesy::SGCartToGeod(SGVec3<double>(p.x(), p.y(), p.z()), geod);
00066 return Point3D::fromSGGeod(geod);
00067 }
00068
00069
00078 inline void sgGeodToCart(double lat, double lon, double alt, double* xyz)
00079 {
00080 SGVec3<double> cart;
00081 SGGeodesy::SGGeodToCart(SGGeod::fromRadM(lon, lat, alt), cart);
00082 xyz[0] = cart(0);
00083 xyz[1] = cart(1);
00084 xyz[2] = cart(2);
00085 }
00086
00094 inline Point3D sgGeodToCart(const Point3D& geod)
00095 {
00096 SGVec3<double> cart;
00097 SGGeodesy::SGGeodToCart(SGGeod::fromRadM(geod.lon(), geod.lat(), geod.elev()), cart);
00098 return Point3D::fromSGVec3(cart);
00099 }
00100
00113 inline int geo_direct_wgs_84 ( double lat1, double lon1, double az1,
00114 double s, double *lat2, double *lon2,
00115 double *az2 )
00116 {
00117 SGGeod p2;
00118 if (!SGGeodesy::direct(SGGeod::fromDeg(lon1, lat1), az1, s, p2, *az2))
00119 return 1;
00120 *lat2 = p2.getLatitudeDeg();
00121 *lon2 = p2.getLongitudeDeg();
00122 return 0;
00123 }
00124 inline int geo_direct_wgs_84 ( double alt, double lat1,
00125 double lon1, double az1,
00126 double s, double *lat2, double *lon2,
00127 double *az2 )
00128 { return geo_direct_wgs_84(lat1, lon1, az1, s, lat2, lon2, az2); }
00129
00139 inline int geo_direct_wgs_84(const SGGeod& p1, double az1,
00140 double s, SGGeod& p2, double *az2 )
00141 {
00142 return !SGGeodesy::direct(p1, az1, s, p2, *az2);
00143 }
00144
00157 inline int geo_inverse_wgs_84( double lat1, double lon1, double lat2,
00158 double lon2, double *az1, double *az2,
00159 double *s )
00160 {
00161 return !SGGeodesy::inverse(SGGeod::fromDeg(lon1, lat1),
00162 SGGeod::fromDeg(lon2, lat2), *az1, *az2, *s);
00163 }
00164 inline int geo_inverse_wgs_84( double alt, double lat1,
00165 double lon1, double lat2,
00166 double lon2, double *az1, double *az2,
00167 double *s )
00168 { return geo_inverse_wgs_84(lat1, lon1, lat2, lon2, az1, az2, s); }
00169
00170
00180 inline int geo_inverse_wgs_84(const SGGeod& p1, const SGGeod& p2,
00181 double *az1, double *az2, double *s )
00182 {
00183 return !SGGeodesy::inverse(p1, p2, *az1, *az2, *s);
00184 }
00185
00186 #endif // _SG_GEODESY_HXX