使用下面的代码(对GeographicLib进行简化)来移动坐标并再次返回,以创建到原始起点的偏移。 差异随着运动距离的增加而增加,并取决于方位角。使用GeodesicExact和Geodesic的情况相同。 最后,我要实现的是通过移动起始坐标来创建latLon形状。
是否有一种精确/更好的方法来做到这一点,或者我错过了一些基本知识?
inline double distanceInMeters(const GeoCoords &_c1, const GeoCoords &_c2) {
GeodesicExact geod = geodWGS84(); // GeodesicExact::WGS84()
double meters;
geod.Inverse(_c1.Latitude(), _c1.Longitude(),
_c2.Latitude(), _c2.Longitude(),
meters);
return meters;
}
// move coord _byMeters in direction _azimuth
// inexact with horiz moves !!!
inline GeoCoords move(const GeoCoords &_coords, const double &_azimuth, const double &_byMeters) {
GeodesicExact geod = geodWGS84(); // GeodesicExact::WGS84()
double latOut, lngOut;
geod.Direct(_coords.Latitude(), _coords.Longitude(), _azimuth, _byMeters, latOut, lngOut);
return GeoCoords(latOut, lngOut);
}
inline void testDistanceMove() {
GeoCoords c(12.3456789, 12.3456789);
GeoCoords cc = c;
double dist = 123459998.6789; // meters
bool bHorz = true; // <-- creates some offset???
bool bVert = true; // almost exact
if (bHorz) cc = move(cc, Azimuth::WEST, dist); // 270.
if (bVert) cc = move(cc, Azimuth::SOUTH, dist); // 180
if (bHorz) cc = move(cc, Azimuth::EAST, dist); // 90.
if (bVert) cc = move(cc, Azimuth::NORTH, dist); // 0.
ofLogNotice((__func__)) << "c : " << toString(c);
ofLogNotice((__func__)) << "cc: " << toString(cc);
double diff = distanceInMeters(c, cc);
ofLogNotice((__func__)) << "diff: " << ofToString(diff, 12) << " m";
}