]> git.mxchange.org Git - simgear.git/blob - simgear/ephemeris/star.cxx
Added gdbm to SimGear. Many systems will already have gdbm installed so
[simgear.git] / simgear / ephemeris / star.cxx
1 /**************************************************************************
2  * star.cxx
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 #ifdef __BORLANDC__
27 #  define exception c_exception
28 #endif
29 #include <math.h>
30
31 #include <simgear/debug/logstream.hxx>
32
33 #include <Time/sunpos.hxx>
34 #include <Time/light.hxx>
35 #include <Main/options.hxx>
36
37 #include "star.hxx"
38
39
40 /*************************************************************************
41  * Star::Star(FGTime *t)
42  * Public constructor for class Star
43  * Argument: The current time.
44  * the hard coded orbital elements our sun are passed to 
45  * CelestialBody::CelestialBody();
46  * note that the word sun is avoided, in order to prevent some compilation
47  * problems on sun systems 
48  ************************************************************************/
49 Star::Star(FGTime *t) :
50     CelestialBody (0.000000,  0.0000000000,
51                    0.0000,    0.00000,
52                    282.9404,  4.7093500E-5,     
53                    1.0000000, 0.000000, 
54                    0.016709,  -1.151E-9,
55                    356.0470,  0.98560025850, t)
56 {
57     distance = 0.0;
58 }
59
60 Star::Star() :
61     CelestialBody (0.000000,  0.0000000000,
62                    0.0000,    0.00000,
63                    282.9404,  4.7093500E-5,     
64                    1.0000000, 0.000000, 
65                    0.016709,  -1.151E-9,
66                    356.0470,  0.98560025850)
67 {
68     distance = 0.0;
69 }
70
71 Star::~Star()
72 {
73 }
74
75
76 /*************************************************************************
77  * void Star::updatePosition(FGTime *t, Star *ourSun)
78  * 
79  * calculates the current position of our sun.
80  *************************************************************************/
81 void Star::updatePosition(FGTime *t)
82 {
83   double 
84     actTime, eccAnom, 
85     xv, yv, v, r,
86     xe, ye, ze, ecl;
87
88   updateOrbElements(t);
89   
90   actTime = fgCalcActTime(t);
91   ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime); // Angle in Radians
92   eccAnom = fgCalcEccAnom(M, e);  // Calculate the eccentric Anomaly (also known as solving Kepler's equation)
93   
94   xv = cos(eccAnom) - e;
95   yv = sqrt (1.0 - e*e) * sin(eccAnom);
96   v = atan2 (yv, xv);                   // the sun's true anomaly
97   distance = r = sqrt (xv*xv + yv*yv);  // and its distance
98
99   lonEcl = v + w; // the sun's true longitude
100   latEcl = 0;
101
102   // convert the sun's true longitude to ecliptic rectangular 
103   // geocentric coordinates (xs, ys)
104   xs = r * cos (lonEcl);
105   ys = r * sin (lonEcl);
106
107   // convert ecliptic coordinates to equatorial rectangular
108   // geocentric coordinates
109
110   xe = xs;
111   ye = ys * cos (ecl);
112   ze = ys * sin (ecl);
113
114   // And finally, calculate right ascension and declination
115   rightAscension = atan2 (ye, xe);
116   declination = atan2 (ze, sqrt (xe*xe + ye*ye));
117 }