1 /**************************************************************************
3 * Written by Durk Talsma. Originally started October 1997, for distribution
4 * with the FlightGear project. Version 2 was written in August and
5 * September 1998. This code is based upon algorithms and data kindly
6 * provided by Mr. Paul Schlyter. (pausch@saaf.se).
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 **************************************************************************/
26 #ifndef _CELESTIALBODY_H_
27 #define _CELESTIALBODY_H_
30 # error This library requires C++
34 #include <Time/fg_time.hxx>
35 #include <Include/fg_constants.h>
41 protected: // make the data protected, in order to give the inherited
42 // classes direct access to the data
43 double NFirst; /* longitude of the ascending node first part */
44 double NSec; /* longitude of the ascending node second part */
45 double iFirst; /* inclination to the ecliptic first part */
46 double iSec; /* inclination to the ecliptic second part */
47 double wFirst; /* first part of argument of perihelion */
48 double wSec; /* second part of argument of perihelion */
49 double aFirst; /* semimayor axis first part*/
50 double aSec; /* semimayor axis second part */
51 double eFirst; /* eccentricity first part */
52 double eSec; /* eccentricity second part */
53 double MFirst; /* Mean anomaly first part */
54 double MSec; /* Mean anomaly second part */
56 double N, i, w, a, e, M; /* the resulting orbital elements, obtained from the former */
58 double rightAscension, declination;
61 double lonEcl, latEcl;
63 double fgCalcEccAnom(double M, double e);
64 double fgCalcActTime(fgTIME *t);
65 void updateOrbElements(fgTIME *t);
68 CelestialBody(double Nf, double Ns,
73 double Mf, double Ms, fgTIME *t);
74 void getPos(double *ra, double *dec);
75 void getPos(double *ra, double *dec, double *magnitude);
78 void updatePosition(fgTIME *t, Star *ourSun);
81 /*****************************************************************************
82 * inline CelestialBody::CelestialBody
83 * public constructor for a generic celestialBody object.
84 * initializes the 6 primary orbital elements. The elements are:
85 * N: longitude of the ascending node
86 * i: inclination to the ecliptic
87 * w: argument of perihelion
88 * a: semi-major axis, or mean distance from the sun
91 * Each orbital element consists of a constant part and a variable part that
92 * gradually changes over time.
95 * the 13 arguments to the constructor constitute the first, constant
96 * ([NiwaeM]f) and the second variable ([NiwaeM]s) part of the orbital
97 * elements. The 13th argument is the current time. Note that the inclination
98 * is written with a capital (If, Is), because 'if' is a reserved word in the
99 * C/C++ programming language.
100 ***************************************************************************/
101 inline CelestialBody::CelestialBody(double Nf, double Ns,
102 double If, double Is,
103 double wf, double ws,
104 double af, double as,
105 double ef, double es,
106 double Mf, double Ms, fgTIME *t)
108 NFirst = Nf; NSec = Ns;
109 iFirst = If; iSec = Is;
110 wFirst = wf; wSec = ws;
111 aFirst = af; aSec = as;
112 eFirst = ef; eSec = es;
113 MFirst = Mf; MSec = Ms;
114 updateOrbElements(t);
117 /****************************************************************************
118 * inline void CelestialBody::updateOrbElements(fgTIME *t)
119 * given the current time, this private member calculates the actual
122 * Arguments: fgTIME *t: the current time:
125 ***************************************************************************/
126 inline void CelestialBody::updateOrbElements(fgTIME *t)
128 double actTime = fgCalcActTime(t);
129 M = DEG_TO_RAD * (MFirst + (MSec * actTime));
130 w = DEG_TO_RAD * (wFirst + (wSec * actTime));
131 N = DEG_TO_RAD * (NFirst + (NSec * actTime));
132 i = DEG_TO_RAD * (iFirst + (iSec * actTime));
133 e = eFirst + (eSec * actTime);
134 a = aFirst + (aSec * actTime);
136 /*****************************************************************************
137 * inline double CelestialBody::fgCalcActTime(fgTIME *t)
138 * this private member function returns the offset in days from the epoch for
139 * wich the orbital elements are calculated (Jan, 1st, 2000).
141 * Argument: the current time
143 * return value: the (fractional) number of days until Jan 1, 2000.
144 ****************************************************************************/
145 inline double CelestialBody::fgCalcActTime(fgTIME *t)
147 return (t->mjd - 36523.5);
150 /*****************************************************************************
151 * inline void CelestialBody::getPos(double* ra, double* dec)
152 * gives public access to Right Ascension and declination
154 ****************************************************************************/
155 inline void CelestialBody::getPos(double* ra, double* dec)
157 *ra = rightAscension;
161 /*****************************************************************************
162 * inline void CelestialBody::getPos(double* ra, double* dec, double* magnitude
163 * gives public acces to the current Right ascension, declination, and
165 ****************************************************************************/
166 inline void CelestialBody::getPos(double* ra, double* dec, double* magn)
168 *ra = rightAscension;
173 inline double CelestialBody::getLon()
178 inline double CelestialBody::getLat()
183 #endif // _CELESTIALBODY_H_