]> git.mxchange.org Git - simgear.git/blob - simgear/ephemeris/celestialBody.hxx
4b3ba50ac2b8d9a9e73f98aa49d3781269aaf7ad
[simgear.git] / simgear / ephemeris / celestialBody.hxx
1 /**************************************************************************
2  * celestialBody.hxx
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). 
7  *
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.
12  *
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.
17  *
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.
21  *
22  * $Id$
23  **************************************************************************/
24
25
26 #ifndef _CELESTIALBODY_H_
27 #define _CELESTIALBODY_H_
28
29 #ifndef __cplusplus                                                          
30 # error This library requires C++
31 #endif                                   
32
33
34 #include <simgear/constants.h>
35 g
36 class Star;
37
38 class CelestialBody
39 {
40 protected:              // make the data protected, in order to give the
41                         //  inherited classes direct access to the data
42   double NFirst;        /* longitude of the ascending node first part */
43   double NSec;          /* longitude of the ascending node second part */
44   double iFirst;        /* inclination to the ecliptic first part */
45   double iSec;          /* inclination to the ecliptic second part */
46   double wFirst;        /* first part of argument of perihelion */
47   double wSec;          /* second part of argument of perihelion */
48   double aFirst;        /* semimayor axis first part*/
49   double aSec;          /* semimayor axis second part */
50   double eFirst;        /* eccentricity first part */
51   double eSec;          /* eccentricity second part */
52   double MFirst;        /* Mean anomaly first part */
53   double MSec;          /* Mean anomaly second part */
54
55   double N, i, w, a, e, M; /* the resulting orbital elements, obtained from the former */
56
57   double rightAscension, declination;
58   double r, R, s, FV;
59   double magnitude;
60   double lonEcl, latEcl;
61
62   double fgCalcEccAnom(double M, double e);
63   double fgCalcActTime(double mjd);
64   void updateOrbElements(double mjd);
65
66 public:
67   CelestialBody(double Nf, double Ns,
68                 double If, double Is,
69                 double wf, double ws,
70                 double af, double as,
71                 double ef, double es,
72                 double Mf, double Ms, double mjd);
73   CelestialBody(double Nf, double Ns,
74                 double If, double Is,
75                 double wf, double ws,
76                 double af, double as,
77                 double ef, double es,
78                 double Mf, double Ms);
79   void getPos(double *ra, double *dec);
80   void getPos(double *ra, double *dec, double *magnitude);
81   double getRightAscension();
82   double getDeclination();
83   double getMagnitude();
84   double getLon();
85   double getLat(); 
86   void updatePosition(double mjd, Star *ourSun);
87 };
88
89 /*****************************************************************************
90  * inline CelestialBody::CelestialBody
91  * public constructor for a generic celestialBody object.
92  * initializes the 6 primary orbital elements. The elements are:
93  * N: longitude of the ascending node
94  * i: inclination to the ecliptic
95  * w: argument of perihelion
96  * a: semi-major axis, or mean distance from the sun
97  * e: eccenticity
98  * M: mean anomaly
99  * Each orbital element consists of a constant part and a variable part that 
100  * gradually changes over time. 
101  *
102  * Argumetns:
103  * the 13 arguments to the constructor constitute the first, constant 
104  * ([NiwaeM]f) and the second variable ([NiwaeM]s) part of the orbital 
105  * elements. The 13th argument is the current time. Note that the inclination
106  * is written with a capital (If, Is), because 'if' is a reserved word in the 
107  * C/C++ programming language.
108  ***************************************************************************/ 
109 inline CelestialBody::CelestialBody(double Nf, double Ns,
110                                     double If, double Is,
111                                     double wf, double ws,
112                                     double af, double as,
113                                     double ef, double es,
114                                     double Mf, double Ms, double mjd)
115 {
116   NFirst = Nf;     NSec = Ns;
117   iFirst = If;     iSec = Is;
118   wFirst = wf;     wSec = ws;
119   aFirst = af;     aSec = as;
120   eFirst = ef;     eSec = es;
121   MFirst = Mf;     MSec = Ms;
122   updateOrbElements(mjd);
123 };
124
125 inline CelestialBody::CelestialBody(double Nf, double Ns,
126                                     double If, double Is,
127                                     double wf, double ws,
128                                     double af, double as,
129                                     double ef, double es,
130                                     double Mf, double Ms)
131 {
132   NFirst = Nf;     NSec = Ns;
133   iFirst = If;     iSec = Is;
134   wFirst = wf;     wSec = ws;
135   aFirst = af;     aSec = as;
136   eFirst = ef;     eSec = es;
137   MFirst = Mf;     MSec = Ms;
138 };
139
140 /****************************************************************************
141  * inline void CelestialBody::updateOrbElements(double mjd)
142  * given the current time, this private member calculates the actual 
143  * orbital elements
144  *
145  * Arguments: double mjd: the current modified julian date:
146  *
147  * return value: none
148  ***************************************************************************/
149 inline void CelestialBody::updateOrbElements(double mjd)
150 {
151   double actTime = fgCalcActTime(mjd);
152    M = DEG_TO_RAD * (MFirst + (MSec * actTime));
153    w = DEG_TO_RAD * (wFirst + (wSec * actTime));
154    N = DEG_TO_RAD * (NFirst + (NSec * actTime));
155    i = DEG_TO_RAD * (iFirst + (iSec * actTime));
156    e = eFirst + (eSec * actTime);
157    a = aFirst + (aSec * actTime);
158 }
159 /*****************************************************************************
160  * inline double CelestialBody::fgCalcActTime(double mjd)
161  * this private member function returns the offset in days from the epoch for
162  * wich the orbital elements are calculated (Jan, 1st, 2000).
163  * 
164  * Argument: the current time
165  *
166  * return value: the (fractional) number of days until Jan 1, 2000.
167  ****************************************************************************/
168 inline double CelestialBody::fgCalcActTime(double mjd)
169 {
170   return (mjd - 36523.5);
171 }
172
173 /*****************************************************************************
174  * inline void CelestialBody::getPos(double* ra, double* dec)
175  * gives public access to Right Ascension and declination
176  *
177  ****************************************************************************/
178 inline void CelestialBody::getPos(double* ra, double* dec)
179 {
180   *ra  = rightAscension;
181   *dec = declination;
182 }
183
184 /*****************************************************************************
185  * inline void CelestialBody::getPos(double* ra, double* dec, double* magnitude
186  * gives public acces to the current Right ascension, declination, and 
187  * magnitude
188  ****************************************************************************/
189 inline void CelestialBody::getPos(double* ra, double* dec, double* magn)
190 {
191   *ra = rightAscension;
192   *dec = declination;
193   *magn = magnitude;
194 }
195
196 inline double CelestialBody::getRightAscension() { return rightAscension; }
197 inline double CelestialBody::getDeclination() { return declination; }
198 inline double CelestialBody::getMagnitude() { return magnitude; }
199
200 inline double CelestialBody::getLon()
201 {
202   return lonEcl;
203 }
204
205 inline double CelestialBody::getLat()
206 {
207   return latEcl;
208 }
209
210 #endif // _CELESTIALBODY_H_
211
212
213
214
215
216
217
218
219
220
221
222