File Exchange

image thumbnail

GREATCIRCLE and LOXODROME: "As the crow flies" and rhumb lin

version (5.16 KB) by François Beauducel
Computes "As the crow flies" path coordinates, distance and bearing on Earth along great circle or rhumb line.


Updated 28 May 2019

View Version History

View License

The function GREATCIRCLE computes the shortest path along the great circle ("as the crow flies") between two points defined by their geographic coordinates (latitude and longitude). With one output argument it returns distance or vector of distances, with two or more output arguments it returns path coordinates and optional vector of distances and bearing angles along the path.

The function LOXODROME computes the path with a constant bearing, crossing all meridians of longitude at the same angle. It returns also a vector of distances and the bearing angle.

Loxodrome path (also known as "rhumb line") is longer than great circle one, but still used in navigation as it is easier to follow with a compass.

Type "doc greatcircle" or "doc loxodrome" for syntax, help and examples.

Cite As

François Beauducel (2020). GREATCIRCLE and LOXODROME: "As the crow flies" and rhumb lin (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

François Beauducel

Thanks Patrick, I have fixed the singularity.

Patrick Hew

Caveat: GREATCIRCLE has difficulties when the longitude differs by 180 degrees, as in a great circle that passes through one of the poles. For example

load topo
[lat,lon] = greatcircle(48.8,2.3,35.7,2.3+180); % longitude differs by 180 degrees
hold on, plot(lon,lat,'r','linewidth',2), hold off
title('Supposed to be Paris then over the pole')

The problem is at line 104, because sind(lon1 - lon2) = 0.

Patrick Hew

Does what it says and does it well.

In GREATCIRCLE it may be worth commenting out the checks on the inputs that are performed at lines 76 and 84. My experience is that these checks account for a large fraction of the runtime. It's a matter of taste -- I prefer to have functions that trade off input argument checking for speed, so long as the functions concerned "fail noisily" on bad inputs that can be trapped during development.

Thanks again for your work on this.

François Beauducel

Note: update on Nov. 9, 2012 concerns only the loxodrome function: now it uses an exact calculation of bearing angle (using the Gudermann function).

MATLAB Release Compatibility
Created with R2019a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: pathdist

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!