From 4796f801c854bb443998ca111915a04d635d168b Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Thu, 18 Dec 2014 16:12:56 +0300 Subject: Matching bearing while route matching --- platform/location.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'platform/location.hpp') diff --git a/platform/location.hpp b/platform/location.hpp index 978bf8aeab..576c95a3ee 100644 --- a/platform/location.hpp +++ b/platform/location.hpp @@ -5,6 +5,7 @@ #include "../routing/turns.hpp" #include "../std/string.hpp" +#include "../std/cmath.hpp" namespace location @@ -73,6 +74,22 @@ namespace location return lon != 0. && lon < 180. && lon > -180.; } + + // Convert angle (in degrees counterclockwise from X) to bearing ([0, 360) clockwise from the north) + static inline double AngleToBearing(double a) + { + double reverseAng = fmod(-a + 90, 360.); + if (reverseAng < 0) + reverseAng += 360.; + return reverseAng; + } + + // Convert bearing (in degrees clockwise from the north) to angle ([0, 360) counterclockwise from X) + static inline double BearingToAngle(double a) + { + return AngleToBearing(a); + } + class FollowingInfo { public: -- cgit v1.2.3