-
Notifications
You must be signed in to change notification settings - Fork 1
/
pluto.c
509 lines (454 loc) · 10.7 KB
/
pluto.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
// HDS OPE file Editor
// pluto.c : imported from libnova
// 2012.10.22 A.Tajitsu
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Copyright (C) 2000 - 2005 Liam Girdwood
*/
#include <math.h>
#include <stdlib.h>
#include "libnova/pluto.h"
#include "libnova/vsop87.h"
#include "libnova/solar.h"
#include "libnova/earth.h"
#include "libnova/transform.h"
#include "libnova/rise_set.h"
#include "libnova/utility.h"
#define PLUTO_COEFFS 43
struct pluto_argument
{
double J, S, P;
};
struct pluto_longitude
{
double A,B;
};
struct pluto_latitude
{
double A,B;
};
struct pluto_radius
{
double A,B;
};
/* cache variables */
static double cJD = 0, cL = 0, cB = 0, cR = 0;
static const struct pluto_argument argument[PLUTO_COEFFS] = {
{0, 0, 1},
{0, 0, 2},
{0, 0, 3},
{0, 0, 4},
{0, 0, 5},
{0, 0, 6},
{0, 1, -1},
{0, 1, 0},
{0, 1, 1},
{0, 1, 2},
{0, 1, 3},
{0, 2, -2},
{0, 2, -1},
{0, 2, 0},
{1, -1, 0},
{1, -1, 1},
{1, 0, -3},
{1, 0, -2},
{1, 0, -1},
{1, 0, 0},
{1, 0, 1},
{1, 0, 2},
{1, 0, 3},
{1, 0, 4},
{1, 1, -3},
{1, 1, -2},
{1, 1, -1},
{1, 1, 0},
{1, 1, 1},
{1, 1, 3},
{2, 0, -6},
{2, 0, -5},
{2, 0, -4},
{2, 0, -3},
{2, 0, -2},
{2, 0, -1},
{2, 0, 0},
{2, 0, 1},
{2, 0, 2},
{2, 0, 3},
{3, 0, -2},
{3, 0, -1},
{3, 0, 0}
};
static const struct pluto_longitude longitude[PLUTO_COEFFS] = {
{-19799805, 19850055},
{897144, -4954829},
{611149, 1211027},
{-341243, -189585},
{129287, -34992},
{-38164, 30893},
{20442, -9987},
{-4063, -5071},
{-6016, -3336},
{-3956, 3039},
{-667, 3572},
{1276, 501},
{1152, -917},
{630, -1277},
{2571, -459},
{899, -1449},
{-1016, 1043},
{-2343, -1012},
{7042, 788},
{1199, -338},
{418, -67},
{120, -274},
{-60, -159},
{-82, -29},
{-36, -20},
{-40, 7},
{-14, 22},
{4, 13},
{5,2},
{-1,0},
{2,0},
{-4, 5},
{4, -7},
{14, 24},
{-49, -34},
{163, -48},
{9, 24},
{-4, 1},
{-3,1},
{1,3},
{-3, -1},
{5, -3},
{0,0}
};
static const struct pluto_latitude latitude[PLUTO_COEFFS] = {
{-5452852, -14974862},
{3527812, 1672790},
{-1050748, 327647},
{178690, -292153},
{18650, 100340},
{-30697, -25823},
{4878, 11248},
{226, -64},
{2030, -836},
{69, -604},
{-247, -567},
{-57, 1},
{-122, 175},
{-49, -164},
{-197, 199},
{-25, 217},
{589, -248},
{-269, 711},
{185, 193},
{315, 807},
{-130, -43},
{5, 3},
{2, 17},
{2, 5},
{2, 3},
{3, 1},
{2, -1},
{1, -1},
{0, -1},
{0, 0},
{0, -2},
{2, 2},
{-7, 0},
{10, -8},
{-3, 20},
{6, 5},
{14, 17},
{-2, 0},
{0, 0},
{0, 0},
{0, 1},
{0, 0},
{1, 0}
};
static const struct pluto_radius radius[PLUTO_COEFFS] = {
{66865439, 68951812},
{-11827535, -332538},
{1593179, -1438890},
{-18444, 483220},
{-65977, -85431},
{31174, -6032},
{-5794, 22161},
{4601, 4032},
{-1729, 234},
{-415, 702},
{239, 723},
{67, -67},
{1034, -451},
{-129, 504},
{480, -231},
{2, -441},
{-3359, 265},
{7856, -7832},
{36, 45763},
{8663, 8547},
{-809, -769},
{263, -144},
{-126, 32},
{-35, -16},
{-19, -4},
{-15, 8},
{-4, 12},
{5, 6},
{3, 1},
{6, -2},
{2, 2},
{-2, -2},
{14, 13},
{-63, 13},
{136, -236},
{273, 1065},
{251, 149},
{-25, -9},
{9, -2},
{-8, 7},
{2, -10},
{19, 35},
{10, 2}
};
/*! \fn void ln_get_pluto_equ_coords (double JD, struct ln_equ_posn * position);
* \param JD julian Day
* \param position Pointer to store position
*
* Calculates Pluto's equatorial position for the given julian day.
*/
void ln_get_pluto_equ_coords (double JD, struct ln_equ_posn * position)
{
struct ln_helio_posn h_sol, h_pluto;
struct ln_rect_posn g_sol, g_pluto;
double a,b,c;
double ra, dec, delta, diff, last, t = 0;
/* need typdef for solar heliocentric coords */
ln_get_solar_geom_coords (JD, &h_sol);
ln_get_rect_from_helio (&h_sol, &g_sol);
do {
last = t;
ln_get_pluto_helio_coords (JD - t, &h_pluto);
ln_get_rect_from_helio (&h_pluto, &g_pluto);
/* equ 33.10 pg 229 */
a = g_sol.X + g_pluto.X;
b = g_sol.Y + g_pluto.Y;
c = g_sol.Z + g_pluto.Z;
delta = a*a + b*b + c*c;
delta = sqrt (delta);
t = delta * 0.0057755183;
diff = t - last;
} while (diff > 0.0001 || diff < -0.0001);
ra = atan2 (b,a);
dec = c / delta;
dec = asin (dec);
/* back to hours, degrees */
position->ra = ln_range_degrees(ln_rad_to_deg (ra));
position->dec = ln_rad_to_deg (dec);
}
/*! \fn void ln_get_pluto_helio_coords (double JD, struct ln_helio_posn * position)
* \param JD Julian Day
* \param position Pointer to store new heliocentric position
*
* Calculate Pluto's heliocentric coordinates for the given julian day.
* This function is accurate to within 0.07" in longitude, 0.02" in latitude
* and 0.000006 AU in radius vector.
*
* Note: This function is not valid outside the period of 1885-2099.
*/
/* Chap 37. Equ 37.1
*/
void ln_get_pluto_helio_coords (double JD, struct ln_helio_posn * position)
{
double sum_longitude = 0, sum_latitude = 0, sum_radius = 0;
double J, S, P;
double t, a, sin_a, cos_a;
int i;
/* check cache first */
if (JD == cJD) {
/* cache hit */
position->L = cL;
position->B = cB;
position->R = cR;
return;
}
/* get julian centuries since J2000 */
t = (JD - 2451545) / 36525;
/* calculate mean longitudes for jupiter, saturn and pluto */
J = 34.35 + 3034.9057 * t;
S = 50.08 + 1222.1138 * t;
P = 238.96 + 144.9600 * t;
/* calc periodic terms in table 37.A */
for (i=0; i < PLUTO_COEFFS; i++) {
a = argument[i].J * J + argument[i].S * S + argument[i].P * P;
sin_a = sin (ln_deg_to_rad(a));
cos_a = cos (ln_deg_to_rad(a));
/* longitude */
sum_longitude += longitude[i].A * sin_a + longitude[i].B * cos_a;
/* latitude */
sum_latitude += latitude[i].A * sin_a + latitude[i].B * cos_a;
/* radius */
sum_radius += radius[i].A * sin_a + radius[i].B * cos_a;
}
/* calc L, B, R */
position->L = 238.958116 + 144.96 * t + sum_longitude * 0.000001;
position->B = -3.908239 + sum_latitude * 0.000001;
position->R = 40.7241346 + sum_radius * 0.0000001;
/* save cache */
cJD = JD;
cL = position->L;
cB = position->B;
cR = position->R;
}
/*! \fn double ln_get_pluto_earth_dist (double JD);
* \param JD Julian day
* \return Distance in AU
*
* Calculates the distance in AU between the Earth and Pluto for the
* given julian day.
*/
double ln_get_pluto_earth_dist (double JD)
{
struct ln_helio_posn h_pluto, h_earth;
struct ln_rect_posn g_pluto, g_earth;
double x, y, z;
/* get heliocentric positions */
ln_get_pluto_helio_coords (JD, &h_pluto);
ln_get_earth_helio_coords (JD, &h_earth);
/* get geocentric coords */
ln_get_rect_from_helio (&h_pluto, &g_pluto);
ln_get_rect_from_helio (&h_earth, &g_earth);
/* use pythag */
x = g_pluto.X - g_earth.X;
y = g_pluto.Y - g_earth.Y;
z = g_pluto.Z - g_earth.Z;;
x = x * x;
y = y * y;
z = z * z;
return sqrt (x + y + z);
}
/*! \fn double ln_get_pluto_solar_dist (double JD);
* \param JD Julian day
* \return Distance in AU
*
* Calculates the distance in AU between the Sun and Pluto for the
* given julian day.
*/
double ln_get_pluto_solar_dist (double JD)
{
struct ln_helio_posn h_pluto;
/* get heliocentric position */
ln_get_pluto_helio_coords (JD, &h_pluto);
return h_pluto.R;
}
/*! \fn double ln_get_pluto_magnitude (double JD);
* \param JD Julian day
* \return Visible magnitude of Pluto
*
* Calculate the visible magnitude of Pluto for the given
* julian day.
*/
double ln_get_pluto_magnitude (double JD)
{
double delta, r;
/* get distances */
r = ln_get_pluto_solar_dist (JD);
delta = ln_get_pluto_earth_dist (JD);
return -1.0 + 5 * log10 (r * delta);
}
/*! \fn double ln_get_pluto_disk (double JD);
* \param JD Julian day
* \return Illuminated fraction of Plutos disk
*
* Calculate the illuminated fraction of Pluto's disk for
* the given julian day.
*/
/* Chapter 41 */
double ln_get_pluto_disk (double JD)
{
double r,delta,R;
/* get distances */
R = ln_get_earth_solar_dist (JD);
r = ln_get_pluto_solar_dist (JD);
delta = ln_get_pluto_earth_dist (JD);
/* calc fraction angle */
return (((r + delta) * (r + delta)) - R * R) / (4 * r * delta);
}
/*! \fn double ln_get_pluto_phase (double JD);
* \param JD Julian day
* \return Phase angle of Pluto (degrees)
*
* Calculate the phase angle of Pluto (Sun - Pluto - Earth)
* for the given julian day.
*/
/* Chapter 41 */
double ln_get_pluto_phase (double JD)
{
double i,r,delta,R;
/* get distances */
R = ln_get_earth_solar_dist (JD);
r = ln_get_pluto_solar_dist (JD);
delta = ln_get_pluto_earth_dist (JD);
/* calc phase */
i = (r * r + delta * delta - R * R) / (2 * r * delta);
i = acos (i);
return ln_rad_to_deg (i);
}
/*! \fn double ln_get_pluto_rst (double JD, struct ln_lnlat_posn * observer, struct ln_rst_time * rst);
* \param JD Julian day
* \param observer Observers position
* \param rst Pointer to store Rise, Set and Transit time in JD
* \return 0 for success, else 1 for circumpolar.
*
* Calculate the time the rise, set and transit (crosses the local meridian at upper culmination)
* time of Pluto for the given Julian day.
*
* Note: this functions returns 1 if Pluto is circumpolar, that is it remains the whole
* day either above or below the horizon.
*/
int ln_get_pluto_rst (double JD, struct ln_lnlat_posn * observer, struct ln_rst_time * rst)
{
return ln_get_body_rst_horizon (JD, observer, ln_get_pluto_equ_coords, LN_STAR_STANDART_HORIZON, rst);
}
/*! \fn double ln_get_pluto_sdiam (double JD)
* \param JD Julian day
* \return Semidiameter in arc seconds
*
* Calculate the semidiameter of Pluto in arc seconds for the
* given julian day.
*/
double ln_get_pluto_sdiam (double JD)
{
double So = 2.07; /* at 1 AU */
double dist;
dist = ln_get_pluto_earth_dist (JD);
return So / dist;
}
/*! \fn void ln_get_pluto_rect_helio (double JD, struct ln_rect_posn * position)
* \param JD Julian day.
* \param position pointer to return position
*
* Calculate Plutos rectangular heliocentric coordinates for the
* given Julian day. Coordinates are in AU.
*/
void ln_get_pluto_rect_helio (double JD, struct ln_rect_posn * position)
{
struct ln_helio_posn pluto;
ln_get_pluto_helio_coords (JD, &pluto);
ln_get_rect_from_helio (&pluto, position);
}