Earthquake/haversine2km.m

24 lines
991 B
Matlab
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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