-
-
-// Find the Altitude above the Ellipsoid (WGS84) given the Earth
-// Centered Cartesian coordinate vector Distances are specified in
-// meters.
-double fgGeodAltFromCart(const Point3D& cp);
-
-
-// Convert a polar coordinate to a cartesian coordinate. Lon and Lat
-// must be specified in radians. The FG convention is for distances
-// to be specified in meters
-inline Point3D fgPolarToCart3d(const Point3D& p) {
- double tmp = cos( p.lat() ) * p.radius();
-
- return Point3D( cos( p.lon() ) * tmp,
- sin( p.lon() ) * tmp,
- sin( p.lat() ) * p.radius() );
-}
-
-
-// Convert a cartesian coordinate to polar coordinates (lon/lat
-// specified in radians. Distances are specified in meters.
-inline Point3D fgCartToPolar3d(const Point3D& cp) {
- return Point3D( atan2( cp.y(), cp.x() ),
- FG_PI_2 -
- atan2( sqrt(cp.x()*cp.x() + cp.y()*cp.y()), cp.z() ),
- sqrt(cp.x()*cp.x() + cp.y()*cp.y() + cp.z()*cp.z()) );
+#include "SGMath.hxx"
+
+/**
+ * Calculate new lon/lat given starting lon/lat, and offset radial, and
+ * distance. NOTE: starting point is specifed in radians, distance is
+ * specified in meters (and converted internally to radians)
+ * ... assumes a spherical world.
+ * @param orig specified in polar coordinates
+ * @param course offset radial
+ * @param dist offset distance
+ * @return destination point in polar coordinates
+ */
+inline Point3D calc_gc_lon_lat(const Point3D& orig, double course, double dist)
+{ return Point3D::fromSGGeoc(orig.toSGGeoc().advanceRadM(course, dist)); }
+
+
+/**
+ * Calculate course/dist given two spherical points.
+ * @param start starting point
+ * @param dest ending point
+ * @param course resulting course
+ * @param dist resulting distance
+ */
+inline void calc_gc_course_dist( const Point3D& start, const Point3D& dest,
+ double *course, double *dist )
+{
+ SGGeoc gs = start.toSGGeoc();
+ SGGeoc gd = dest.toSGGeoc();
+ *course = SGGeoc::courseRad(gs, gd);
+ *dist = SGGeoc::distanceM(gs, gd);