bakercp / ofxGeographicLib

An openFrameworks wrapper for the Geographic Library.
Other
4 stars 2 forks source link

Q: moving a coordinate horizontally away and back creates an offset #5

Open johanjohan opened 6 years ago

johanjohan commented 6 years ago

@bakercp

using the following code and moving a coordinate away and back again creates a horizontal difference, that gets larger the farther the point is moved. the same is true for using both GeodesicExact and Geodesic alternatively. what i want to achieve is creating a latLon shape by moving the startLatLon around.

is there are an exact/better way of doing this?


        inline string toString(const GeoCoords &_c, const int &_precision, const string &_delim = ",") {
            return ofToString(_c.Latitude(), _precision) + _delim + ofToString(_c.Longitude(), _precision);
        }

        inline string toString(const GeoCoords &_c) {
            return toString(_c, 12);
        }
        inline double distanceInMeters(const GeoCoords &_c1, const GeoCoords &_c2) {
            ofx3jGeodesic   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) {
            ofx3jGeodesic   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";
        }