Skip to content

Instantly share code, notes, and snippets.

@Karry
Last active December 4, 2018 19:55
Show Gist options
  • Save Karry/f1523d5a7ad262786967bcaeb93d7d23 to your computer and use it in GitHub Desktop.
Save Karry/f1523d5a7ad262786967bcaeb93d7d23 to your computer and use it in GitHub Desktop.
#include <osmscout/util/Geometry.h>
#include <osmscout/util/Projection.h>
#include <osmscout/system/Math.h>
#define CATCH_CONFIG_MAIN
#include <catch.hpp>
#include <chrono>
#include <iostream>
TEST_CASE("Move") {
osmscout::GeoCoord position(51.57251,7.46506);
double speedKmH = 42;
// radians, 0 is north, M_PI_2 is east, M_PI is south, -M_PI_2 is west
double bearing = M_PI_2;
auto time = std::chrono::duration<double>(0.250);
double speed = speedKmH / 3.6; // meters/s
auto distance = osmscout::Distance::Of<osmscout::Meter>(speed * time.count());
// compute position2 with given distance and bearing from position
double lat,lon;
osmscout::GetEllipsoidalDistance(position.GetLat(), position.GetLon(),
bearing, distance, lat, lon);
osmscout::GeoCoord position2(lat, lon);
// compute map coordinates for both positions
osmscout::MercatorProjection projection;
projection.Set(position,
osmscout::Magnification(osmscout::Magnification::magBlock),
/*dpi*/ 300, /*width*/ 1200, /*height*/ 1200);
double x1,y1,x2,y2;
projection.GeoToPixel(position,x1,y1);
projection.GeoToPixel(position2,x2,y2);
// mapMove [pixels] = sqrt(dx^2 * dy^2)
double mapMove = std::hypot(x1-x2, y1-y2);
std::cout << mapMove << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment