I am programming for a transportaion system which every 5 second I have to check if there are drivers nearby the start point. I know that it is not optimum solution If I loop through all thousnads drivers and calculate the distance using (LAT,LONG) so I want to simplify the calculations just by linear difference between the (LAT,LONG) of start point and the drivers to be in specific range. My problem is how to calculate this RANGE to satisfy the minimum desired distance in a specific area.
list of variables:
- The targt area of activity is beteewn
- The start Point is
(lat0,long0)which is in bounds of area.
- Drivers position is any point
(latD,longD)which is in the bounds of area.
- The real DISTANCE is calculated using a complex spherical formula between start point and drivers point (Please see the footnotes).
- I want to simplify the distance check just by comparing
abs(lat0 - latD)< Rangealso
abs(long0-longD)<Range. The Range should be the minimum number which if satisfies these two formula, so the real DISTANCE also should be Less than the MINIMUM.
in brief find the relation between RANGE and MINIMM which:
(abs(lat0 - latD)< Range) && (abs(long0 - longD)<Range)
Distance < Minimum
How should I calculate the RANGE within the defined area to satisfy all points in this area? I am aware that using a single RANGE causes the low accuracy in different points of the area but I am looking for minimum one which satisfies all points (or perhaps an optimum one).
Footnote: obviousley the RANGE is independent of drivers position and should be calculated using these 7 parameters (LAT0,LONG0),(LAT1,LONG1),(LAT2,LONG2) and MINIMUM.
Footnote2: The real Forumla for spherical Distance between
(latD,lonD) by assuming the earth radius (Ref.):
function distance(lat0, lon0, latD, lonD) p = 0.017453292519943295 a = 0.5 - cos((latD - lat0) * p)/2 + cos(lat0 * p) * cos(latD * p) * (1 - cos((lonD - lon0) * p))/2 distance = 12742 * arcsin(sqr(a)) end function
I guess I need a mapping from spherical to Cartesian system to convert that curved area to a flat square? Do you have any other idea? Do you deep dive into that complex formula to extract
latD - lat0 from the shark's mouth? :))