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 library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
24 **************************************************************************/
27 #ifndef _CELESTIALBODY_H_
28 #define _CELESTIALBODY_H_
31 # error This library requires C++
35 #include <simgear/constants.h>
41 protected: // make the data protected, in order to give the
42 // inherited 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 sgCalcEccAnom(double M, double e);
64 double sgCalcActTime(double mjd);
65 void updateOrbElements(double mjd);
68 CelestialBody(double Nf, double Ns,
73 double Mf, double Ms, double mjd);
74 CelestialBody(double Nf, double Ns,
79 double Mf, double Ms);
80 void getPos(double *ra, double *dec);
81 void getPos(double *ra, double *dec, double *magnitude);
82 double getRightAscension();
83 double getDeclination();
84 double getMagnitude();
87 void updatePosition(double mjd, Star *ourSun);
90 /*****************************************************************************
91 * inline CelestialBody::CelestialBody
92 * public constructor for a generic celestialBody object.
93 * initializes the 6 primary orbital elements. The elements are:
94 * N: longitude of the ascending node
95 * i: inclination to the ecliptic
96 * w: argument of perihelion
97 * a: semi-major axis, or mean distance from the sun
100 * Each orbital element consists of a constant part and a variable part that
101 * gradually changes over time.
104 * the 13 arguments to the constructor constitute the first, constant
105 * ([NiwaeM]f) and the second variable ([NiwaeM]s) part of the orbital
106 * elements. The 13th argument is the current time. Note that the inclination
107 * is written with a capital (If, Is), because 'if' is a reserved word in the
108 * C/C++ programming language.
109 ***************************************************************************/
110 inline CelestialBody::CelestialBody(double Nf, double Ns,
111 double If, double Is,
112 double wf, double ws,
113 double af, double as,
114 double ef, double es,
115 double Mf, double Ms, double mjd)
117 NFirst = Nf; NSec = Ns;
118 iFirst = If; iSec = Is;
119 wFirst = wf; wSec = ws;
120 aFirst = af; aSec = as;
121 eFirst = ef; eSec = es;
122 MFirst = Mf; MSec = Ms;
123 updateOrbElements(mjd);
126 inline CelestialBody::CelestialBody(double Nf, double Ns,
127 double If, double Is,
128 double wf, double ws,
129 double af, double as,
130 double ef, double es,
131 double Mf, double Ms)
133 NFirst = Nf; NSec = Ns;
134 iFirst = If; iSec = Is;
135 wFirst = wf; wSec = ws;
136 aFirst = af; aSec = as;
137 eFirst = ef; eSec = es;
138 MFirst = Mf; MSec = Ms;
141 /****************************************************************************
142 * inline void CelestialBody::updateOrbElements(double mjd)
143 * given the current time, this private member calculates the actual
146 * Arguments: double mjd: the current modified julian date:
149 ***************************************************************************/
150 inline void CelestialBody::updateOrbElements(double mjd)
152 double actTime = sgCalcActTime(mjd);
153 M = DEG_TO_RAD * (MFirst + (MSec * actTime));
154 w = DEG_TO_RAD * (wFirst + (wSec * actTime));
155 N = DEG_TO_RAD * (NFirst + (NSec * actTime));
156 i = DEG_TO_RAD * (iFirst + (iSec * actTime));
157 e = eFirst + (eSec * actTime);
158 a = aFirst + (aSec * actTime);
160 /*****************************************************************************
161 * inline double CelestialBody::sgCalcActTime(double mjd)
162 * this private member function returns the offset in days from the epoch for
163 * wich the orbital elements are calculated (Jan, 1st, 2000).
165 * Argument: the current time
167 * return value: the (fractional) number of days until Jan 1, 2000.
168 ****************************************************************************/
169 inline double CelestialBody::sgCalcActTime(double mjd)
171 return (mjd - 36523.5);
174 /*****************************************************************************
175 * inline void CelestialBody::getPos(double* ra, double* dec)
176 * gives public access to Right Ascension and declination
178 ****************************************************************************/
179 inline void CelestialBody::getPos(double* ra, double* dec)
181 *ra = rightAscension;
185 /*****************************************************************************
186 * inline void CelestialBody::getPos(double* ra, double* dec, double* magnitude
187 * gives public acces to the current Right ascension, declination, and
189 ****************************************************************************/
190 inline void CelestialBody::getPos(double* ra, double* dec, double* magn)
192 *ra = rightAscension;
197 inline double CelestialBody::getRightAscension() { return rightAscension; }
198 inline double CelestialBody::getDeclination() { return declination; }
199 inline double CelestialBody::getMagnitude() { return magnitude; }
201 inline double CelestialBody::getLon()
206 inline double CelestialBody::getLat()
211 #endif // _CELESTIALBODY_H_