2

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

任何帮助是极大的赞赏。

问候, 约臣

4

1 回答 1

1

我从来没有处理过 WGS84 坐标并且对这种类型的数学很生疏,但我会给你我想到的。我并没有真正回答这个问题,但这太多了,无法发表评论,而且它有伪代码。我只是觉得这个问题很有趣,想尝试一下。无论如何,这里...

想象中心为 P 的所有球体的集合。

现在,这些球体中只有一个应该与 AB 共享 1 点。如果你有一个描述 AB 的方程,那么你应该能够找到以它为中心的球体与 AB 正好共享一个点。

可能有比试错更快的方法来做到这一点,但我想到的是二分搜索。这应该找到到 AB 的直线距离。如果您想要 P 和 AB 之间的距离,我将在代码之后进行介绍。伪代码:

   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 所在的椭圆的任何其他部分更接近 P,这将找到 P 和 AB 之间的直线距离。如果这不是真的,那么测试应该很容易,只需使用 A 或 B 中的较近者作为最近点。

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

于 2010-04-03T21:36:50.177 回答