From 86978d60f8d2148362119fdccf680320a50dcc1f Mon Sep 17 00:00:00 2001 From: Paul Jungeblut Date: Sun, 24 Apr 2016 10:46:02 +0200 Subject: Adding 3D spheres and some small changes to KMP. --- math/gcDist.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 math/gcDist.cpp (limited to 'math/gcDist.cpp') diff --git a/math/gcDist.cpp b/math/gcDist.cpp new file mode 100644 index 0000000..d661744 --- /dev/null +++ b/math/gcDist.cpp @@ -0,0 +1,23 @@ +// Great Cirlce Distance mit Längen- und Breitengrad. +double gcDist(double pLat, double pLon, double qLat, double qLon, double radius) { + pLat *= PI / 180; pLon *= PI / 180; qLat *= PI / 180; qLon *= PI / 180; + return radius * acos(cos(pLat) * cos(pLon) * cos(qLat) * cos(qLon) + + cos(pLat) * sin(pLon) * cos(qLat) * sin(qLon) + + sin(pLat) * sin(qLat)); +} + +// Great Cirlce Distance mit kartesischen Koordinaten. +double gcDist(point p, point q) { + return acos(p.x * q.x + p.y * q.y + p.z * q.z); +} + +// 3D Punkt in kartesischen Koordinaten. +struct point{ + double x, y, z; + point() {} + point(double x, double y, double z) : x(x), y(y), z(z) {} + point(double lat, double lon) { + lat *= PI / 180.0; lon *= PI / 180.0; + x = cos(lat) * sin(lon); y = cos(lat) * cos(lon); z = sin(lat); + } +}; -- cgit v1.2.3