]> git.mxchange.org Git - flightgear.git/blob - Scenery/planets.c
More light/material property tweaking ... still a ways off.
[flightgear.git] / Scenery / planets.c
1 /**************************************************************************
2  * planets.c
3  *
4  * Written 1997 by Durk Talsma, started October, 1997.  For the flight gear
5  * project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * $Id$
22  * (Log is kept at end of this file)
23  **************************************************************************/
24
25
26 #include "../Time/fg_time.h"
27 #include "orbits.h"
28 #include "planets.h"
29 #include "sun.h"
30
31
32 struct CelestialCoord fgCalculatePlanet(struct OrbElements planet,
33                                         struct OrbElements theSun,
34                                         struct fgTIME t)
35 {
36    struct CelestialCoord
37                 result;
38
39     struct SunPos
40         SolarPosition;
41
42         double
43         eccAnom, r, v, ecl, actTime,
44         xv, yv, xh, yh, zh, xg, yg, zg, xe, ye, ze;
45
46       actTime = fgCalcActTime(t);
47       /* calculate the angle between ecliptic and equatorial coordinate system */
48       ecl = fgDegToRad(23.4393 - 3.563E-7 * actTime);
49
50
51     /* calculate the eccentric anomaly */
52         eccAnom  = fgCalcEccAnom(planet.M, planet.e);
53
54     /* calculate the planets distance (r) and true anomaly (v) */
55     xv = planet.a * (cos(eccAnom) - planet.e);
56     yv = planet.a * (sqrt(1.0 - planet.e*planet.e) * sin(eccAnom));
57     v = atan2(yv, xv);
58     r = sqrt ( xv*xv + yv*yv);
59
60     /* calculate the planets position in 3-dimensional space */
61     xh = r * ( cos(planet.N) * cos(v+planet.w) - sin(planet.N) * sin(v+planet.w) * cos(planet.i));
62     yh = r * ( sin(planet.N) * cos(v+planet.w) + cos(planet.N) * sin(v+planet.w) * cos(planet.i));
63     zh = r * ( sin(v+planet.w) * sin(planet.i));
64
65     /* calculate the ecleptic longitude and latitude */
66
67     /*
68     lonecl = atan2(yh, xh);
69     latecl = atan2(zh, sqrt ( xh*xh + yh*yh));
70     */
71     /* calculate the solar position */
72
73     SolarPosition = fgCalcSunPos(theSun);
74     xg = xh + SolarPosition.xs;
75     yg = yh + SolarPosition.ys;
76     zg = zh;
77
78     xe = xg;
79     ye = yg * cos(ecl) - zg * sin(ecl);
80          ze = yg * sin(ecl) + zg * cos(ecl);
81     result.RightAscension = atan2(ye,xe);
82     result.Declination = atan2(ze, sqrt(xe*xe + ye*ye));
83     return result;
84 }
85
86
87 /* $Log$
88 /* Revision 1.2  1997/12/12 21:41:29  curt
89 /* More light/material property tweaking ... still a ways off.
90 /*
91  * Revision 1.1  1997/10/25 03:16:10  curt
92  * Initial revision of code contributed by Durk Talsma.
93  *
94  */