Files
Earthquake/haversine2km.m
2021-06-12 00:26:34 +03:00

24 lines
991 B
Matlab
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

d=distance(55.7522,37.6156,51.7373,36.1873) % Мск Курск
disp(d)
function rad = radians(degree) % градусы в радианы
rad = degree .* pi / 180;
end
function out=distance(fiA,LA,fiB,LB) % расстояние по координатам
% cos(d) = sin(φА)·sin(φB) + cos(φА)·cos(φB)·cos(λА λB),
% где φА и φB — широты, λА, λB — долготы данных пунктов,
% d — расстояние между пунктами, измеряемое в радианах длиной дуги
% большого круга земного шара.
fiA=radians(fiA);
LA=radians(LA);
fiB=radians(fiB);
LB=radians(LB);
d = acos(sin(fiA)*sin(fiB) + cos(fiA)*cos(fiB)*cos(LA-LB));%
% Расстояние между пунктами, измеряемое в километрах,
% определяется по формуле:
% L = d·R,
% где R = 6371 км — средний радиус земного шара.
out=d*6371;
end