more useful options PerlMonks

### Re: Alternatives To Geo::Distance (hack)

by tye (Sage)
 on Oct 21, 2010 at 19:22 UTC ( #866624=note: print w/replies, xml ) Need Help??

in reply to Alternatives To Geo::Distance

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

Replies are listed 'Best First'.
Re^2: Alternatives To Geo::Distance (hack)
by BrowserUk (Pope) on Oct 22, 2010 at 09:59 UTC

It seems to rapidly screw up as you move north.

The distance from (0,0)-(10,10) should be the same as from (80,0)-(90,10) as shown by the Geo::Distance output. Or should it?

```[0,0][10,10]
geo: 974.731395416589
972.5 .. 975.7 miles (3.27 range)
972.5 .. 975.7 miles (3.27 range)
[10,0][20,10]
geo: 974.731395416589
957.7 .. 960.9 miles (3.22 range)
957.7 .. 960.9 miles (3.22 range)
[20,0][30,10]
geo: 974.731395416589
929.4 .. 932.5 miles (3.13 range)
929.4 .. 932.5 miles (3.13 range)
[30,0][40,10]
geo: 974.731395416589
889.9 .. 892.9 miles (2.99 range)
889.9 .. 892.9 miles (2.99 range)
[40,0][50,10]
geo: 974.731395416589
842.7 .. 845.5 miles (2.84 range)
842.7 .. 845.5 miles (2.84 range)
[50,0][60,10]
geo: 974.731395416589
792.8 .. 795.5 miles (2.67 range)
792.8 .. 795.5 miles (2.67 range)
[60,0][70,10]
geo: 974.731395416589
746.2 .. 748.7 miles (2.51 range)
746.2 .. 748.7 miles (2.51 range)
[70,0][80,10]
geo: 974.731395416589
709.6 .. 712.0 miles (2.39 range)
709.6 .. 712.0 miles (2.39 range)
[80,0][90,10]
geo: 974.731395416589
689.4 .. 691.7 miles (2.32 range)
689.4 .. 691.7 miles (2.32 range)

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
The distance should go down closer to the pole. (90,10) and (90,0) are the same point.

If you start at the north pole and walk one mile to the south and then one mile to the west you are still one mile to the south of the north pole. At the equator you will get a hypotenuse.

Create A New User
Node Status?
node history
Node Type: note [id://866624]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
As of 2018-07-22 20:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

Results (455 votes). Check out past polls.

Notices?