DateTime-Util-Astro

 view release on metacpan or  search on metacpan

lib/DateTime/Util/Astro/Sun.pm  view on Meta::CPAN

    
}

# [1] p.198, errata 179
sub sine_offset
{
    my($dt, $location, $alpha) = @_;
    my $phi   = $location->latitude;
    my $delta = asin_deg(
        sin_deg(obliquity($dt)) *
        sin_deg(solar_longitude($dt))
    );
    return tan_deg($phi) * tan_deg($delta) +
        (sin_deg($alpha) / (cos_deg($delta) * cos_deg($phi)));
}

# [1] p.198, errata 179
sub approx_moment_of_depression
{
    my($dt, $location, $alpha, $morning) = @_;

    my $try  = sine_offset($dt, $location, $alpha);
    my $date = POSIX::floor(moment($dt));
    my $alt  = $alpha >= 0 ?
        ($morning ? $date : $date + 1) :
        $date + 0.5;
    my $value = abs($try) > 1 ?
        sine_offset(dt_from_moment($alt), $location, $alpha) :
        $try;

    if (abs($value) <= 1) {
        return moment( local_from_apparent(
            dt_from_moment(
                $date + 0.5 +
                ($morning ? -1 : 1) *
                (mod(0.5 + asin_deg($value) / 360, 1) - 0.25)
            )
        ));
    } else {
        return undef;
    }
}

1;

__END__

=head1 NAME

DateTime::Util::Astro::Sun - Functions To Calculate Solar Data

=head1 SYNOPSIS

  use DateTime::Util::Astro::Sun qw(solar_longitude);
  my $longitude = solar_longitude($dt);

=head1 DESCRIPTION

This module provides functions to calculate solar data, but its main
focus is to provide just enough functionality that allows us to
create lunisolar calendars and other DateTime related modules.

This module is a *straight* port from "Calendrical Calculations" [1] --
and therefore there are places where things can probably be "fixed" so
that they look more like Perl, as well as places where we could
leverage the DateTime functionalities better. If you see things that
doesn't quite look right (in Perl), that's probably because of that.

=head2 Notes On Accuracy

Before you use this module, please be aware that this module was originally
created B<solely> for the purpose of creating a lunisolar calendar for
the DateTime project (http://datetime.perl.org). 

We used [1] as basis for our calculations. While for most purposes the
results are accurate enough, you should note that the calculations from
this book are I<approximations>. 

Obviously we would like to make this module as good as possible, but
there's only so much you can do in the accuracy department. However, having
L<GMP|http://www.swox.com/gmp> and Math::BigInt::GMP may help a little bit.

=head1 FUNCTIONS

=head2 solar_longitude($dt)

Given a DateTime object $dt, calculates the solar longitude at that time.

=head2 solar_longitude_after($dt, $phi)

=head2 solar_longitude_before($dt, $phi)

=head1 HELPER FUNCTIONS

=head2 estimate_prior_solar_longitude($dt, $pho)

=head2 approx_moment_of_depression($dt, $alpha, $location, $morning);

=head2 sine_offset($dt, $location, $alpha)

=head1 AUTHOR

Daisuke Maki E<lt>dmaki@cpan.orgE<gt>

=head1 REFERENCES

  [1] Edward M. Reingold, Nachum Dershowitz
      "Calendrical Calculations (Millenium Edition)", 2nd ed.
       Cambridge University Press, Cambridge, UK 2002

=head1 SEE ALSO

L<DateTime>
L<DateTime::Event::Lunar>
L<DateTime::Event::SolarTerm>
L<DateTime::Util::Astro::Common>
L<DateTime::Util::Astro::Moon>

=cut



( run in 0.547 second using v1.01-cache-2.11-cpan-39bf76dae61 )