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.
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 .
Thanks Patrick, I have fixed the singularity.
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
[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.
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).
- greatcircle: fixes the singularity when LON1 and LON2 have 180° of difference (thanks to Patrick Hew's comment)
- greatcircle: two possible syntaxes (output distances or path way)
BUG CORRECTION: bearing angle (and distances) are now with correct values.
- add loxodrome function