NAME

Astro::Montenbruck::Ephemeris - calculate planetary positions.

SYNOPSIS

Iterator interface

use Astro::Montenbruck::Ephemeris::Planet qw/@PLANETS/;
use Astro::Montenbruck::Ephemeris qw/iterator/;
use Data::Dumper;

my $jd = 2458630.5; # Standard Julian date for May 27, 2019, 00:00 UTC.
my $t  = ($jd - 2451545) / 36525; # Convert Julian date to centuries since epoch 2000.0
                                  # for better accuracy, convert $t to Ephemeris (Dynamic) time.
my $iter = iterator( $t, \@PLANETS ); # get iterator function for Sun. Moon and the planets.

while ( my $result = $iter->() ) {
    my ($id, $co) = @$result;
    print $id, "\n", Dumper($co), "\n"; # geocentric longitude, latitude and distance from Earth
}

Callback interface

use Astro::Montenbruck::Ephemeris::Planet qw/@PLANETS/;
use Astro::Montenbruck::Ephemeris qw/find_positions/;

my $jd = 2458630.5; # Standard Julian date for May 27, 2019, 00:00 UTC.
my $t  = ($jd - 2451545) / 36525; # Convert Julian date to centuries since epoch 2000.0
                                  # for better accuracy, convert $t to Ephemeris (Dynamic) time.

find_positions($t, \@PLANETS, sub {
    my ($id, %pos) = @_;
    say "$id X: $pos{x}, Y: $pos{y}, Z: $pos{z}";
})

DESCRIPTION

Calculates apparent geocentric ecliptic coordinates of the Sun, the Moon, and the 8 planets. Algorithms are based on "Astronomy on the Personal Computer" by O.Montenbruck and Th.Pfleger. The results are supposed to be precise enough for amateur's purposes:

"The errors in the fundamental routines for determining the coordinates
of the Sun, the Moon, and the planets amount to about 1″-3″."

-- Introduction to the 4-th edition, p.2.

You may use one of two interfaces: iterator and callback.

The coordinates are referred to the true equinox of date and contain corrections for precession, nutation, aberration and light-time.

Implementation details

This module is implemented as a "factory". User may not need all the planets at once, so each class is loaded lazily, by demand.

Mean daily motion

To calculate mean daily motion along with the celestial coordinates, use with_motion option:

iterator( $t, \@PLANETS, with_motion => 1 );
# Or:
find_positions($t, \@PLANETS, $callback, with_motion => 1);

That will slow down the program.

Pluto

Pluto's position is calculated only between years 1890 and 2100. See Astro::Montenbruck::Ephemeris::Planet::Pluto.

Universal Time vs Ephemeris Time

For better accuracy the time must be given in Ephemeris Time (ET). To convert UT to ET, use t2dt function from Astro::Montenbruck::Time module.

SUBROUTINES

iterator($t, $ids, %options)

Returns iterator function, which, on its turn, when called returns either undef, when exhausted, or arrayref, containing:

  • identifier of the celestial body, a string

  • a hashref, containing celestial coordinates and mean daily motion

Coordinates and daily motion

  • x — celestial longitude, arc-degrees

  • y — celestial latitude, arc-degrees

  • z — distance from Earth in A.U.

  • motion — mean daily motion, degrees, (only when with_motion flag is set)

Positional Arguments

  • $t — time in centuries since epoch 2000.0; for better precision UTC should be converted to Ephemeris time, see "Universal Time vs Ephemeris Time".

  • $ids — reference to an array of ids of celestial bodies to be calculated.

Named Arguments

  • with_motion — optional flag; when set to true, there is additional motion field in the result; false by default.

find_positions($t, $ids, $callback, %options)

The arguments are the same as for the iterator, except the third, which is a callback function. It is called on each iteration:

$callback->($id, x => $scalar, y => $scalar, z => $scalar [, motion => $scalar])

The arguments are the same as described above.

AUTHOR

Sergey Krushinsky, <krushi at cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2010-2019 by Sergey Krushinsky

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.