Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

90 degree turn described as "turn slight left/right" #532

Closed
emiltin opened this Issue · 6 comments

2 participants

@emiltin
Collaborator

this route has several turns very close to 90 degreee, yet they're described as 'turn slight left/right':

http://map.project-osrm.org/?hl=en&loc=55.686790,12.523600&loc=55.687610,12.528540&z=17&center=55.687117,12.525353&alt=0&df=0&re=0

this is just one example. the problem seems to be general.

@emiltin
Collaborator

request:

URL:http://router.project-osrm.org/viaroute?z=17&output=json&jsonp=OSRM.JSONP.callbacks.route&loc=55.686790,12.523600&loc=55.687610,12.528540&instructions=true

response extract:

  "route_instructions": [
    ["10", "Vej 6", 79, 0, 0, "79m", "N", 22],
    ["2", "Skadestuevejen", 177, 3, 42, "177m", "SE", 113],
    ["8", "Nordre Fasanvej", 127, 7, 13, "127m", "NE", 25],
    ["2", "Godthåbsvej", 67, 11, 3, "67m", "E", 112],
    ["15", "", 0, 13, 0, "", "N", 0.0]
  ],

@emiltin
Collaborator

another example. they are easy to find, and always seem to involve streets that go diagonally, rather than north-south and easy-west:

sharp:
http://osrm.at/2rp
http://osrm.at/2rq

slight:
http://osrm.at/2rr
http://osrm.at/2rs

@emiltin
Collaborator

i haven't been able to reproduce it in test though, which is annoying. in the first example, the instructions:

"route_instructions": [
["10", "Vej 6", 79, 0, 0, "79m", "N", 22],
["2", "Skadestuevejen", 177, 3, 42, "177m", "SE", 113],
["8", "Nordre Fasanvej", 127, 7, 13, "127m", "NE", 25],
["2", "Godthåbsvej", 67, 11, 3, "67m", "E", 112],
["15", "", 0, 13, 0, "", "N", 0.0]
],

correspond to degrees of
113-22 = 91
22-113 = -91
112-25 = 87

@emiltin
Collaborator

seems related to projection, since the angles are different from the bearing in the instructions, which are calculated using a different formula. (which hanndles projection?)

the bearing angles seems to match what you see on the map, where as the angles computed during contraction does not, which result in mismatched labels.

involved data:

55.68740,12.52430 # u: southeast
55.68745,12.52409 # v: junction
55.68711,12.52383 # w: southwest
=> angle: 245.987

360-246 = 114.

the angle is constructed by subtracting to intermediate angles -13 and -127, yielding -114, and finally adding 360 to avoid negative angles.

@emiltin
Collaborator

the following code results in correct turn instructions. it has more trig call, although a few tests on copenhagen data didn't show much overall slowdown.

it's just the bearing formular used twice, and then subtracting the two angles. anyone know how to simplify it? :-)

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 angle = a2-a1;

    if(angle < 0) {
        return angle + 360;
    } else {
        return angle;
    }
}

edit: a2-a1, not a1-a2.

@emiltin
Collaborator

simpler solution at #596

@DennisOSRM DennisOSRM closed this
@Zhdanovich Zhdanovich referenced this issue from a commit in Zhdanovich/Project-OSRM
DennisOSRM Compute turn angles in mercartor projection. Implements issues #596, 070cc01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.