我试图找到两个经度和纬度点之间的距离。我正在尝试使用 great circle distance 。这是公式:

我不知道为什么,但我的程序不起作用。这是我得到的结果:

Change Angle: 0.00016244370761414
Earth Radius: 6371

RESULTS:
Correct  Distance: 24.883 km
Computed Distance: 1.0349288612097

来源:
$latStart = 44.638;
$longStart = -63.587;

$latFinish = 44.644;
$longFinish = -63.597;


# Convert Input to Radians
$latStart = deg2Rad($latStart);
$longStart = deg2Rad($longStart);

$latFinish = deg2Rad($latFinish);
$longFinish = deg2Rad($longFinish);

# Because the Earth is not perfectly spherical, no single value serves as its
# natural radius. Distances from points on the surface to the center range from
# 6,353 km to 6,384 km (≈3,947–3,968 mi). Several different ways of modeling the
# Earth as a sphere each yield a convenient mean radius of 6371 km (≈3,959 mi).
# http://en.wikipedia.org/wiki/Earth_radius
$earthRadius = 6371;

# difference in Long/Lat
$latChange = $latFinish - $latStart;
$longChange = $longFinish - $longStart;



# haversine formula
# numerically stable for small distances
# http://en.wikipedia.org/wiki/Great-circle_distance
$changeAngle = 2 * asin(
                sqrt(
                        pow(sin($latChange/2),2) +
                        cos($latStart) * cos($latFinish) * pow(sin($longChange/2),2)
                )
        );



echo "Change Angle: $changeAngle\n";
echo "Earth Radius: $earthRadius\n";

最佳答案

让我们使用平面近似进行全面检查。纬度差为0.006°,经度差为0.01°,但乘以纬度余弦得到0.0075°。应用毕达哥拉斯:

>>> sqrt(0.006 ** 2 + 0.0075 ** 2)
0.0096046863561492727

这大约是 0.000167 弧度,非常接近您的计算。 (更深入的检查:度数约为 69 英里,略高于 100 公里,因此 0.01° 应该略高于 1 公里。)

所以我认为这是你所谓的“正确距离”是错误的,而不是你的计算。

关于geometry - 使用半正弦公式计算纬度/经度点之间的距离,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4314209/

10-13 09:46