
144
|
Chapter 3, Mapping Your World
#30 Plot a Great Circle on a Flat Map
HACK
Great Circles of Perl
In practice, great-circle routes are hard to navigate precisely, because the
bearing of a great circle relative to True North changes continually, unlike
that of a rhumb line. In fact, the conventional way to navigate a great-circle
route is to approximate it with a series of short rhumb lines. We can use this
same technique to draw the path of a great-circle arc on a flat map in Perl:
#!/usr/bin/perl
use Math::Trig qw(great_circle_direction deg2rad);
use Imager;
use strict;
my ($mapfile, $lon1, $lat1, $lon2, $lat2) = @ARGV;
my @origin = ($lon1, $lat1);
my @dest = ($lon2, $lat2);
my $step = .1;
my @position = @origin;
my @points;
until (abs($position[0] - $dest[0]) < $step
and abs($position[1] - $dest[1]) < $step) {
my $bearing = great_circle_direction(
deg2rad( $position[0] ),
Figure 3-33. Great-circle arc from San Francisco to London on a Gnomonic projection