]> git.mxchange.org Git - simgear.git/blob - simgear/ephemeris/celestialBody.hxx
40c8a1163149aac8f8e5a4092e8e69a9e0aaeb68
[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 #include <simgear/timing/sg_time.hxx>
36
37 class Star;
38
39 class CelestialBody
40 {
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 */
55
56   double N, i, w, a, e, M; /* the resulting orbital elements, obtained from the former */
57
58   double rightAscension, declination;
59   double r, R, s, FV;
60   double magnitude;
61   double lonEcl, latEcl;
62
63   double fgCalcEccAnom(double M, double e);
64   double fgCalcActTime(double mjd);
65   void updateOrbElements(double mjd);
66
67 public:
68   CelestialBody(double Nf, double Ns,
69                 double If, double Is,
70                 double wf, double ws,
71                 double af, double as,
72                 double ef, double es,
73                 double Mf, double Ms, double mjd);
74   CelestialBody(double Nf, double Ns,
75                 double If, double Is,
76                 double wf, double ws,
77                 double af, double as,
78                 double ef, double es,
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();
85   double getLon();
86   double getLat(); 
87   void updatePosition(double mjd, Star *ourSun);
88 };
89
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
98  * e: eccenticity
99  * M: mean anomaly
100  * Each orbital element consists of a constant part and a variable part that 
101  * gradually changes over time. 
102  *
103  * Argumetns:
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)
116 {
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);
124 };
125
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)
132 {
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;
139 };
140
141 /****************************************************************************
142  * inline void CelestialBody::updateOrbElements(double mjd)
143  * given the current time, this private member calculates the actual 
144  * orbital elements
145  *
146  * Arguments: double mjd: the current modified julian date:
147  *
148  * return value: none
149  ***************************************************************************/
150 inline void CelestialBody::updateOrbElements(double mjd)
151 {
152   double actTime = fgCalcActTime(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);
159 }
160 /*****************************************************************************
161  * inline double CelestialBody::fgCalcActTime(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).
164  * 
165  * Argument: the current time
166  *
167  * return value: the (fractional) number of days until Jan 1, 2000.
168  ****************************************************************************/
169 inline double CelestialBody::fgCalcActTime(double mjd)
170 {
171   return (mjd - 36523.5);
172 }
173
174 /*****************************************************************************
175  * inline void CelestialBody::getPos(double* ra, double* dec)
176  * gives public access to Right Ascension and declination
177  *
178  ****************************************************************************/
179 inline void CelestialBody::getPos(double* ra, double* dec)
180 {
181   *ra  = rightAscension;
182   *dec = declination;
183 }
184
185 /*****************************************************************************
186  * inline void CelestialBody::getPos(double* ra, double* dec, double* magnitude
187  * gives public acces to the current Right ascension, declination, and 
188  * magnitude
189  ****************************************************************************/
190 inline void CelestialBody::getPos(double* ra, double* dec, double* magn)
191 {
192   *ra = rightAscension;
193   *dec = declination;
194   *magn = magnitude;
195 }
196
197 inline double CelestialBody::getRightAscension() { return rightAscension; }
198 inline double CelestialBody::getDeclination() { return declination; }
199 inline double CelestialBody::getMagnitude() { return magnitude; }
200
201 inline double CelestialBody::getLon()
202 {
203   return lonEcl;
204 }
205
206 inline double CelestialBody::getLat()
207 {
208   return latEcl;
209 }
210
211 #endif // _CELESTIALBODY_H_
212
213
214
215
216
217
218
219
220
221
222
223