2

地表 (または楕円体) 上の 2 つの WGS84 座標間に線分 AB があり、点 P と線分 AB 上の P に最も近い点の間の距離を計算する必要があります。これどうやってするの?

どんな助けでも大歓迎です。

よろしく、ヨッヘン

4

1 に答える 1

1

私は WGS84 座標を扱ったことがなく、このタイプの数学には慣れていませんが、思いついたことをお伝えします。私はこの質問に実際に答えているわけではありませんが、コメントするには多すぎて、疑似コードが含まれています。問題が面白いと思ったので、少し遊んでみたいと思いました。とにかく、ここに行く...

中心が P であるすべての球の集合を想像してください。

ここで、これらの球の 1 つだけが AB と正確に 1 点を共有する必要があります。AB を表す方程式がある場合、AB とちょうど 1 点を共有する点を中心とする球を見つけることができるはずです。

試行錯誤よりも迅速にこれを行う方法があるかもしれませんが、思いつくのは二分探索です。これは、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 の近い方を最も近い点として使用するだけです。

OK、実際には P と AB の間の表面距離が必要でした。これはより複雑ですが、それで動作するように私のアルゴリズムを変更できる可能性があります。

于 2010-04-03T21:36:50.177 に答える