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