Я никогда не имел дело с координатами WGS84 и я ржавый в этом типе математики, но я дам вам то, что пришло на ум. Я не отвечаю на этот вопрос, но это было слишком много, чтобы добавить комментарий, и у него есть psudo-код. Я просто подумал, что проблема была интересной и хотела немного поиграть с ней. Во всяком случае, здесь идет ...
Представьте себе совокупность всех сфер, центр которых является П.
Теперь, только одна из этих сфер должны разделить ровно 1 очко с AB. Если у вас есть уравнение, описывающее 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
Найдет расстояние прямой линии между Р и АВ до тех пор, как Eliptical отрезка АВ ближе к Р, чем любая другая часть эллипса, что AB лежит на. Если это неверно, достаточно просто проверить это и просто использовать ближе A или B как ближайшую точку.
Итак, вам действительно нужно расстояние между P и AB. Это сложнее, но вы, вероятно, можете изменить свой алгоритм для работы с этим.
См. Также [Как рассчитать расстояние от точки до сегмента линии, на сфере?] (Http://stackoverflow.com/questions/1299567/how-to-calculate-distance-from-a-point- к-а-линейного сегмента-на-сфере). – tsauerwein