matlab利用经纬度计算距离,MATLAB函数可计算两个坐标(纬度和经度)之间的距离...

How can I calculate distance between two world map coordinates (latitude and longitude) using MATLAB R2015a (in meters)?

解决方案

If you don't have access to the MATLAB Mapping toolbox then a simple approximation is to use the Haversine formula. Here is an excerpt from the link:

The haversine formula is an equation important in navigation, giving great-circle distances between two points on a sphere from their longitudes and latitudes. It is a special case of a more general formula in spherical trigonometry, the law of haversines, relating the sides and angles of spherical triangles.

Here is a MATLAB implementation:

function rad = radians(degree)

% degrees to radians

rad = degree .* pi / 180;

end;

function [a,c,dlat,dlon]=haversine(lat1,lon1,lat2,lon2)

% HAVERSINE_FORMULA.AWK - converted from AWK

dlat = radians(lat2-lat1);

dlon = radians(lon2-lon1);

lat1 = radians(lat1);

lat2 = radians(lat2);

a = (sin(dlat./2)).^2 + cos(lat1) .* cos(lat2) .* (sin(dlon./2)).^2;

c = 2 .* asin(sqrt(a));

arrayfun(@(x) printf("distance: %.4f km\n",6372.8 * x), c);

end;

[a,c,dlat,dlon] = haversine(36.12,-86.67,33.94,-118.40); % BNA to LAX

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值