Reputation: 29240
I want to calculate the minimum distance between a point and a bounding box which represents an area of latitude and longitude on a globe. If the point falls between the min-long and max-long then I can just compute the latitude distance which is easy since its a constant value. Otherwise I need to compute the distance using the Haversine formula from my point to the point on the longitudinal line that is closest to my point. I see a lot of info on calculating the distance between two points, but not so much on between a point and a line, or about finding the closest point on a line to a point.
Upvotes: 2
Views: 950
Reputation: 99094
You know how to find the distance between two points. Now you just need to know how to find the distance from a point to a great circle. The trick is to find the point equidistant from the whole great circle (the way the North pole is equidistant from the whole equator), find the distance from your point to that, then subtract from 90 degrees (with a +/-, depending on whether your point is on the same side of the circle as the pole you chose).
Once you have that trick down, notice that you're trying to find the distance from a point to a curve of constant longitude, which is a great circle whose "pole" is a point on the equator with longitude 90 degrees off from the curve.
(You'll probably have to draw a few pictures, but it really isn't that hard.)
Upvotes: 3