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