| ??? 01/16/08 15:44 Read: times Msg Score: +1 +1 Good Answer/Helpful |
#149570 - Much better Responding to: ???'s previous message |
Ap said:
Language problem , here I think I have written enough English, but maybe not enough :) . I would need to update every second my vehicle GPS coordinates , all other are stationary . I have said earlier , my vehicle is moving , it searches the telemetry and list the received coordinates. It then reads its own coordinates in real time , and it then has to calculate the approaching most nearby node the roadside out of all listed nodes. I feel I have explained my requirement here , if still I am not able to explain correctly please ask for clarification. That is much better. I think I understand now. Here is what I would do:
Calculate north-south distance:
Y = latitude A - latitude B
Calculate east-west distance:
X = longitude A - longitude B
Adjust east-west distance for latitude
XA = X * cos(latitude A)
Calculate total distance:
D = square root ((XA * XA) + (Y * Y))
Notes:
1. The distances in these formulas are expressed in degrees of
latitude along the surface of the Earth, so one degree is
equivalent to roughly 69 miles.
2. For calculating the cosine function, you have several options:
A) Write your program in a HLL and use its library function,
B) Use a table lookup or some other simple approximation. C)
If you know that you will always be operating within a narrow
range of latitudes, consider simply using a constant for
cos(latitude A).
3. If you are only interested in finding the closest object, and
don't care about the actual distances, you don't have to
compute the square root in the last step. Just calculate the
value ((XA * XA) + (Y * Y)) for each case and compare those
results to find the closest object.
-- Russ
|



