The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

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, $lambda, $beta, $delta) = @_;
      say "$id $lambda, $beta, $delta";
  })

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

  • arrayref, containing ecliptic coordinates: longitude (arc-degrees), latitude (arc-degrees) and distance from Earth (AU).

  • mean daily motion, double, if with_motion option is true

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.

Options

  • 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 and options are the same as for the iterator, except the third argument, which is a callback function, called on each iteration:

  $callback->($id, $lambda, $beta, $delta [, $daily_motion])

$lambda, $beta, $delta are ecliptic coordinates: longitude (arc-degrees), latitude (arc-degrees) and distance from Earth (AU). The fifth argument, $daily_motion is defined only when with_motion option is on; it is the mean daily motion (arc-degrees).

AUTHOR

Sergey Krushinsky, <krushi at cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2010-2021 by Sergey Krushinsky

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