+ Post New Thread
Results 1 to 5 of 5
Coding Thread, Help with geometry please in Coding and Web Development; In my speedlimit 'droid app I search my database for signs "pointing" in same direction as you are travelling and ...
  1. #1

    SimpleSi's Avatar
    Join Date
    Jun 2005
    Location
    Lancashire
    Posts
    5,829
    Thank Post
    1,476
    Thanked 595 Times in 446 Posts
    Rep Power
    170

    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. #2

    Join Date
    Oct 2007
    Location
    Lincolnshire
    Posts
    133
    Thank Post
    0
    Thanked 22 Times in 22 Posts
    Rep Power
    18
    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. #3

    SimpleSi's Avatar
    Join Date
    Jun 2005
    Location
    Lancashire
    Posts
    5,829
    Thank Post
    1,476
    Thanked 595 Times in 446 Posts
    Rep Power
    170
    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. #4

    Join Date
    Oct 2007
    Location
    Lincolnshire
    Posts
    133
    Thank Post
    0
    Thanked 22 Times in 22 Posts
    Rep Power
    18
    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. #5

    SimpleSi's Avatar
    Join Date
    Jun 2005
    Location
    Lancashire
    Posts
    5,829
    Thank Post
    1,476
    Thanked 595 Times in 446 Posts
    Rep Power
    170
    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:
+ Post New Thread

Similar Threads

  1. [Video] Cardstock Geometry Puzzle
    By DaveP in forum Jokes/Interweb Things
    Replies: 0
    Last Post: 1st December 2009, 12:24 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •