Just for reference, here is the quick and dirty implementation I threw together after consulting several pages at Wikipedia:

sub acos { atan2( sqrt(1-$_[0]*$_[0]), $_[0] ) } sub asin { atan2( $_[0], sqrt(1-$_[0]*$_[0]) ) } my $pi= atan2(0,-1); my @c= ( 33.943603, -118.408189, 39.17965, -76.668824 ); my $lat1= $c[0]/180*$pi; my $lat2= $c[2]/180*$pi; my $dlong= ($c[1]-$c[3])/180*$pi; my $ang= acos( sin($lat1)*sin($lat2) + cos($lat1)*cos($lat2)*cos($dlong) ); my $max= $ang * 3_963.19059; my $min= $ang * 3_949.90257; printf "%.1f .. %.1f miles (%.2f range)\n", $min, $max, $max-$min; my $h1= sin(($lat1-$lat2)/2); my $h2= sin($dlong/2); $ang= 2*asin( sqrt( $h1*$h1 + cos($lat1)*cos($lat2)*$h2*$h2 ) ); $max= $ang * 3_963.19059; $min= $ang * 3_949.90257; printf "%.1f .. %.1f miles (%.2f range)\n", $min, $max, $max-$min; __END__ 2318.6 .. 2326.4 miles (7.80 range) 2318.6 .. 2326.4 miles (7.80 range)

And if somebody tells you that a >10% error is due to Earth being an oblate spheroid, tell them that such a discrepancy would be less than 0.34%.

- tye        


In reply to Re: Alternatives To Geo::Distance (hack) by tye
in thread Alternatives To Geo::Distance by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.