Been doing some distance calculations using lattitude and longitude. One of the things that I needed to know was the number of miles in a degree of longitude at the equator. The answer is 69.1703234283616.
I was also needing to calculate if two points were within each others radius. For instance if point 1 has a radius of 10 miles, and point 2 has a radius of 25 miles, do the circles that those radii form intersect each other anywhere. The formula for this is below:
(r1 + r2) ^ 2 <= (clat1 - clat 2) ^ 2 + (clon1 - clon2) ^ 2
where
lat1 = the latitude of the first point
lat2 = the latitude of the second point
lon1 = the longitude of the first point
lon2 = the longitude of the second point
r1 = the radius from the first point
r2 = the radius from the second point
clat1 = (lat1 * 69.1703234283616)
clat2 = (lat2 * 69.1703234283616)
clon1 = ((lon1 * 69.1703234283616) * cos(lat1))
clon2 = ((lon2 * 69.1703234283616) * cos(lat2))
Now, since clat1, clat2, clon2, and clon2 all use constants, or lat/lon values of the same point, the calculation results will be the same everytime for a particluar lat/lon pair, so I store the results of these calculation in the database as well, to save calculation time later.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment