File Coverage

lib/Astro/Montenbruck/Ephemeris/Planet/Sun.pm
Criterion Covered Total %
statement 111 111 100.0
branch n/a
condition n/a
subroutine 12 12 100.0
pod 3 3 100.0
total 126 126 100.0


line stmt bran cond sub pod time code
1             package Astro::Montenbruck::Ephemeris::Planet::Sun;
2              
3 6     6   3021 use strict;
  6         13  
  6         163  
4 6     6   30 use warnings;
  6         9  
  6         175  
5              
6 6     6   27 use base qw/Astro::Montenbruck::Ephemeris::Planet/;
  6         10  
  6         1143  
7 6     6   31 use Math::Trig qw/:pi rad2deg deg2rad/;
  6         10  
  6         826  
8 6     6   44 use Astro::Montenbruck::MathUtils qw /frac ARCS reduce_rad cart polar/;
  6         12  
  6         355  
9 6     6   2351 use Astro::Montenbruck::Ephemeris::Pert qw/pert/;
  6         15  
  6         315  
10 6     6   36 use Astro::Montenbruck::Ephemeris::Planet qw/$SU/;
  6         12  
  6         6393  
11              
12             our $VERSION = 0.01;
13              
14             sub new {
15 687     687 1 1360 my $class = shift;
16 687         2427 $class->SUPER::new( id => $SU );
17             }
18              
19             sub sunpos {
20 704     704 1 1832 my ( $self, $t ) = @_;
21              
22             # mean anomalies of planets and mean arguments of lunar orbit [rad]
23 704         1935 my $m2 = pi2 * frac( 0.1387306 + 162.5485917 * $t );
24 704         1925 my $m3 = pi2 * frac( 0.9931266 + 99.9973604 * $t );
25 704         1781 my $m4 = pi2 * frac( 0.0543250 + 53.1666028 * $t );
26 704         1627 my $m5 = pi2 * frac( 0.0551750 + 8.4293972 * $t );
27 704         1503 my $m6 = pi2 * frac( 0.8816500 + 3.3938722 * $t );
28              
29 704         1590 my $d = pi2 * frac( 0.8274 + 1236.8531 * $t );
30 704         1690 my $a = pi2 * frac( 0.3749 + 1325.5524 * $t );
31 704         1831 my $u = pi2 * frac( 0.2591 + 1342.2278 * $t );
32              
33 704         1561 my ( $dl, $dr, $db ) = ( 0, 0, 0 ); # Corrections in longitude ["],
34 704     36608   2898 my $pert_cb = sub { $dl += $_[0]; $dr += $_[1]; $db += $_[2] };
  36608         42416  
  36608         40626  
  36608         48799  
35              
36             # Keplerian terms and perturbations by Venus
37 704         2484 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 704         2532 $term->( 1, 0, 0, -0.22, 6892.76, -16707.37, -0.54, 0, 0 );
49 704         2238 $term->( 1, 0, 1, -0.06, -17.35, 42.04, -0.15, 0.00, 0.00 );
50 704         2039 $term->( 1, 0, 2, -0.01, -0.05, 0.13, -0.02, 0.00, 0.00 );
51 704         2021 $term->( 2, 0, 0, 0.00, 71.98, -139.57, 0.00, 0.00, 0.00 );
52 704         2042 $term->( 2, 0, 1, 0.00, -0.36, 0.70, 0.00, 0.00, 0.00 );
53 704         1978 $term->( 3, 0, 0, 0.00, 1.04, -1.75, 0.00, 0.00, 0.00 );
54 704         2221 $term->( 0, -1, 0, 0.03, -0.07, -0.16, -0.07, 0.02, -0.02 );
55 704         2030 $term->( 1, -1, 0, 2.35, -4.23, -4.75, -2.64, 0.00, 0.00 );
56 704         1871 $term->( 1, -2, 0, -0.10, 0.06, 0.12, 0.20, 0.02, 0.00 );
57 704         1822 $term->( 2, -1, 0, -0.06, -0.03, 0.20, -0.01, 0.01, -0.09 );
58 704         1914 $term->( 2, -2, 0, -4.70, 2.90, 8.28, 13.42, 0.01, -0.01 );
59 704         2099 $term->( 3, -2, 0, 1.80, -1.74, -1.44, -1.57, 0.04, -0.06 );
60 704         1948 $term->( 3, -3, 0, -0.67, 0.03, 0.11, 2.43, 0.01, 0.00 );
61 704         1873 $term->( 4, -2, 0, 0.03, -0.03, 0.10, 0.09, 0.01, -0.01 );
62 704         1847 $term->( 4, -3, 0, 1.51, -0.40, -0.88, -3.36, 0.18, -0.10 );
63 704         1966 $term->( 4, -4, 0, -0.19, -0.09, -0.38, 0.77, 0.00, 0.00 );
64 704         2046 $term->( 5, -3, 0, 0.76, -0.68, 0.30, 0.37, 0.01, 0.00 );
65 704         2039 $term->( 5, -4, 0, -0.14, -0.04, -0.11, 0.43, -0.03, 0.00 );
66 704         1820 $term->( 5, -5, 0, -0.05, -0.07, -0.31, 0.21, 0.00, 0.00 );
67 704         2041 $term->( 6, -4, 0, 0.15, -0.04, -0.06, -0.21, 0.01, 0.00 );
68 704         1959 $term->( 6, -5, 0, -0.03, -0.03, -0.09, 0.09, -0.01, 0.00 );
69 704         1881 $term->( 6, -6, 0, 0.00, -0.04, -0.18, 0.02, 0.00, 0.00 );
70 704         2128 $term->( 7, -5, 0, -0.12, -0.03, -0.08, 0.31, -0.02, -0.01 );
71              
72             # perturbations by Mars
73 704         1937 $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 704         2565 $term->( 1, -1, 0, -0.22, 0.17, -0.21, -0.27, 0.00, 0.00 );
84 704         1917 $term->( 1, -2, 0, -1.66, 0.62, 0.16, 0.28, 0.00, 0.00 );
85 704         1904 $term->( 2, -2, 0, 1.96, 0.57, -1.32, 4.55, 0.00, 0.01 );
86 704         1987 $term->( 2, -3, 0, 0.40, 0.15, -0.17, 0.46, 0.00, 0.00 );
87 704         1809 $term->( 2, -4, 0, 0.53, 0.26, 0.09, -0.22, 0.00, 0.00 );
88 704         1753 $term->( 3, -3, 0, 0.05, 0.12, -0.35, 0.15, 0.00, 0.00 );
89 704         1870 $term->( 3, -4, 0, -0.13, -0.48, 1.06, -0.29, 0.01, 0.00 );
90 704         2021 $term->( 3, -5, 0, -0.04, -0.20, 0.20, -0.04, 0.00, 0.00 );
91 704         1785 $term->( 4, -4, 0, 0.00, -0.03, 0.10, 0.04, 0.00, 0.00 );
92 704         1880 $term->( 4, -5, 0, 0.05, -0.07, 0.20, 0.14, 0.00, 0.00 );
93 704         2178 $term->( 4, -6, 0, -0.10, 0.11, -0.23, -0.22, 0.00, 0.00 );
94 704         1875 $term->( 5, -7, 0, -0.05, 0.00, 0.01, -0.14, 0.00, 0.00 );
95 704         1877 $term->( 5, -8, 0, 0.05, 0.01, -0.02, 0.10, 0.00, 0.00 );
96              
97             # perturbations by Sun
98 704         1719 $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 704         2265 $term->( -1, -1, 0, 0.01, 0.07, 0.18, -0.02, 0.00, -0.02 );
109 704         2073 $term->( 0, -1, 0, -0.31, 2.58, 0.52, 0.34, 0.02, 0.00 );
110 704         2025 $term->( 1, -1, 0, -7.21, -0.06, 0.13, -16.27, 0.00, -0.02 );
111 704         1997 $term->( 1, -2, 0, -0.54, -1.52, 3.09, -1.12, 0.01, -0.17 );
112 704         1955 $term->( 1, -3, 0, -0.03, -0.21, 0.38, -0.06, 0.00, -0.02 );
113 704         2109 $term->( 2, -1, 0, -0.16, 0.05, -0.18, -0.31, 0.01, 0.00 );
114 704         2111 $term->( 2, -2, 0, 0.14, -2.73, 9.23, 0.48, 0.00, 0.00 );
115 704         1919 $term->( 2, -3, 0, 0.07, -0.55, 1.83, 0.25, 0.01, 0.00 );
116 704         2087 $term->( 2, -4, 0, 0.02, -0.08, 0.25, 0.06, 0.00, 0.00 );
117 704         2154 $term->( 3, -2, 0, 0.01, -0.07, 0.16, 0.04, 0.00, 0.00 );
118 704         2119 $term->( 3, -3, 0, -0.16, -0.03, 0.08, -0.64, 0.00, 0.00 );
119 704         2153 $term->( 3, -4, 0, -0.04, -0.01, 0.03, -0.17, 0.00, 0.00 );
120              
121             # perturbations by Saturn
122 704         1805 $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 704         2287 $term->( 0, -1, 0, 0.00, 0.32, 0.01, 0.00, 0.00, 0.00 );
133 704         2085 $term->( 1, -1, 0, -0.08, -0.41, 0.97, -0.18, 0.00, -0.01 );
134 704         1904 $term->( 1, -2, 0, 0.04, 0.10, -0.23, 0.10, 0.00, 0.00 );
135 704         2125 $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 704         1267 my $dpa = $d + $a;
139 704         1106 my $dma = $d - $a;
140 704         2126 $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 704         2205 $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 704         1198 $db += 0.576 * sin($u);
155              
156             # long-periodic perturbations
157 704         2180 $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 704         2466 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 704         1487 my $r = 1.0001398 - 0.0000007 * $t + $dr * 1e-6;
171 704         1201 my $b = $db / 3600;
172              
173 704         1585 rad2deg($l), $b, $r;
174             }
175              
176              
177 465     465   1117 sub _lbr_geo { 0, 0, 0 }
178              
179              
180             sub apparent {
181 465     465 1 688 my $self = shift;
182 465         939 my ($t, $lbr, $nut_func) = @_;
183 465         847 my ($l, $b, $r) = @$lbr;
184             # geocentric ecliptic coordinates (light-time corrected, referred to the mean equinox of date)
185 465         1576 my @mean = $self->_geocentric(
186             $t,
187             { l => 0, b => 0, r => 0 },
188             { l => deg2rad($l), b => deg2rad($b), r => $r }
189             );
190             # true equinox of date
191 465         1696 my @date = $nut_func->(\@mean);
192             # rectangular -> polar
193 465         1406 ($r, $b, $l) = polar(@date);
194 465         1078 rad2deg($l), rad2deg($b), $r
195             }
196              
197              
198             1;
199              
200             __END__
201              
202             =pod
203              
204             =encoding UTF-8
205              
206             =head1 NAME
207              
208             Astro::Montenbruck::Ephemeris::Planet::Sun - Sun.
209              
210             =head1 SYNOPSIS
211              
212             use Astro::Montenbruck::Ephemeris::Planet::Sun;
213             Astro::Montenbruck::NutEqu qw/mean2true/;
214              
215             my $sun = Astro::Montenbruck::Ephemeris::Planet::Sun->new();
216             my ($l, $b, $r) = $sun->sunpos($t); # true geocentric ecliptical coordinates
217              
218             my $nut_func = mean2true($t);
219             # apparent geocentric ecliptical coordinates
220             my ($lambda, $beta, $delta) = $sun->apparent($t, [$l, $b, $r], $nut_func);
221              
222             =head1 DESCRIPTION
223              
224             Child class of L<Astro::Montenbruck::Ephemeris::Planet>, responsible for calculating
225             B<Sun> position.
226              
227             =head1 METHODS
228              
229             =head2 Astro::Montenbruck::Ephemeris::Planet::Sun->new
230              
231             Constructor.
232              
233             =head2 $self->sunpos($t)
234              
235             Ecliptic coordinates L, B, R (in deg and AU) of the Sun referred to the I<mean equinox of date>.
236              
237             =head3 Arguments
238              
239             =over
240              
241             =item B<$t> — time in Julian centuries since J2000: (JD-2451545.0)/36525.0
242              
243             =back
244              
245             =head3 Returns
246              
247             Array of geocentric ecliptical coordinates.
248              
249             =over
250              
251             =item * B<x> — geocentric longitude, arc-degrees
252              
253             =item * B<y> — geocentric latitude, arc-degrees
254              
255             =item * B<z> — distance from Earth, AU
256              
257             =back
258              
259              
260             =head1 AUTHOR
261              
262             Sergey Krushinsky, C<< <krushi at cpan.org> >>
263              
264             =head1 COPYRIGHT AND LICENSE
265              
266             Copyright (C) 2009-2022 by Sergey Krushinsky
267              
268             This library is free software; you can redistribute it and/or modify
269             it under the same terms as Perl itself.
270              
271             =cut