Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

Recommended Posts

Posted

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

Posted

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

  • Thanks 1
Posted

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

Posted

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

Posted

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...