I came across a function that takes in 2 points on the earth as latitude/longitude and calculates the distance between them. Having been somewhat lacking in the trig back in highschool and college (I took the math light version of a CS BS degree), I'm at a loss as to how this works and (more importantly) the theories that make it work that way. Any enlightenment you could give me would be greatly appreciated.
function distance(Latitude1, Longitude1, Latitude2, Longitude2)
{
THETA = Longitude1 - Longitude2;
distance = sin(degrees_to_radians(Latitude1)) * sin(degrees_to_radians(Latitude2)) + cos(degrees_to_radians(Latitude1)) * cos(degrees_to_radians(Latitude2)) * cos(degrees_to_radians(THETA));
distance = acos(distance);
distance = radians_to_degrees(distance);
miles = distance * 60 * 1.1515;
return miles;
}
function distance(Latitude1, Longitude1, Latitude2, Longitude2)
{
THETA = Longitude1 - Longitude2;
distance = sin(degrees_to_radians(Latitude1)) * sin(degrees_to_radians(Latitude2)) + cos(degrees_to_radians(Latitude1)) * cos(degrees_to_radians(Latitude2)) * cos(degrees_to_radians(THETA));
distance = acos(distance);
distance = radians_to_degrees(distance);
miles = distance * 60 * 1.1515;
return miles;
}