Coding Thread, Help with geometry please in Coding and Web Development; In my speedlimit 'droid app I search my database for signs &quot;pointing&quot; in same direction as you are travelling and ...
1. ## Help with geometry please

In my speedlimit 'droid app I search my database for signs "pointing" in same direction as you are travelling and then it matches up the nearest one.

Minor problem is that that it will match up to a sign that is "behind" you as its nearer than the nearest one ahead of you.

Its not a real problem as it only changes the speedlimit if a sign is within a 100m range but I'd like my app to ignore signs that are "behind" me

So the info available is a database of signs with the direction they "point" in (0-369 0 being North) and x y (lat long) positions and I know where I am x y (lat long) pos and which direction I'm travelling in (0-359 0 being North).

Anyone up for the maths challenge?

regards
Si

2. Ok, I'll have a go:

I'm assuming 90 degrees in your system means East (just to be awkward).
I'll be using conventional angles with 0 = 'East' and increasing anti-clockwise.

Sign is at (xs, ys)
Vehicle is at (xv, yv)
Traveling direction of vehicle is 'trav'

Direction of sign from vehicle is (180/pi)*atan2((ys-yv), (xs-xs))

Direction of vehicle travel in same coordinate system is: 90 - trav

If vehicle is traveling towards sign you will have abs((180/pi)*atan2((ys-yv), (xs-xs)) - 90 + trav) < 180

3. ## Thanks to keithu from:

SimpleSi (21st August 2010)

4. Looks good testing at home - I'll try it out on the road tomorrow
Ta
Your algorithm much shorter and quicker than my attempt - cut the testing loop time from 180ms to 110ms

regards

Simon

5. Hi Simon

I think there's a problem with that formula if the angles become negative (plus I should have put < 90 really).

This is my latest attempt:

((180/pi)*atan2((ys-yv), (xs-xs)) +270 + trav) % 360 < 180

6. This is what I ended up using

int eduAngleToSign = Math.abs((int)((180/3.1415926) * Math.atan2((double)latDist,(double)longDist)) - 90 + Bearing);

which is just me wrapping your original code within an ABS statement.

I then test whether eduAngleToSign < 30 which should be covering a 60 degree arc

I'm in the process of adding some logging to the app so I can just drive around and then analyse the data back at home to see what the algorithm is doing

regards

Simon

SHARE: