DateTime-Event-Jewish
view release on metacpan or search on metacpan
lib/DateTime/Event/Jewish/Haversine.pm view on Meta::CPAN
package DateTime::Event::Jewish::Haversine;
use strict;
use warnings;
use base qw(Exporter);
use vars qw(@EXPORT_OK);
@EXPORT_OK = qw(recalculate_coordinate azimuth elevation point2distance);
use Math::Trig;
our $VERSION = '0.01';
# Python implementation of Haversine formula
# Copyright (C) <2009> Bartek Garny <bartek at gorny.edu.pl>
# Converted to Perl by Raphael Mankin <rapmankin at cpan.org> Feb 2010
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
lib/DateTime/Event/Jewish/Haversine.pm view on Meta::CPAN
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>
#
# Apparent angular diameters
# Sun: 31.6' - 32.7'
# Moon: 29.3' - 34.1'
=head1 NAME
Haversine.pm - Calculations using haversine formula
=head1 SYNOPSIS
use Haversine;
my $degrees = recalculate_coordinate([51, 12, 0], 'deg');
my $radians = recalculate_coordinate([51, 12, 0], 'rad');
my $km = points2distance($start, $end);
my $degrees = azimuth($start, $end, 'deg');
=cut
lib/DateTime/Event/Jewish/Haversine.pm view on Meta::CPAN
if ($_as eq 'deg') { return $sec / 3600;}
if ($_as eq 'rad') { return deg2rad($sec / 3600);}
}
return [$deg, $min, $sec];
}
=head3 points2distance($start, $end)
Calculate distance (in kilometers) between two points
given as (lat, long) pairs based on Haversine formula
(http://en.wikipedia.org/wiki/Haversine_formula).
Implementation inspired by JavaScript implementation from http://www.movable-type.co.uk/scripts/latlong.html
Accepts coordinates as tuples (deg, min, sec), but coordinates can be given in any form - e.g.
can specify only minutes:
(0, 3133.9333, 0)
is interpreted as
(52.0, 13.0, 55.998000000008687)
which, not accidentally, is the latitude of Warsaw, Poland.
=cut
lib/DateTime/Event/Jewish/Haversine.pm view on Meta::CPAN
if ($_as) {
if ($_as eq 'rad'){ return $c;}
if ($_as eq 'deg'){ return rad2deg($c);}
}
return 6371 * $c;
}
=head3 azimuth($start, $end)
Calculate azimuth (bearing) of one point from another
given as (lat, long) pairs based on Haversine formula
=cut
sub azimuth {
my ($start, $end) = @_;
shift; shift;
my $_as= shift||'deg';
# Calculate the azimuth (initial bearing) to travel by a
# great circle path from 'start' to 'end'
( run in 0.920 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )