File Coverage

lib/Astro/Montenbruck/Ephemeris/Planet/Sun.pm
Criterion Covered Total %
statement 103 103 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod 2 2 100.0
total 115 115 100.0


line stmt bran cond sub pod time code
1             package Astro::Montenbruck::Ephemeris::Planet::Sun;
2              
3 1     1   847 use strict;
  1         3  
  1         37  
4 1     1   38 use warnings;
  1         5  
  1         55  
5              
6 1     1   7 use base qw/Astro::Montenbruck::Ephemeris::Planet/;
  1         2  
  1         116  
7 1     1   6 use Math::Trig qw/:pi rad2deg/;
  1         2  
  1         194  
8 1     1   8 use Astro::Montenbruck::MathUtils qw /frac ARCS reduce_rad/;
  1         2  
  1         62  
9 1     1   6 use Astro::Montenbruck::Ephemeris::Pert qw/pert/;
  1         2  
  1         52  
10 1     1   7 use Astro::Montenbruck::Ephemeris::Planet qw/$SU/;
  1         2  
  1         1195  
11              
12             our $VERSION = 0.01;
13              
14             sub new {
15 4     4 1 11 my $class = shift;
16 4         22 $class->SUPER::new( id => $SU );
17             }
18              
19             sub position {
20 4     4 1 13 my ( $self, $t ) = @_;
21              
22             # mean anomalies of planets and mean arguments of lunar orbit [rad]
23 4         21 my $m2 = pi2 * frac( 0.1387306 + 162.5485917 * $t );
24 4         29 my $m3 = pi2 * frac( 0.9931266 + 99.9973604 * $t );
25 4         14 my $m4 = pi2 * frac( 0.0543250 + 53.1666028 * $t );
26 4         15 my $m5 = pi2 * frac( 0.0551750 + 8.4293972 * $t );
27 4         13 my $m6 = pi2 * frac( 0.8816500 + 3.3938722 * $t );
28              
29 4         13 my $d = pi2 * frac( 0.8274 + 1236.8531 * $t );
30 4         14 my $a = pi2 * frac( 0.3749 + 1325.5524 * $t );
31 4         13 my $u = pi2 * frac( 0.2591 + 1342.2278 * $t );
32              
33 4         12 my ( $dl, $dr, $db ) = ( 0, 0, 0 ); # Corrections in longitude ["],
34 4     208   19 my $pert_cb = sub { $dl += $_[0]; $dr += $_[1]; $db += $_[2] };
  208         302  
  208         283  
  208         355  
35              
36             # Keplerian terms and perturbations by Venus
37 4         21 my $term = pert(
38             T => $t,
39             M => $m3,
40             m => $m2,
41             I_min => 0,
42             I_max => 7,
43             i_min => -6,
44             i_max => 0,
45             callback => $pert_cb
46             );
47              
48 4         16 $term->( 1, 0, 0, -0.22, 6892.76, -16707.37, -0.54, 0, 0 );
49 4         16 $term->( 1, 0, 1, -0.06, -17.35, 42.04, -0.15, 0.00, 0.00 );
50 4         17 $term->( 1, 0, 2, -0.01, -0.05, 0.13, -0.02, 0.00, 0.00 );
51 4         15 $term->( 2, 0, 0, 0.00, 71.98, -139.57, 0.00, 0.00, 0.00 );
52 4         14 $term->( 2, 0, 1, 0.00, -0.36, 0.70, 0.00, 0.00, 0.00 );
53 4         14 $term->( 3, 0, 0, 0.00, 1.04, -1.75, 0.00, 0.00, 0.00 );
54 4         14 $term->( 0, -1, 0, 0.03, -0.07, -0.16, -0.07, 0.02, -0.02 );
55 4         15 $term->( 1, -1, 0, 2.35, -4.23, -4.75, -2.64, 0.00, 0.00 );
56 4         14 $term->( 1, -2, 0, -0.10, 0.06, 0.12, 0.20, 0.02, 0.00 );
57 4         16 $term->( 2, -1, 0, -0.06, -0.03, 0.20, -0.01, 0.01, -0.09 );
58 4         13 $term->( 2, -2, 0, -4.70, 2.90, 8.28, 13.42, 0.01, -0.01 );
59 4         14 $term->( 3, -2, 0, 1.80, -1.74, -1.44, -1.57, 0.04, -0.06 );
60 4         15 $term->( 3, -3, 0, -0.67, 0.03, 0.11, 2.43, 0.01, 0.00 );
61 4         14 $term->( 4, -2, 0, 0.03, -0.03, 0.10, 0.09, 0.01, -0.01 );
62 4         12 $term->( 4, -3, 0, 1.51, -0.40, -0.88, -3.36, 0.18, -0.10 );
63 4         18 $term->( 4, -4, 0, -0.19, -0.09, -0.38, 0.77, 0.00, 0.00 );
64 4         14 $term->( 5, -3, 0, 0.76, -0.68, 0.30, 0.37, 0.01, 0.00 );
65 4         14 $term->( 5, -4, 0, -0.14, -0.04, -0.11, 0.43, -0.03, 0.00 );
66 4         12 $term->( 5, -5, 0, -0.05, -0.07, -0.31, 0.21, 0.00, 0.00 );
67 4         15 $term->( 6, -4, 0, 0.15, -0.04, -0.06, -0.21, 0.01, 0.00 );
68 4         15 $term->( 6, -5, 0, -0.03, -0.03, -0.09, 0.09, -0.01, 0.00 );
69 4         14 $term->( 6, -6, 0, 0.00, -0.04, -0.18, 0.02, 0.00, 0.00 );
70 4         13 $term->( 7, -5, 0, -0.12, -0.03, -0.08, 0.31, -0.02, -0.01 );
71              
72             # perturbations by Mars
73 4         13 $term = pert(
74             T => $t,
75             M => $m3,
76             m => $m4,
77             I_min => 1,
78             I_max => 5,
79             i_min => -8,
80             i_max => -1,
81             callback => $pert_cb
82             );
83 4         20 $term->( 1, -1, 0, -0.22, 0.17, -0.21, -0.27, 0.00, 0.00 );
84 4         16 $term->( 1, -2, 0, -1.66, 0.62, 0.16, 0.28, 0.00, 0.00 );
85 4         15 $term->( 2, -2, 0, 1.96, 0.57, -1.32, 4.55, 0.00, 0.01 );
86 4         13 $term->( 2, -3, 0, 0.40, 0.15, -0.17, 0.46, 0.00, 0.00 );
87 4         16 $term->( 2, -4, 0, 0.53, 0.26, 0.09, -0.22, 0.00, 0.00 );
88 4         17 $term->( 3, -3, 0, 0.05, 0.12, -0.35, 0.15, 0.00, 0.00 );
89 4         14 $term->( 3, -4, 0, -0.13, -0.48, 1.06, -0.29, 0.01, 0.00 );
90 4         13 $term->( 3, -5, 0, -0.04, -0.20, 0.20, -0.04, 0.00, 0.00 );
91 4         13 $term->( 4, -4, 0, 0.00, -0.03, 0.10, 0.04, 0.00, 0.00 );
92 4         24 $term->( 4, -5, 0, 0.05, -0.07, 0.20, 0.14, 0.00, 0.00 );
93 4         15 $term->( 4, -6, 0, -0.10, 0.11, -0.23, -0.22, 0.00, 0.00 );
94 4         16 $term->( 5, -7, 0, -0.05, 0.00, 0.01, -0.14, 0.00, 0.00 );
95 4         13 $term->( 5, -8, 0, 0.05, 0.01, -0.02, 0.10, 0.00, 0.00 );
96              
97             # perturbations by Sun
98 4         13 $term = pert(
99             T => $t,
100             M => $m3,
101             m => $m5,
102             I_min => -1,
103             I_max => 3,
104             i_min => -4,
105             i_max => -1,
106             callback => $pert_cb
107             );
108 4         21 $term->( -1, -1, 0, 0.01, 0.07, 0.18, -0.02, 0.00, -0.02 );
109 4         18 $term->( 0, -1, 0, -0.31, 2.58, 0.52, 0.34, 0.02, 0.00 );
110 4         15 $term->( 1, -1, 0, -7.21, -0.06, 0.13, -16.27, 0.00, -0.02 );
111 4         15 $term->( 1, -2, 0, -0.54, -1.52, 3.09, -1.12, 0.01, -0.17 );
112 4         15 $term->( 1, -3, 0, -0.03, -0.21, 0.38, -0.06, 0.00, -0.02 );
113 4         15 $term->( 2, -1, 0, -0.16, 0.05, -0.18, -0.31, 0.01, 0.00 );
114 4         15 $term->( 2, -2, 0, 0.14, -2.73, 9.23, 0.48, 0.00, 0.00 );
115 4         14 $term->( 2, -3, 0, 0.07, -0.55, 1.83, 0.25, 0.01, 0.00 );
116 4         13 $term->( 2, -4, 0, 0.02, -0.08, 0.25, 0.06, 0.00, 0.00 );
117 4         16 $term->( 3, -2, 0, 0.01, -0.07, 0.16, 0.04, 0.00, 0.00 );
118 4         13 $term->( 3, -3, 0, -0.16, -0.03, 0.08, -0.64, 0.00, 0.00 );
119 4         13 $term->( 3, -4, 0, -0.04, -0.01, 0.03, -0.17, 0.00, 0.00 );
120              
121             # perturbations by Saturn
122 4         13 $term = pert(
123             T => $t,
124             M => $m3,
125             m => $m6,
126             I_min => -0,
127             I_max => 2,
128             i_min => -2,
129             i_max => -1,
130             callback => $pert_cb
131             );
132 4         19 $term->( 0, -1, 0, 0.00, 0.32, 0.01, 0.00, 0.00, 0.00 );
133 4         17 $term->( 1, -1, 0, -0.08, -0.41, 0.97, -0.18, 0.00, -0.01 );
134 4         12 $term->( 1, -2, 0, 0.04, 0.10, -0.23, 0.10, 0.00, 0.00 );
135 4         14 $term->( 2, -2, 0, 0.04, 0.10, -0.35, 0.13, 0.00, 0.00 );
136              
137             # difference of Earth-Moon-barycentre and centre of the Earth
138 4         10 my $dpa = $d + $a;
139 4         9 my $dma = $d - $a;
140 4         18 $dl +=
141             +6.45 * sin($d) -
142             0.42 * sin($dma) +
143             0.18 * sin($dpa) +
144             0.17 * sin( $d - $m3 ) -
145             0.06 * sin( $d + $m3 );
146              
147 4         14 $dr +=
148             +30.76 * cos($d) -
149             3.06 * cos($dma) +
150             0.85 * cos($dpa) -
151             0.58 * cos( $d + $m3 ) +
152             0.57 * cos( $d - $m3 );
153              
154 4         9 $db += +0.576 * sin($u);
155              
156             # long-periodic perturbations
157 4         19 $dl +=
158             +6.40 * sin( pi2 * ( 0.6983 + 0.0561 * $t ) ) +
159             1.87 * sin( pi2 * ( 0.5764 + 0.4174 * $t ) ) +
160             0.27 * sin( pi2 * ( 0.4189 + 0.3306 * $t ) ) +
161             0.20 * sin( pi2 * ( 0.3581 + 2.4814 * $t ) );
162              
163             # ecliptic coordinates ([rad],[AU])
164 4         20 my $l = reduce_rad(
165             pi2 * frac(
166             0.7859453 + $m3 / pi2 +
167             ( ( 6191.2 + 1.1 * $t ) * $t + $dl ) / 1296.0e3
168             )
169             );
170 4         12 my $r = 1.0001398 - 0.0000007 * $t + $dr * 1.0e-6;
171 4         10 my $b = $db / ARCS;
172              
173 4         15 rad2deg($l), rad2deg($b), $r;
174              
175             }
176              
177             1;
178              
179             __END__
180              
181             =pod
182              
183             =encoding UTF-8
184              
185             =head1 NAME
186              
187             Astro::Montenbruck::Ephemeris::Planet::Sun - Sun.
188              
189             =head1 SYNOPSIS
190              
191             use Astro::Montenbruck::Ephemeris::Planet::Sun;
192             my $planet = Astro::Montenbruck::Ephemeris::Planet::Sun->new();
193             my @geo = $planet->position($t); # apparent geocentric ecliptical coordinates
194              
195             =head1 DESCRIPTION
196              
197             Child class of L<Astro::Montenbruck::Ephemeris::Planet>, responsible for calculating
198             B<Sun> position.
199              
200             =head1 METHODS
201              
202             =head2 Astro::Montenbruck::Ephemeris::Planet::Sun->new
203              
204             Constructor.
205              
206             =head2 $self->position($t)
207              
208             Geocentric ecliptic coordinates of the Sun
209              
210             =head3 Arguments
211              
212             =over
213              
214             =item B<$t> — time in Julian centuries since J2000: (JD-2451545.0)/36525.0
215              
216             =back
217              
218             =head3 Returns
219              
220             Hash of geocentric ecliptical coordinates.
221              
222             =over
223              
224             =item * B<x> — geocentric longitude, arc-degrees
225              
226             =item * B<y> — geocentric latitude, arc-degrees
227              
228             =item * B<z> — distance from Earth, AU
229              
230             =back
231              
232             =head1 AUTHOR
233              
234             Sergey Krushinsky, C<< <krushi at cpan.org> >>
235              
236             =head1 COPYRIGHT AND LICENSE
237              
238             Copyright (C) 2009-2019 by Sergey Krushinsky
239              
240             This library is free software; you can redistribute it and/or modify
241             it under the same terms as Perl itself.
242              
243             =cut