Skip to content

Instantly share code, notes, and snippets.

@Umair444
Created January 16, 2022 08:03
Show Gist options
  • Save Umair444/e97f22540336f198af7ab71aacd2bbfb to your computer and use it in GitHub Desktop.
Save Umair444/e97f22540336f198af7ab71aacd2bbfb to your computer and use it in GitHub Desktop.
function d = greatCircleDistance(lat1, lon1, lat2, lon2)
R = 6371.1e3; % Mean Earth Radius
p1 = lat1*(pi/180);
p2 = lat2*(pi/180);
p = (lat2-lat1)*(pi/180);
l = (lon2-lon1)*(pi/180);
a = sin(p/2)*sin(p/2)+cos(p1)*cos(p2)*sin(l/2)*sin(l/2);
c = 2*atan2(sqrt(a), sqrt(1-a));
d = R*c;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment