simplified angle formula

This commit is contained in:
Emil Tin 2013-02-23 13:17:57 +01:00
parent 8077418c98
commit 1690b4037b
3 changed files with 19 additions and 27 deletions

View File

@ -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<class CoordinateT>
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 {

View File

@ -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 |

View File

@ -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