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.
This commit is contained in:
jmt 2008-12-26 12:08:28 +00:00 committed by Tim Moore
parent b0a5b54949
commit 94942d1ac4
2 changed files with 39 additions and 0 deletions

View File

@ -21,6 +21,7 @@
#include <cmath>
#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

View File

@ -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);