]> git.mxchange.org Git - simgear.git/blob - Scenery/sun.c
Initial revision of code contributed by Durk Talsma.
[simgear.git] / Scenery / sun.c
1 /**************************************************************************
2  * sun.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
29 struct SunPos fgCalcSunPos(struct OrbElements params)
30 {
31     double
32         EccAnom, lonSun,
33         xv, yv, v, r;
34     struct SunPos
35         solarPosition;
36
37     /* calculate the eccentric anomaly */
38     EccAnom = fgCalcEccAnom(params.M, params.e);
39
40     /* calculate the Suns distance (r) and its true anomaly (v) */
41         xv = cos(EccAnom) - params.e;
42     yv = sqrt(1.0 - params.e*params.e) * sin(EccAnom);
43     v = atan2(yv, xv);
44     r = sqrt(xv*xv + yv*yv);
45
46     /* calculate the the Suns true longitude (lonsun) */
47     lonSun = v + params.w;
48
49         /* convert true longitude and distance to ecliptic rectangular geocentric
50        coordinates (xs, ys) */
51     solarPosition.xs = r * cos(lonSun);
52     solarPosition.ys = r * sin(lonSun);
53     return solarPosition;
54 }
55
56
57 /* $Log$
58 /* Revision 1.1  1997/10/25 03:16:11  curt
59 /* Initial revision of code contributed by Durk Talsma.
60 /*
61  */