% calculates distance and bearing between two points
function [dist,bear] = distbear(lat1, lon1, lat2, lon2)
    %dist = 2.*asin(sqrt((sin((lat1-lat2)/2)).^2 + cos(lat1).*cos(lat2).*(sin((lon1-lon2)/2)).^2));
    dist=acos(sin(lat1).*sin(lat2)+cos(lat1).*cos(lat2).*cos(lon1-lon2));
    bear = mod(atan2(sin(lon1-lon2).*cos(lat2), cos(lat1).*sin(lat2)-sin(lat1).*cos(lat2).*cos(lon1-lon2)), 2.*pi);
end

