2010-03-31 147 views
2

我在地球表面上的两个WGS84坐标之间(或者椭圆体上)有一条线段AB,需要计算点P和线段AB上最接近点P的点之间的距离。我怎样才能做到这一点?计算椭球(或WGS84坐标)上的点与线段之间的距离?

任何帮助,非常感谢。

问候, 约亨

+0

另请参见[如何计算从点到线段,在球体上的距离?](http://stackoverflow.com/questions/1299567/how-to-calculate-distance-from-a-point-到一个线段上-A-球体)。 – tsauerwein 2012-02-15 10:27:51

回答

1

我从来没有处理WGS84坐标和我这种类型的数学生疏,但我给你什么浮现在脑海。我没有真正回答这个问题,但是这太过分了,无法发表评论,而且它有psudo代码。我只是认为这个问题很有意思,并且想要稍微玩一下。总之,这里去...

试想集为中心的P.

现在,只有那些球的之一应该AB分享正好1点的所有领域的。如果你有一个描述AB的方程式,那么你应该能够找到与AB共享一个点的球体。

可能有一个比试验和错误更快速的方法来做到这一点,但二分搜索是想到的。这应该找到到AB的直线距离。如果你想要P和AB之间的不满,我会在代码之后分类。 psudocode:

Radius_lo = 0 
    Radius_hi = minimum(distance(P, A), distance(P, B)) 
    Radius_test = Raduis_hi // you may want to add a miniscule amount to this to keep from floating point inprecision from effectively rounding down which could lead to no actual intersection 
    while true 
     intersections = intersection_points(sphere(P, Radius_test), AB) 
     if (count(intersections) == 1) // or close enough. With floating pt math you'll likely need to recognize close enough or it will never exit. 
      return Radius_test 
     if (count(intersections) == 2) 
      // Here you may do one of two things, both of which are binary searches. 
      // 1. The first and simplest would be to divide average _test with _lo and try again 
      Radius_hi = Radius_test 
      Radius_test = (Radius_test + Radius_lo)/2 
      Continue 
      // 2. The second would be to attempt to divide the segment fromed by the two intersection points, which is more complicated, but would almost always result in fewer times through the loop 
      X = midpoint(intersection[0], intersection[1]) // midpoint would have to know how to find the midpoint of them along the elipse that they live on 
      Radius_test = distance(P, X) 
      Continue 
    if (count(intersections) == 0) 
      // Gone too far. If you had done (1) above, then do 
      Radius_lo = Radius_test 
      Radius_test = (Radius_test + Radius_hi)/2 
      Continue 
      // If on the otherhand you had done (2) above then you shouldn't ever have this case 
      error("0 intersections!") 
    // Now, this should be for any intersection count other than 0, 1, or 2. This shouldn't happen so 
    error("bad intersection count") 
    endloop // while true 

这只要滑步AB段比AB在于对elipse的任何其他部分更接近至P找到P和AB之间的直线距离。如果这不是真的,那么测试它应该很容易,只需使用A或B中最接近的点即可。

好的,所以你实际上想要P和AB之间的表面距离。这更复杂,但你可能会改变我的算法来处理这个问题。

相关问题