]> git.mxchange.org Git - flightgear.git/blob - Astro/celestialBody.hxx
MSVC++ portability tweaks contributed by Bernie Bright.
[flightgear.git] / Astro / 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  * (Log is kept at end of this file)
24  **************************************************************************/
25
26
27 #ifndef _CELESTIALBODY_H_
28 #define _CELESTIALBODY_H_
29
30 #ifndef __cplusplus                                                          
31 # error This library requires C++
32 #endif                                   
33
34
35 #include <Time/fg_time.hxx>
36 #include <Include/fg_constants.h>
37
38 class Star;
39
40 class CelestialBody
41 {
42 protected:              // make the data protected, in order to give the inherited
43                         // 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
63   double fgCalcEccAnom(double M, double e);
64   double fgCalcActTime(fgTIME *t);
65   void updateOrbElements(fgTIME *t);
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, fgTIME *t);
74   void getPos(double *ra, double *dec);
75   void getPos(double *ra, double *dec, double *magnitude);
76   void updatePosition(fgTIME *t, Star *ourSun);
77 };
78
79 /*****************************************************************************
80  * inline CelestialBody::CelestialBody
81  * public constructor for a generic celestialBody object.
82  * initializes the 6 primary orbital elements. The elements are:
83  * N: longitude of the ascending node
84  * i: inclination to the ecliptic
85  * w: argument of perihelion
86  * a: semi-major axis, or mean distance from the sun
87  * e: eccenticity
88  * M: mean anomaly
89  * Each orbital element consists of a constant part and a variable part that 
90  * gradually changes over time. 
91  *
92  * Argumetns:
93  * the 13 arguments to the constructor constitute the first, constant 
94  * ([NiwaeM]f) and the second variable ([NiwaeM]s) part of the orbital 
95  * elements. The 13th argument is the current time. Note that the inclination
96  * is written with a capital (If, Is), because 'if' is a reserved word in the 
97  * C/C++ programming language.
98  ***************************************************************************/ 
99 inline CelestialBody::CelestialBody(double Nf, double Ns,
100                                     double If, double Is,
101                                     double wf, double ws,
102                                     double af, double as,
103                                     double ef, double es,
104                                     double Mf, double Ms, fgTIME *t)
105 {
106   NFirst = Nf;     NSec = Ns;
107   iFirst = If;     iSec = Is;
108   wFirst = wf;     wSec = ws;
109   aFirst = af;     aSec = as;
110   eFirst = ef;     eSec = es;
111   MFirst = Mf;     MSec = Ms;
112   updateOrbElements(t);
113 };
114
115 /****************************************************************************
116  * inline void CelestialBody::updateOrbElements(fgTIME *t)
117  * given the current time, this private member calculates the actual 
118  * orbital elements
119  *
120  * Arguments: fgTIME *t: the current time:
121  *
122  * return value: none
123  ***************************************************************************/
124 inline void CelestialBody::updateOrbElements(fgTIME *t)
125 {
126   double actTime = fgCalcActTime(t);
127    M = DEG_TO_RAD * (MFirst + (MSec * actTime));
128    w = DEG_TO_RAD * (wFirst + (wSec * actTime));
129    N = DEG_TO_RAD * (NFirst + (NSec * actTime));
130    i = DEG_TO_RAD * (iFirst + (iSec * actTime));
131    e = eFirst + (eSec * actTime);
132    a = aFirst + (aSec * actTime);
133 }
134 /*****************************************************************************
135  * inline double CelestialBody::fgCalcActTime(fgTIME *t)
136  * this private member function returns the offset in days from the epoch for
137  * wich the orbital elements are calculated (Jan, 1st, 2000).
138  * 
139  * Argument: the current time
140  *
141  * return value: the (fractional) number of days until Jan 1, 2000.
142  ****************************************************************************/
143 inline double CelestialBody::fgCalcActTime(fgTIME *t)
144 {
145   return (t->mjd - 36523.5);
146 }
147
148 /*****************************************************************************
149  * inline void CelestialBody::getPos(double* ra, double* dec)
150  * gives public access to Right Ascension and declination
151  *
152  ****************************************************************************/
153 inline void CelestialBody::getPos(double* ra, double* dec)
154 {
155   *ra  = rightAscension;
156   *dec = declination;
157 }
158
159 /*****************************************************************************
160  * inline void CelestialBody::getPos(double* ra, double* dec, double* magnitude
161  * gives public acces to the current Right ascension, declination, and 
162  * magnitude
163  ****************************************************************************/
164 inline void CelestialBody::getPos(double* ra, double* dec, double* magn)
165 {
166   *ra = rightAscension;
167   *dec = declination;
168   *magn = magnitude;
169 }
170
171
172 #endif // _CELESTIALBODY_H_
173
174
175
176
177
178
179
180
181
182
183
184