1 /***************************************************************************
2 kssun.cpp - K Desktop Planetarium
4 begin : Sun Jul 22 2001
5 copyright : (C) 2001 by Jason Harris
6 email : jharris@30doradus.org
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
19 #include <qdatetime.h>
23 #include "ksnumbers.h"
24 #include "kstarsdatetime.h"
26 KSSun::KSSun( KStarsData
*kd
, QString fn
, double pSize
) : KSPlanet( kd
, I18N_NOOP( "Sun" ), fn
, pSize
) {
28 JD0 = 2447892.5; //Jan 1, 1990
29 eclong0 = 279.403303; //mean ecliptic longitude at JD0
30 plong0 = 282.768422; //longitude of sun at perigee for JD0
31 e0 = 0.016713; //eccentricity of Earth's orbit at JD0
35 bool KSSun::loadData() {
36 // kdDebug() << k_funcinfo << endl;
37 return (odm
.loadData("earth") != 0);
40 bool KSSun::findGeocentricPosition( const KSNumbers
*num
, const KSPlanetBase
*Earth
) {
43 // For the precision we need, the earth's orbit is circular.
44 // So don't bother to iterate like KSPlanet does. Just subtract
45 // The current delay and recompute (once).
47 double delay
= (.0057755183 * Earth
->rsun()) / 365250.0;
50 // MHH 2002-02-04 I don't like this. But it avoids code duplication.
51 // Maybe we can find a better way.
53 const KSPlanet
*pEarth
= dynamic_cast<const KSPlanet
*>(Earth
);
54 /* FIXME: if you use pEarth at some point again, make sure you
55 check for 0L after the dynamic_cast! */
56 EclipticPosition trialpos
;
57 pEarth
->calcEcliptic(num
->julianMillenia() - delay
, trialpos
);
59 setEcLong( trialpos
.longitude
.Degrees() + 180.0 );
60 setEcLong( ecLong()->reduce().Degrees() );
61 setEcLat( -1.0*trialpos
.latitude
.Degrees() );
65 dms EarthLong
, EarthLat
; //heliocentric coords of Earth
67 double T
= num
->julianMillenia(); //Julian millenia since J2000
71 for (int i
=1; i
<6; ++i
) {
72 Tpow
[i
] = Tpow
[i
-1] * T
;
74 //First, find heliocentric coordinates
76 if (!(odc
= odm
.loadData("earth"))) return false;
79 for (int i
=0; i
<6; ++i
) {
81 for (uint j
= 0; j
< odc
->Lon
[i
].size(); ++j
) {
82 sum
[i
] += odc
->Lon
[i
][j
]->A
* cos( odc
->Lon
[i
][j
]->B
+ odc
->Lon
[i
][j
]->C
*T
);
85 //kdDebug() << name() << " : sum[" << i << "] = " << sum[i] <<endl;
88 EarthLong
.setRadians( sum
[0] + sum
[1] + sum
[2] +
89 sum
[3] + sum
[4] + sum
[5] );
90 EarthLong
.setD( EarthLong
.reduce().Degrees() );
92 //Compute Ecliptic Latitude
93 for (int i
=0; i
<6; ++i
) {
95 for (uint j
= 0; j
< odc
->Lat
[i
].size(); ++j
) {
96 sum
[i
] += odc
->Lat
[i
][j
]->A
* cos( odc
->Lat
[i
][j
]->B
+ odc
->Lat
[i
][j
]->C
*T
);
102 EarthLat
.setRadians( sum
[0] + sum
[1] + sum
[2] + sum
[3] +
105 //Compute Heliocentric Distance
106 for (int i
=0; i
<6; ++i
) {
108 for (uint j
= 0; j
< odc
->Dst
[i
].size(); ++j
) {
109 sum
[i
] += odc
->Dst
[i
][j
]->A
* cos( odc
->Dst
[i
][j
]->B
+ odc
->Dst
[i
][j
]->C
*T
);
114 ep
.radius
= sum
[0] + sum
[1] + sum
[2] + sum
[3] + sum
[4] + sum
[5];
116 setEcLong( EarthLong
.Degrees() + 180.0 );
117 setEcLong( ecLong()->reduce().Degrees() );
118 setEcLat( -1.0*EarthLat
.Degrees() );
121 //Finally, convert Ecliptic coords to Ra, Dec. Ecliptic latitude is zero, by definition
122 EclipticToEquatorial( num
->obliquity() );
127 // We obtain the apparent geocentric ecliptic coordinates. That is, after
128 // nutation and aberration have been applied.
129 EquatorialToEcliptic( num
->obliquity() );
131 //Determine the position angle
137 long double KSSun::springEquinox(int year
) {
138 return equinox(year
, 18, 3, 0.);
141 long double KSSun::summerSolstice(int year
) {
142 return equinox(year
, 18, 6, 90.);
145 long double KSSun::autumnEquinox(int year
) {
146 return equinox(year
, 19, 9, 180.);
149 long double KSSun::winterSolstice(int year
) {
150 return equinox(year
, 18, 12, 270.);
153 long double KSSun::equinox(int year
, int d
, int m
, double angle
) {
155 long double eclipticLongitude
[5];
157 for(int i
= 0; i
<5; ++i
) {
158 jd0
[i
] = KStarsDateTime( ExtDate(year
,m
,d
+i
), QTime(0,0,0) ).djd();
159 KSNumbers
*ksn
= new KSNumbers(jd0
[i
]);
160 //FIXME this is the Earth position
161 findGeocentricPosition( ksn
);
163 eclipticLongitude
[i
] = (long double)ecLong()->Degrees();
166 return KSUtils::lagrangeInterpolation( eclipticLongitude
, jd0
, 5, angle
);