Calculate distance from geographics points
1 次查看(过去 30 天)
显示 更早的评论
Hi, I have two vectors of coordinates, latitude and longitude, of points describing the centerline of a track. I want to create a distance channel to plot some quantities (e.g. velocity) as function of this distance, how can I create a distance channel of the same numerosity of the two vectors of coordinates?
0 个评论
回答(1 个)
KSSV
2022-4-25
编辑:KSSV
2022-4-25
USe Haversine's formula:
Let (lon1,lat1) and (lon2,lat2) be your coordinates in degrees.
% Haversine formula
dlon = lon2 - lon1 ;
dlat = lat2 - lat1 ;
a = sind(dlat/2)^2 + cos(dlat1)*cosd(lat2)*sin(dlon/2)^2 ;
c = 2*asind(sqrt(a)) ;
d = 6367*c ; % distance in km
11 个评论
Bruno Luong
2022-4-26
编辑:Bruno Luong
2022-4-26
Just wonder do you have you long / lat in degree or radian?
My code supposes long/lat in radian as you see it use cos function on them.
180/pi % ratio bewteen rad and deg
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Bug Finder Analysis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!