File Exchange

image thumbnail

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

version 1.4.0.0 (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.

3 Downloads

Updated 28 May 2019

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 (2019). GREATCIRCLE and LOXODROME: "As the crow flies" and rhumb lin (https://www.mathworks.com/matlabcentral/fileexchange/37652-greatcircle-and-loxodrome-as-the-crow-flies-and-rhumb-lin), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

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
contour(0:359,-89:90,topo,[0,0],'k')
[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.

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

Updates

1.4.0.0

- greatcircle: fixes the singularity when LON1 and LON2 have 180° of difference (thanks to Patrick Hew's comment)

1.3.0.0

- greatcircle: two possible syntaxes (output distances or path way)
- loxodrome: bug correction

1.2.0.0

BUG CORRECTION: bearing angle (and distances) are now with correct values.

1.1.0.0

- add loxodrome function
- improve input argument checking

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

Inspired: pathdist