MATLAB函数可计算两个坐标(纬度和经度)之间的距离 [英] MATLAB function to calculate distance between two coordinates (latitude and longitude)

查看:2947
本文介绍了MATLAB函数可计算两个坐标(纬度和经度)之间的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用MATLAB R2015a(以米为单位)计算两个世界地图坐标(纬度和经度)之间的距离?

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

推荐答案

如果您无权访问MATLAB映射工具箱,则一个简单的近似方法是使用

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:

haversine公式是一个在导航中很重要的方程式,它给出了球面上两个点之间的经度和纬度之间的大圆距离.这是球面三角法中更通用的公式的特例,这是正弦曲线的定律,它关系到球面三角形的边和角.

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.

此处 是MATLAB实现:

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

这篇关于MATLAB函数可计算两个坐标(纬度和经度)之间的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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