Let A,B and C be points on the Earth, for example. Suppose A and B are joined by a geodesic (so AB is a geodesic segment). How do you calculate the shortest distance from C to AB? I can easily calucate the distance to the great circle plane... simply take
N = A x B / | A x B |
Then, normalize C call it C' and so
C' . N = cos(<CON).
Then 90-<CON yields distance from C to the plane on which AB lives (after multiplying by appropriate radius of course). But this may not be the distance to the segment. For example, take A and B to be points, say (30 E, 0 N) and (30 W, 0 N) (resp.) and C = (180E, 0N). Then the distance of C to the equitorial plane is 0 but that is certainly not the distance from C to geodesic segment AB.
Can someone help me out here?
Thanks in advance.
> Let A,B and C be points on the Earth, for example. Suppose A and B are joined by a
> geodesic (so AB is a geodesic segment). How do you calculate the shortest distance
[quoted text clipped - 16 lines]
>
> Thanks in advance.
Maybe you should ask the question in comp.graphics.algorithms.
But here is an idea. Using your notation, let angle = 90 degrees-<CON
the angle that you calculated above. Then compute the vector
corresponding to that angle:
D = C - (C dot N)*N
and ajust the length of D to be the same as C.
D is the point on the great circle that contains A and B. As you said,
maybe this point doesn't lie inside the segment from A to B. To
determine this, compute the cross-products:
E = A x D
F = D x B
in that order. If both E and F are vectors in the same direction as
vector N that you calculated previously then D is inside the segment
from A to B and the angular distance that you want is 'angle'. If not
then compute the great circle distance between C and A and C and B to
determine which one is smallest.
This may not be the most efficient method though. It's just an idea,
and actually I'm not sure if it works :)
Paul - 10 Aug 2006 16:33 GMT
Thanks I will have to look at your idea and I'll let you know if it works out. For now here are some more interesting questions.
Suppose I have a set of points (lon1,lat1),...,(lon_n,lat_n) = (lon1,lat1) on the Earth. So we have a closed region which we shall call a "polygon". The edges of this region are geodesics (arc of great circles).
1) Given a point (phi, theta), how do I determine if (phi,theta) is contained in the given polygon?
In flatland this is easy, cast a ray from the point through the polygon and count the nubmer of intersections. Even intersections => not inside, odd => inside. This works even if the poly has holes.. we just have be be careful when the ray crosses a vertex (always some annoying case to watch out for).
So I'm wondering if there is a spherical analogue to the problem.
2) How do I find the centroid of the polygon?