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 4     4   2454 use strict;
  4         10  
  4         131  
4 4     4   44 use warnings;
  4         10  
  4         136  
5              
6 4     4   22 use base qw/Astro::Montenbruck::Ephemeris::Planet/;
  4         8  
  4         372  
7 4     4   29 use Math::Trig qw/:pi rad2deg/;
  4         13  
  4         590  
8 4     4   28 use Astro::Montenbruck::MathUtils qw /frac ARCS reduce_rad/;
  4         8  
  4         276  
9 4     4   467 use Astro::Montenbruck::Ephemeris::Pert qw/pert/;
  4         9  
  4         189  
10 4     4   26 use Astro::Montenbruck::Ephemeris::Planet qw/$SU/;
  4         9  
  4         5084  
11              
12             our $VERSION = 0.01;
13              
14             sub new {
15 459     459 1 947 my $class = shift;
16 459         1535 $class->SUPER::new( id => $SU );
17             }
18              
19             sub position {
20 459     459 1 1057 my ( $self, $t ) = @_;
21              
22             # mean anomalies of planets and mean arguments of lunar orbit [rad]
23 459         1561 my $m2 = pi2 * frac( 0.1387306 + 162.5485917 * $t );
24 459         1227 my $m3 = pi2 * frac( 0.9931266 + 99.9973604 * $t );
25 459         1071 my $m4 = pi2 * frac( 0.0543250 + 53.1666028 * $t );
26 459         1088 my $m5 = pi2 * frac( 0.0551750 + 8.4293972 * $t );
27 459         1046 my $m6 = pi2 * frac( 0.8816500 + 3.3938722 * $t );
28              
29 459         1007 my $d = pi2 * frac( 0.8274 + 1236.8531 * $t );
30 459         1061 my $a = pi2 * frac( 0.3749 + 1325.5524 * $t );
31 459         1147 my $u = pi2 * frac( 0.2591 + 1342.2278 * $t );
32              
33 459         1092 my ( $dl, $dr, $db ) = ( 0, 0, 0 ); # Corrections in longitude ["],
34 459     23868   1737 my $pert_cb = sub { $dl += $_[0]; $dr += $_[1]; $db += $_[2] };
  23868         35443  
  23868         32495  
  23868         39495  
35              
36             # Keplerian terms and perturbations by Venus
37 459         1473 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 459         1766 $term->( 1, 0, 0, -0.22, 6892.76, -16707.37, -0.54, 0, 0 );
49 459         1440 $term->( 1, 0, 1, -0.06, -17.35, 42.04, -0.15, 0.00, 0.00 );
50 459         1367 $term->( 1, 0, 2, -0.01, -0.05, 0.13, -0.02, 0.00, 0.00 );
51 459         1464 $term->( 2, 0, 0, 0.00, 71.98, -139.57, 0.00, 0.00, 0.00 );
52 459         1327 $term->( 2, 0, 1, 0.00, -0.36, 0.70, 0.00, 0.00, 0.00 );
53 459         1343 $term->( 3, 0, 0, 0.00, 1.04, -1.75, 0.00, 0.00, 0.00 );
54 459         1461 $term->( 0, -1, 0, 0.03, -0.07, -0.16, -0.07, 0.02, -0.02 );
55 459         1493 $term->( 1, -1, 0, 2.35, -4.23, -4.75, -2.64, 0.00, 0.00 );
56 459         1309 $term->( 1, -2, 0, -0.10, 0.06, 0.12, 0.20, 0.02, 0.00 );
57 459         1419 $term->( 2, -1, 0, -0.06, -0.03, 0.20, -0.01, 0.01, -0.09 );
58 459         1438 $term->( 2, -2, 0, -4.70, 2.90, 8.28, 13.42, 0.01, -0.01 );
59 459         1376 $term->( 3, -2, 0, 1.80, -1.74, -1.44, -1.57, 0.04, -0.06 );
60 459         1363 $term->( 3, -3, 0, -0.67, 0.03, 0.11, 2.43, 0.01, 0.00 );
61 459         1378 $term->( 4, -2, 0, 0.03, -0.03, 0.10, 0.09, 0.01, -0.01 );
62 459         1319 $term->( 4, -3, 0, 1.51, -0.40, -0.88, -3.36, 0.18, -0.10 );
63 459         1393 $term->( 4, -4, 0, -0.19, -0.09, -0.38, 0.77, 0.00, 0.00 );
64 459         1342 $term->( 5, -3, 0, 0.76, -0.68, 0.30, 0.37, 0.01, 0.00 );
65 459         1348 $term->( 5, -4, 0, -0.14, -0.04, -0.11, 0.43, -0.03, 0.00 );
66 459         1349 $term->( 5, -5, 0, -0.05, -0.07, -0.31, 0.21, 0.00, 0.00 );
67 459         1325 $term->( 6, -4, 0, 0.15, -0.04, -0.06, -0.21, 0.01, 0.00 );
68 459         1386 $term->( 6, -5, 0, -0.03, -0.03, -0.09, 0.09, -0.01, 0.00 );
69 459         1368 $term->( 6, -6, 0, 0.00, -0.04, -0.18, 0.02, 0.00, 0.00 );
70 459         1400 $term->( 7, -5, 0, -0.12, -0.03, -0.08, 0.31, -0.02, -0.01 );
71              
72             # perturbations by Mars
73 459         1267 $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 459         1805 $term->( 1, -1, 0, -0.22, 0.17, -0.21, -0.27, 0.00, 0.00 );
84 459         1417 $term->( 1, -2, 0, -1.66, 0.62, 0.16, 0.28, 0.00, 0.00 );
85 459         1346 $term->( 2, -2, 0, 1.96, 0.57, -1.32, 4.55, 0.00, 0.01 );
86 459         1361 $term->( 2, -3, 0, 0.40, 0.15, -0.17, 0.46, 0.00, 0.00 );
87 459         1323 $term->( 2, -4, 0, 0.53, 0.26, 0.09, -0.22, 0.00, 0.00 );
88 459         1324 $term->( 3, -3, 0, 0.05, 0.12, -0.35, 0.15, 0.00, 0.00 );
89 459         1428 $term->( 3, -4, 0, -0.13, -0.48, 1.06, -0.29, 0.01, 0.00 );
90 459         1334 $term->( 3, -5, 0, -0.04, -0.20, 0.20, -0.04, 0.00, 0.00 );
91 459         1352 $term->( 4, -4, 0, 0.00, -0.03, 0.10, 0.04, 0.00, 0.00 );
92 459         1316 $term->( 4, -5, 0, 0.05, -0.07, 0.20, 0.14, 0.00, 0.00 );
93 459         1397 $term->( 4, -6, 0, -0.10, 0.11, -0.23, -0.22, 0.00, 0.00 );
94 459         1426 $term->( 5, -7, 0, -0.05, 0.00, 0.01, -0.14, 0.00, 0.00 );
95 459         1353 $term->( 5, -8, 0, 0.05, 0.01, -0.02, 0.10, 0.00, 0.00 );
96              
97             # perturbations by Sun
98 459         1168 $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 459         1768 $term->( -1, -1, 0, 0.01, 0.07, 0.18, -0.02, 0.00, -0.02 );
109 459         2071 $term->( 0, -1, 0, -0.31, 2.58, 0.52, 0.34, 0.02, 0.00 );
110 459         1420 $term->( 1, -1, 0, -7.21, -0.06, 0.13, -16.27, 0.00, -0.02 );
111 459         1444 $term->( 1, -2, 0, -0.54, -1.52, 3.09, -1.12, 0.01, -0.17 );
112 459         1380 $term->( 1, -3, 0, -0.03, -0.21, 0.38, -0.06, 0.00, -0.02 );
113 459         1445 $term->( 2, -1, 0, -0.16, 0.05, -0.18, -0.31, 0.01, 0.00 );
114 459         1352 $term->( 2, -2, 0, 0.14, -2.73, 9.23, 0.48, 0.00, 0.00 );
115 459         1290 $term->( 2, -3, 0, 0.07, -0.55, 1.83, 0.25, 0.01, 0.00 );
116 459         1308 $term->( 2, -4, 0, 0.02, -0.08, 0.25, 0.06, 0.00, 0.00 );
117 459         1318 $term->( 3, -2, 0, 0.01, -0.07, 0.16, 0.04, 0.00, 0.00 );
118 459         1371 $term->( 3, -3, 0, -0.16, -0.03, 0.08, -0.64, 0.00, 0.00 );
119 459         1351 $term->( 3, -4, 0, -0.04, -0.01, 0.03, -0.17, 0.00, 0.00 );
120              
121             # perturbations by Saturn
122 459         1231 $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 459         1761 $term->( 0, -1, 0, 0.00, 0.32, 0.01, 0.00, 0.00, 0.00 );
133 459         1465 $term->( 1, -1, 0, -0.08, -0.41, 0.97, -0.18, 0.00, -0.01 );
134 459         1482 $term->( 1, -2, 0, 0.04, 0.10, -0.23, 0.10, 0.00, 0.00 );
135 459         1333 $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 459         866 my $dpa = $d + $a;
139 459         781 my $dma = $d - $a;
140 459         1440 $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 459         1323 $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 459         799 $db += +0.576 * sin($u);
155              
156             # long-periodic perturbations
157 459         1322 $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 459         1560 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 459         1042 my $r = 1.0001398 - 0.0000007 * $t + $dr * 1.0e-6;
171 459         782 my $b = $db / ARCS;
172              
173 459         1092 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