1 /*
2  *  This library is free software; you can redistribute it and/or
3  *  modify it under the terms of the GNU Lesser General Public
4  *  License as published by the Free Software Foundation; either
5  *  version 2 of the License, or (at your option) any later version.
6  *
7  *  This library is distributed in the hope that it will be useful,
8  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10  *  Lesser General Public License for more details.
11  *
12  *  You should have received a copy of the GNU General Public License
13  *  along with this program; if not, write to the Free Software
14  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  *
16  *  Copyright (C) 2000 - 2005 Liam Girdwood  <lgirdwood@gmail.com>
17  */
18 
19 module nova.comet;
20 
21 import std.math;
22 
23 import nova.elliptic_motion;
24 import nova.parabolic_motion;
25 import nova.ln_types;
26 
27 extern (C) {
28 
29 /*!
30 * \fn double ln_get_ell_comet_mag(double JD, struct ln_ell_orbit *orbit, double g, double k)
31 * \param JD Julian day.
32 * \param orbit Orbital parameters
33 * \param g Absolute magnitude
34 * \param k Comet constant
35 * \return The visual magnitude.
36 *
37 * Calculate the visual magnitude of a comet in an elliptical orbit.
38 *
39 * Note: modifies orbit.n if it's zero
40 */
41 @nogc double ln_get_ell_comet_mag(double JD, ref ln_ell_orbit orbit, double g,
42 	double k) nothrow
43 {
44 	double d, r;
45 	double E,M;
46 
47 	/* get mean anomaly */
48 	if (orbit.n == 0)
49 		orbit.n = ln_get_ell_mean_motion (orbit.a);
50 	M = ln_get_ell_mean_anomaly(orbit.n, JD - orbit.JD);
51 
52 	/* get eccentric anomaly */
53 	E = ln_solve_kepler(orbit.e, M);
54 
55 	/* get radius vector */
56 	r = ln_get_ell_radius_vector(orbit.a, orbit.e, E);
57 	d = ln_get_ell_body_solar_dist(JD, orbit);
58 
59 	return g + 5.0 * log10(d) + k * log10(r);
60 }
61 
62 /*!
63 * \fn double ln_get_par_comet_mag(double JD, struct ln_par_orbit *orbit, double g, double k)
64 * \param JD Julian day.
65 * \param orbit Orbital parameters
66 * \param g Absolute magnitude
67 * \param k Comet constant
68 * \return The visual magnitude.
69 *
70 * Calculate the visual magnitude of a comet in a parabolic orbit.
71 *
72 * Note: modifies orbit.n if it's zero
73 */
74 @nogc double ln_get_par_comet_mag(double JD, ref ln_par_orbit orbit, double g,
75 	double k) nothrow
76 {
77 	double d,r,t;
78 
79 	/* time since perihelion */
80 	t = JD - orbit.JD;
81 
82 	/* get radius vector */
83 	r = ln_get_par_radius_vector(orbit.q, t);
84 	d = ln_get_par_body_solar_dist(JD, orbit);
85 
86 	return g + 5.0 * log10(d) + k * log10(r);
87 }
88 
89 /*! \example comet.c
90  *
91  * Examples of how to use comet functions.
92  */
93 
94 }