lib/Astro/Montenbruck/Ephemeris/Planet.pm

filter: Statementstmt 98.6% 73 / 74 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 100% 3 / 3 totaltotal 97.7% 86 / 88 CC 1 SCAR 0.9
CC
1
Cov
99%
heliocentric
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« lib/Astro/Montenbruck/Ephemeris/Planet/Pluto.pm ↑ Summary lib/Astro/Montenbruck.pm »
1 package Astro::Montenbruck::Ephemeris::Planet;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Math::Trig qw/:pi rad2deg deg2rad/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Astro::Montenbruck::MathUtils qw/frac polar cart /;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 6 our $VERSION = 0.04;
10  
11 6 Readonly our $MO => 'Moon';
12 6 Readonly our $SU => 'Sun';
13 6 Readonly our $ME => 'Mercury';
14 6 Readonly our $VE => 'Venus';
15 6 Readonly our $MA => 'Mars';
16 6 Readonly our $JU => 'Jupiter';
17 6 Readonly our $SA => 'Saturn';
18 6 Readonly our $UR => 'Uranus';
19 6 Readonly our $NE => 'Neptune';
20 6 Readonly our $PL => 'Pluto';
21  
22 6 Readonly::Array our @PLANETS =>
23 ( $MO, $SU, $ME, $VE, $MA, $JU, $SA, $UR, $NE, $PL );
24  
25 6 ▶use Exporter qw/import/;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 6 our %EXPORT_TAGS = (
28 ids => [ qw/$MO $SU $ME $VE $MA $JU $SA $UR $NE $PL/ ],
29 funcs => [ qw/true2apparent light_travel/ ]
30 );
31 6 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'ids'} }, '@PLANETS', @{ $EXPORT_TAGS{'funcs'} });
32  
33 942 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
34 942 my ( $class, %arg ) = @_;
35 942 bless { _id => $arg{id}, }, $class;
36 }
37  
38  
39 # from the time derivatives of the polar coordinates (l, b, r)
40 # derive the components of the velocity vector in ecliptic coordinates
41 1002 ▶sub _posvel {
Subroutine _posvel: called CC=1 SCAR=0.0
42 1002 my ( $self, $l, $b, $r, $dl, $db, $dr ) = @_;
43 1002 my $cl = cos($l);
44 1002 my $sl = sin($l);
45 1002 my $cb = cos($b);
46 1002 my $sb = sin($b);
47 1002 my $x = $r * $cl * $cb;
48 1002 my $vx = $dr * $cl * $cb - $dl * $r * $sl * $cb - $db * $r * $cl * $sb;
49 1002 my $y = $r * $sl * $cb;
50 1002 my $vy = $dr * $sl * $cb + $dl * $r * $cl * $cb - $db * $r * $sl * $sb;
51 1002 my $z = $r * $sb;
52 1002 my $vz = $dr * $sb + $db * $r * $cb;
53  
54 1002 $x, $y, $z, $vx, $vy, $vz;
55 }
56  
57 # geocentric ecliptic coordinates (light-time corrected)
58 501 ▶sub _geocentric {
Subroutine _geocentric: called CC=1 SCAR=0.0
59 501 my ( $self, $t, $hpla_ref, $gsun_ref ) = @_;
60  
61 501 my $m = pi2 * frac( 0.9931266 + 99.9973604 * $t ); # Sun
62 # calculate the heliocentric velosity vector, which is required
63 # to take account of the various aberration effects.
64 501 my $dls = 172.00 + 5.75 * sin($m);
65 501 my $drs = 2.87 * cos($m);
66 501 my $dbs = 0.0;
67 ###
68 501 my ( $dl, $db, $dr ) = $self->_lbr_geo($t);
69  
70 # ecliptic geocentric coordinates of the Sun
71 my ( $xs, $ys, $zs, $vxs, $vys, $vzs ) =
72 501 $self->_posvel( $gsun_ref->{l}, $gsun_ref->{b}, $gsun_ref->{r}, $dls, $dbs, $drs );
73 # ecliptic heliocentric coordinates of the planet
74 my ( $xp, $yp, $zp, $vx, $vy, $vz ) =
75 501 $self->_posvel( $hpla_ref->{l}, $hpla_ref->{b}, $hpla_ref->{r}, $dl, $db, $dr );
76 501 my $x = $xp + $xs;
77 501 my $y = $yp + $ys;
78 501 my $z = $zp + $zs;
79  
80 # mean heliocentric motion
81 501 my $delta0 = sqrt( $x * $x + $y * $y + $z * $z );
82 501 my $fac = 0.00578 * $delta0 * 1E-4;
83  
84 # correct for light travel
85 501 $x -= $fac * ( $vx + $vxs );
86 501 $y -= $fac * ( $vy + $vys );
87 501 $z -= $fac * ( $vz + $vzs );
88  
89 501 $x, $y, $z # ecliptic geocentric coordinates of the planet
90 }
91  
92 36 ▶sub apparent {
Subroutine apparent: called CC=1 SCAR=0.0
Pod documented
93 36 my $self = shift;
94 36 my ( $t, $lbr, $sun, $nut_func ) = @_;
95 36 my ( $l, $b, $r ) = @$lbr; # $self->heliocentric($t);
96 # geocentric ecliptic coordinates (light-time corrected, referred to the mean equinox of date)
97 36 my @mean = $self->_geocentric( $t, { l => $l, b => $b, r => $r }, $sun );
98 # true equinox of date
99 36 my @date = $nut_func->(\@mean);
100 # rectangular -> polar
101 36 ($r, $b, $l) = polar(@date);
102 36 rad2deg($l), rad2deg($b), $r;
103 }
104  
105  
106 0 ▶sub heliocentric {
Subroutine heliocentric: not called CC=1 SCAR=6.9
Pod documented
107 0 die "Must be overriden by a descendant";
108 }
109  
110  
111  
112  
113 6 1;
114 __END__
« lib/Astro/Montenbruck/Ephemeris/Planet/Pluto.pm ↑ Summary lib/Astro/Montenbruck.pm »