From: jmt Date: Fri, 26 Dec 2008 12:08:28 +0000 (+0000) Subject: Add some syntactic helpers to allow distance/course to be queried between X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=94942d1ac4e9084c254955de99ff76a85413c148;p=simgear.git Add some syntactic helpers to allow distance/course to be queried between two geodetic points. This still entails a full _geo_inverse_wgs_84 call, but makes call sites neater. --- diff --git a/simgear/math/SGGeodesy.cxx b/simgear/math/SGGeodesy.cxx index 819acdd0..f105dfa5 100644 --- a/simgear/math/SGGeodesy.cxx +++ b/simgear/math/SGGeodesy.cxx @@ -21,6 +21,7 @@ #include +#include "structure/exception.hxx" #include "SGMath.hxx" // These are hard numbers from the WGS84 standard. DON'T MODIFY @@ -423,6 +424,40 @@ SGGeodesy::inverse(const SGGeod& p1, const SGGeod& p2, double& course1, return ret == 0; } +double +SGGeodesy::courseDeg(const SGGeod& p1, const SGGeod& p2) +{ + double course1, course2, distance; + int r = _geo_inverse_wgs_84(p1.getLatitudeDeg(), p1.getLongitudeDeg(), + p2.getLatitudeDeg(), p2.getLongitudeDeg(), + &course1, &course2, &distance); + if (r != 0) { + throw sg_exception("SGGeodesy::courseDeg, unable to compute course"); + } + + return course1; +} + +double +SGGeodesy::distanceM(const SGGeod& p1, const SGGeod& p2) +{ + double course1, course2, distance; + int r = _geo_inverse_wgs_84(p1.getLatitudeDeg(), p1.getLongitudeDeg(), + p2.getLatitudeDeg(), p2.getLongitudeDeg(), + &course1, &course2, &distance); + if (r != 0) { + throw sg_exception("SGGeodesy::distanceM, unable to compute distance"); + } + + return distance; +} + +double +SGGeodesy::distanceNm(const SGGeod& from, const SGGeod& to) +{ + return distanceM(from, to) * SG_METER_TO_NM; +} + /// Geocentric routines void diff --git a/simgear/math/SGGeodesy.hxx b/simgear/math/SGGeodesy.hxx index 8128b832..53e2cbb3 100644 --- a/simgear/math/SGGeodesy.hxx +++ b/simgear/math/SGGeodesy.hxx @@ -53,6 +53,10 @@ public: static bool inverse(const SGGeod& p1, const SGGeod& p2, double& course1, double& course2, double& distance); + static double courseDeg(const SGGeod& from, const SGGeod& to); + static double distanceM(const SGGeod& from, const SGGeod& to); + static double distanceNm(const SGGeod& from, const SGGeod& to); + // Geocentric course/distance computation static void advanceRadM(const SGGeoc& geoc, double course, double distance, SGGeoc& result);