2010-03-31 148 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之間的表面距離。這更復雜,但你可能會改變我的算法來處理這個問題。

相關問題