Haversine formula: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 2,317: | Line 2,317: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
===Low-Level=== |
|||
{{libheader|ntheory}} |
{{libheader|ntheory}} |
||
<lang perl>use ntheory qw/Pi/; |
<lang perl>use ntheory qw/Pi/; |
||
Line 2,339: | Line 2,342: | ||
{{out}} |
{{out}} |
||
<pre>Distance: 2887.260 km</pre> |
<pre>Distance: 2887.260 km</pre> |
||
===Idiomatic=== |
|||
Contrary to ntheory, Math::Trig is part of the Perl core distribution. |
|||
It comes with a great circle distance built-in. |
|||
<lang perl>use Math::Trig qw(great_circle_distance deg2rad); |
|||
# Notice the 90 - latitude: phi zero is at the North Pole. |
|||
# Parameter order is: LON, LAT |
|||
my @BNA = (deg2rad(-86.67), deg2rad(90 - 36.12)); |
|||
my @LAX = (deg2rad(-118.4), deg2rad(90 - 33.94)); |
|||
print "Distance: ", great_circle_distance(@BNA, @LAX, 6372.8), " km\n";</lang> |
|||
{{out}} |
|||
<pre>Distance: 2887.25995060711 km</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |