使用半正式公式计算纬度/长点之间的距离 [英] Distance between lat/long points using the haversine formula

查看:158
本文介绍了使用半正式公式计算纬度/长点之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

 更改角度:0.00016244370761414 
地球半径:6371

结果:
正确距离:24.883 km
计算距离:1.0349288612097

来源:

  $ latStart = 44.638; 
$ longStart = -63.587;

$ latFinish = 44.644;
$ longFinish = -63.597;


#将输入转换为弧度
$ latStart = deg2Rad($ latStart);
$ longStart = deg2Rad($ longStart);

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

#因为地球不是完全球形的,所以没有单个值作为它的
#自然半径。从地表到中心的距离从
#6,353 km到6,384 km(≈3,947-3,968 mi)不等。将
#地球建模为球体的几种不同方式可以产生6371公里(≈3,959英里)的方便平均半径。
#http://en.wikipedia.org/wiki/Earth_radius
$ earthRadius = 6371;

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



#haversine公式
#对于小距离数值稳定
#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)

);



回声更改角度:$ changeAngle\\\
;
回显地球半径:$ earthRadius \\\
;


解决方案

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

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

约0.000167弧度,非常接近你的计算。 (甚至更多的信封检查:一个程度是大约69英里,这是有点超过100公里,所以0.01°应该有点超过1公里。)

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


I am trying to find the distance between two longitude and latitude points. I am trying ot use the great circle distance. This is the formula:

I am not sure why but my program is not working. This is the result I am getting:

Change Angle: 0.00016244370761414
Earth Radius: 6371

RESULTS: 
Correct  Distance: 24.883 km
Computed Distance: 1.0349288612097

Source:

$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";

解决方案

Let's do a back-of-the-envelope check using a planar approximation. The difference in latitude is 0.006°, and the difference in longitude is 0.01°, but multiply by cosine of latitude to get 0.0075°. Apply Pythagoras:

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

which is about 0.000167 radians, pretty close to your computation. (Even more back-of-the-envelope check: a degree is about 69 miles, which is a bit over 100 km, so 0.01° should be a bit over 1 km.)

So I think it's your alleged "Correct distance" that's wrong, not your computation.

这篇关于使用半正式公式计算纬度/长点之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆