以下是解決了這個對我來說,
function point_to_line_segment_distance($startX,$startY, $endX,$endY, $pointX,$pointY)
{
$r_numerator = ($pointX - $startX) * ($endX - $startX) + ($pointY - $startY) * ($endY - $startY);
$r_denominator = ($endX - $startX) * ($endX - $startX) + ($endY - $startY) * ($endY - $startY);
$r = $r_numerator/$r_denominator;
$px = $startX + $r * ($endX - $startX);
$py = $startY + $r * ($endY - $startY);
$closest_point_on_segment_X = $px;
$closest_point_on_segment_Y = $py;
$distance = user_bomb_distance_calc($closest_point_on_segment_X, $closest_point_on_segment_Y, $pointX, $pointY);
return array($distance, $closest_point_on_segment_X, $closest_point_on_segment_Y);
}
function user_bomb_distance_calc($uLat , $uLong , $bLat , $bLong)
{
$earthRadius = 6371; #km
$dLat = deg2rad((double)$bLat - (double) $uLat);
$dlong = deg2rad((double)$bLong - (double) $uLong);
$a = sin($dLat/2) * sin($dLat/2) + cos(deg2rad((double)$uLat)) * cos(deg2rad((double)$bLat)) * sin($dlong/2) * sin($dlong/2);
$c = 2 * atan2(sqrt($a), sqrt(1 - $a));
$distance = $earthRadius * $c;
$meter = 1000; //convert to meter 1KM = 1000M
return intval($distance * $meter) ;
}
你說的一個座標的「名單」的意思。你想要兩個人之間的每一個可能的協調,有6個有效數字?或者你想要兩點之間的線的方程?還是你想要完全的東西? –
是的,兩者之間的每一個可能的座標,有5位有效數字就足夠了。我會澄清我的問題。謝謝。 –
如果您包含最終用途以及您已經嘗試過的內容,它將有助於SO用戶。你的計算將產生一個非常大的排列列表。爲什麼你想在算法更好的時候將它們全部列出來? – nickhar