已经两点经纬度,计算两点之间距离

距离计算有两种公式,VincentyHaversine,前者经度很高,可以达到0.5毫米,但是速度慢;后者速度快,但是经度差点,但是也不含糊,实际中很常用,只要是精度要求不是特别高的例如航空、导弹等的领域,还是很实用的。例如在只能网联汽车领域,后者应用很广泛。

原文见:
计算球面两点间距离实现Vincenty+Haversine

这里将上述链接中Vincenty公式的源码copy过来:

double toRadians(double a)
{
	return a*(PI/180)
}

//return the distance of two point, unit is meter
double distance_2(double latitude1, double longitude1, double latitude2, double longitude2) {
    // R is the radius of the earth in meters
    double R = 6371004;  //EARTH_RADIUS
    double deltaLatitude = toRadians(latitude2-latitude1);
    double deltaLongitude = toRadians(longitude2-longitude1);
    latitude1 =toRadians(latitude1);
    latitude2 =toRadians(latitude2);
    double a = pow(sin(deltaLatitude/2), 2)+ cos(latitude1)* cos(latitude2)* pow(sin(deltaLongitude/2), 2);
    double c = 2 * atan2(sqrt(a),sqrt(1-a));

    double d = R * c;
    return d;
}

更详细的讲解见:根据两点的经纬度求方位角和距离
这里有详细的公式噢~

文章中的提到的球面正弦定律,没有详细展开,这里补充下:
球面三角正弦定理

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值