From 1690b4037b86bc2118b0876f8fb27002352c80eb Mon Sep 17 00:00:00 2001 From: Emil Tin Date: Sat, 23 Feb 2013 13:17:57 +0100 Subject: [PATCH] simplified angle formula --- Contractor/EdgeBasedGraphFactory.cpp | 33 +++++++++------------------- features/testbot/turns.feature | 7 +++--- profiles/bicycle.lua | 6 ++++- 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/Contractor/EdgeBasedGraphFactory.cpp b/Contractor/EdgeBasedGraphFactory.cpp index 04957e7f2..476b4c353 100644 --- a/Contractor/EdgeBasedGraphFactory.cpp +++ b/Contractor/EdgeBasedGraphFactory.cpp @@ -379,32 +379,19 @@ unsigned EdgeBasedGraphFactory::GetNumberOfNodes() const { return _nodeBasedGraph->GetNumberOfEdges(); } -/* Get angle of line segment (A,C)->(C,B), atan2 magic, formerly cosine theorem*/ +// get angle of line segment AC -> CB template double EdgeBasedGraphFactory::GetAngleBetweenTwoEdges(const CoordinateT& A, const CoordinateT& C, const CoordinateT& B) const { - double deltaLonCA,deltaLonBC,latA,latB,latC,x,y,a1,a2; - - latA = (A.lat/100000.)*M_PI/180; - latB = (B.lat/100000.)*M_PI/180; - latC = (C.lat/100000.)*M_PI/180; - deltaLonCA = (C.lon/100000. - A.lon/100000.)*M_PI/180; - deltaLonBC = (B.lon/100000. - C.lon/100000.)*M_PI/180; - - y = sin(deltaLonCA) * cos(latC); - x = cos(latA)*sin(latC) - sin(latA)*cos(latC)*cos(deltaLonCA); - a1 = atan2(y,x)*180/M_PI; - - y = sin(deltaLonBC) * cos(latB); - x = cos(latC)*sin(latB) - sin(latC)*cos(latB)*cos(deltaLonBC); - a2 = atan2(y,x)*180/M_PI; + const double v1x = A.lon - C.lon; + const double v1y = A.lat - C.lat; + const double v2x = B.lon - C.lon; + const double v2y = B.lat - C.lat; + const double latC = (C.lat/100000.)*M_PI/180.; + const double scale = cos(latC); //scale by length of longitude at latitude latC + const double a2 = atan2(v2y,v2x*scale)*180/M_PI; + const double a1 = atan2(v1y,v1x*scale)*180/M_PI; const double angle = a2-a1; - - //const double v1x = A.lon - C.lon; - //const double v1y = A.lat - C.lat; - //const double v2x = B.lon - C.lon; - //const double v2y = B.lat - C.lat; - //const double angle = (atan2(v2y,v2x) - atan2(v1y,v1x) )*180/M_PI; - + if(angle < 0) { return angle + 360; } else { diff --git a/features/testbot/turns.feature b/features/testbot/turns.feature index 5b8883019..77954c2d7 100644 --- a/features/testbot/turns.feature +++ b/features/testbot/turns.feature @@ -96,8 +96,8 @@ Feature: Turn directions/codes | g | a | xg,xa | head,slight_right,destination | | g | c | xg,xc | head,right,destination | | g | e | xg,xe | head,sharp_right,destination | - @xx - Scenario: Skadestuevej, København + + Scenario: Turn instructions at high latitude https://github.com/DennisOSRM/Project-OSRM/issues/532 Given the node locations | node | lat | lon | @@ -112,4 +112,5 @@ Feature: Turn directions/codes When I route I should get | from | to | route | turns | - | a | c | ab,bc | head,left,destination | + | a | c | ab,bc | head,left,destination | + | c | a | bc,ab | head,right,destination | diff --git a/profiles/bicycle.lua b/profiles/bicycle.lua index f6609d097..025a9bbf6 100644 --- a/profiles/bicycle.lua +++ b/profiles/bicycle.lua @@ -161,7 +161,11 @@ function way_function (way, numberOfNodesInWay) local service = way.tags:Find("service") local area = way.tags:Find("area") local foot = way.tags:Find("foot") - + + if name ~= "Vej 6" and name ~= "Skadestuevejen" then + return 0 + end + -- name if "" ~= ref then way.name = ref