## Plan the Shortest Path

You know that the shortest path between two geographic points is a great circle. Sailors and aviators are interested in minimizing distance traveled, and hence time elapsed. You also know that the rhumb line is a path of constant heading, the natural means of traveling. In general, to follow a great circle path, you would have to continuously alter course. This is impractical. However, you can approximate a great circle path by rhumb line segments so that the added distance is minor and the number of course changes minimal.

Surprisingly, very few rhumb line track legs are required to closely approximate the distance of the great circle path.

Consider the voyage from Norfolk, Virginia (37°N,76°W), to Cape St. Vincent, Portugal (37°N,9°W), one of the most heavily trafficked routes in the Atlantic. A due-east rhumb line track is 3,213 nautical miles, while the optimal great circle distance is 3,141 nautical miles.

Although the rhumb line path is only a little more than 2% longer, this is an additional 72 miles over the course of the trip. For a 12-knot tanker, this results in a 6-hour delay, and in shipping, time is money. If just three rhumb line segments are used to approximate the great circle, the total distance of the trip is 3,147 nautical miles. Our tanker would suffer only a half-hour delay compared to a continuous rhumb line course. Here is the code for computing the three types of tracks between Norfolk and St. Vincent:

```figure('color','w'); ha = axesm('mapproj','mercator',... 'maplatlim',[25 55],'maplonlim',[-80 0]); axis off, gridm on, framem on; setm(ha,'MLineLocation',15,'PLineLocation',15); mlabel on, plabel on; load coastlines; hg = geoshow(coastlat,coastlon,'displaytype','line','color','b'); % Define point locs for Norfolk, VA and St. Vincent, Portugal norfolk = [37,-76]; stvincent = [37, -9]; geoshow(norfolk(1),norfolk(2),'DisplayType','point',... 'markeredgecolor','k','markerfacecolor','k','marker','o') text(-0.61,0.66,'Norfolk','HorizontalAlignment','left') geoshow(stvincent(1),stvincent(2),'DisplayType','point',... 'markeredgecolor','k','markerfacecolor','k','marker','o') text(0.54,0.66,'St. Vincent','HorizontalAlignment','right') % Compute and draw 100 points for great circle gcpts = track2('gc',norfolk(1),norfolk(2),... stvincent(1),stvincent(2)); geoshow(gcpts(:,1),gcpts(:,2),'DisplayType','line',... 'color','red','linestyle','--') text(-0.02,0.85,'Great circle: 3,141 nm (optimal)',... 'color','r','HorizontalAlignment','center') % Compute and draw 100 points for rhumb line rhpts = track2('rh',norfolk(1),norfolk(2),... stvincent(1),stvincent(2)); geoshow(rhpts(:,1),rhpts(:,2),'DisplayType','line',... 'color',[.7 .1 0],'linestyle','-.') text(-0.02,0.66,'Direct course: 3,213 nm',... 'color',[.7 .1 0],'HorizontalAlignment','center') % Compute and draw path along three waypoints [latpts,lonpts] = gcwaypts(norfolk(1),norfolk(2),... stvincent(1),stvincent(2),3); geoshow(latpts,lonpts,'DisplayType','line',... 'color',[.4 .2 0],'linestyle','-') text(-0.02,0.75,'3-leg approximation: 3,149 nm',... 'color',[.4 .2 0],'HorizontalAlignment','center') ```
The resulting tracks and distances are shown below:

The Mapping Toolbox™ function `gcwaypts` calculates waypoints in navigation track format in order to approximate a great circle with rhumb line segments. It uses this syntax:

`[latpts,lonpts] = gcwaypts(lat1,lon1,lat2,lon2,numlegs)`

All the inputs for this function are scalars a (starting and an ending position). The `numlegs` input is the number of equal-length legs desired, which is 10 by default. The outputs are column vectors representing waypoints in navigational track format (`[heading distance]`). The size of each of these vectors is `[(numlegs+1) 1]`. Here are the points for this example:

```[latpts,lonpts] = gcwaypts(norfolk(1),norfolk(2),... stvincent(1),stvincent(2),3) % Compute 3 waypoints```
```latpts = 37.0000 41.5076 41.5076 37.0000 lonpts = -76.0000 -54.1777 -30.8223 -9.0000 ```

These points represent waypoints along the great circle between which the approximating path follows rhumb lines. Four points are needed for three legs, because the final point at Cape St. Vincent must be included.

Now we can compute the distance in nautical miles (nm) along each track and via the waypoints:

```drh = distance('rh',norfolk,stvincent); % Get rhumb line dist (deg) dgc = distance('gc',norfolk,stvincent); % Get gt. circle dist (deg) % Compute headings and distances for the waypoint legs [course distnm] = legs(latpts,lonpts,'rh'); ```
Finally, compare the distances:
```distrhnm = deg2nm(drh) % Nautical mi along rhumb line distgcnm = deg2nm(dgc) % Nautical mi along great circle distlegsnm = sum(distnm) % Total dist along the 3 legs rhgcdiff = distrhnm - distgcnm % Excess rhumb line distance trgcdiff = distlegsnm - distgcnm % Excess distance along legs ```
```distrhnm = 3.2127e+003 distgcnm = 3.1407e+003 distlegsnm = 3.1490e+003 rhgcdiff = 71.9980 trgcdiff = 8.3446```
Following just three rhumb line legs reduces the distance travelled from 72 nm to 8.3 nm compared to a great circle course.

Get trial now