Earthquake/mydistance.m

25 lines
956 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.

function out=mydistance(fiA,LA,fiB,LB) % расстояние по координатам
%% By L_DelOff
% out[км]=mydistance(fiA,LA,fiB,LB[всё градусы])
% cos(d) = sin(φА)·sin(φB) + cos(φА)·cos(φB)·cos(λА λB),
% где φА и φB — широты, λА, λB — долготы данных пунктов,
% d — расстояние между пунктами, измеряемое в радианах длиной дуги
% большого круга земного шара.
if LA>180
LA=LA-360;
end
if LB>180
LB=LB-360;
end
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