• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

kssun.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           kssun.cpp  -  K Desktop Planetarium
00003                              -------------------
00004     begin                : Sun Jul 22 2001
00005     copyright            : (C) 2001 by Jason Harris
00006     email                : jharris@30doradus.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <math.h>
00019 #include <qdatetime.h>
00020 
00021 #include "kssun.h"
00022 #include "ksutils.h"
00023 #include "ksnumbers.h"
00024 #include "kstarsdatetime.h"
00025 
00026 KSSun::KSSun( KStarsData *kd, QString fn, double pSize ) : KSPlanet( kd, I18N_NOOP( "Sun" ), fn, pSize ) {
00027     /*
00028     JD0 = 2447892.5; //Jan 1, 1990
00029     eclong0 = 279.403303; //mean ecliptic longitude at JD0
00030     plong0 = 282.768422; //longitude of sun at perigee for JD0
00031     e0 = 0.016713; //eccentricity of Earth's orbit at JD0
00032     */
00033     setMag( -26.73 );
00034 }
00035 
00036 bool KSSun::loadData() {
00037 //  kdDebug() << k_funcinfo << endl;
00038     return (odm.loadData("earth") != 0);
00039 }
00040 
00041 bool KSSun::findGeocentricPosition( const KSNumbers *num, const KSPlanetBase *Earth ) {
00042     if (Earth) {
00043         //
00044         // For the precision we need, the earth's orbit is circular.
00045         // So don't bother to iterate like KSPlanet does. Just subtract
00046         // The current delay and recompute (once).
00047         //
00048         double delay = (.0057755183 * Earth->rsun()) / 365250.0;
00049 
00050         //
00051         // MHH 2002-02-04 I don't like this. But it avoids code duplication.
00052         // Maybe we can find a better way.
00053         //
00054         const KSPlanet *pEarth = dynamic_cast<const KSPlanet *>(Earth);
00055         /* FIXME: if you use pEarth at some point again, make sure you
00056             check for 0L after the dynamic_cast! */
00057         EclipticPosition trialpos;
00058         pEarth->calcEcliptic(num->julianMillenia() - delay, trialpos);
00059 
00060         setEcLong( trialpos.longitude.Degrees() + 180.0 );
00061         setEcLong( ecLong()->reduce().Degrees() );
00062         setEcLat( -1.0*trialpos.latitude.Degrees() );
00063 
00064     } else {
00065         double sum[6];
00066         dms EarthLong, EarthLat; //heliocentric coords of Earth
00067         OrbitDataColl * odc;
00068         double T = num->julianMillenia(); //Julian millenia since J2000
00069         double Tpow[6];
00070 
00071         Tpow[0] = 1.0;
00072         for (int i=1; i<6; ++i) {
00073             Tpow[i] = Tpow[i-1] * T;
00074         }
00075             //First, find heliocentric coordinates
00076 
00077         if (!(odc =  odm.loadData("earth"))) return false;
00078 
00079         //Ecliptic Longitude
00080         for (int i=0; i<6; ++i) {
00081             sum[i] = 0.0;
00082             for (uint j = 0; j < odc->Lon[i].size(); ++j) {
00083                 sum[i] += odc->Lon[i][j]->A * cos( odc->Lon[i][j]->B + odc->Lon[i][j]->C*T );
00084             }
00085             sum[i] *= Tpow[i];
00086             //kdDebug() << name() << " : sum[" << i << "] = " << sum[i] <<endl;
00087         }
00088 
00089         EarthLong.setRadians( sum[0] + sum[1] + sum[2] +
00090                 sum[3] + sum[4] + sum[5] );
00091         EarthLong.setD( EarthLong.reduce().Degrees() );
00092 
00093         //Compute Ecliptic Latitude
00094         for (int i=0; i<6; ++i) {
00095             sum[i] = 0.0;
00096             for (uint j = 0; j < odc->Lat[i].size(); ++j) {
00097                 sum[i] += odc->Lat[i][j]->A * cos( odc->Lat[i][j]->B + odc->Lat[i][j]->C*T );
00098             }
00099             sum[i] *= Tpow[i];
00100         }
00101 
00102 
00103         EarthLat.setRadians( sum[0] + sum[1] + sum[2] + sum[3] +
00104                 sum[4] + sum[5] );
00105 
00106         //Compute Heliocentric Distance
00107         for (int i=0; i<6; ++i) {
00108             sum[i] = 0.0;
00109             for (uint j = 0; j < odc->Dst[i].size(); ++j) {
00110                 sum[i] += odc->Dst[i][j]->A * cos( odc->Dst[i][j]->B + odc->Dst[i][j]->C*T );
00111             }
00112             sum[i] *= Tpow[i];
00113         }
00114 
00115         ep.radius = sum[0] + sum[1] + sum[2] + sum[3] + sum[4] + sum[5];
00116 
00117         setEcLong( EarthLong.Degrees() + 180.0 );
00118         setEcLong( ecLong()->reduce().Degrees() );
00119         setEcLat( -1.0*EarthLat.Degrees() );
00120     }
00121 
00122     //Finally, convert Ecliptic coords to Ra, Dec.  Ecliptic latitude is zero, by definition
00123     EclipticToEquatorial( num->obliquity() );
00124 
00125     nutate(num);
00126     aberrate(num);
00127 
00128     // We obtain the apparent geocentric ecliptic coordinates. That is, after 
00129     // nutation and aberration have been applied.
00130     EquatorialToEcliptic( num->obliquity() );
00131     
00132     //Determine the position angle
00133     findPA( num );
00134 
00135     return true;
00136 }
00137 
00138 long double KSSun::springEquinox(int year) {
00139     return equinox(year, 18, 3, 0.);
00140 }
00141 
00142 long double KSSun::summerSolstice(int year) {
00143     return equinox(year, 18, 6, 90.);
00144 }
00145 
00146 long double KSSun::autumnEquinox(int year) {
00147     return equinox(year, 19, 9, 180.);
00148 }
00149 
00150 long double KSSun::winterSolstice(int year) {
00151     return equinox(year, 18, 12, 270.);
00152 }
00153 
00154 long double KSSun::equinox(int year, int d, int m, double angle) {
00155     long double jd0[5];
00156     long double eclipticLongitude[5];
00157     
00158     for(int i = 0; i<5; ++i) {
00159         jd0[i] = KStarsDateTime( ExtDate(year,m,d+i), QTime(0,0,0) ).djd();
00160         KSNumbers *ksn = new KSNumbers(jd0[i]);
00161         //FIXME this is the Earth position
00162         findGeocentricPosition( ksn );
00163         delete ksn;
00164         eclipticLongitude[i] = (long double)ecLong()->Degrees();
00165     }
00166 
00167     return KSUtils::lagrangeInterpolation( eclipticLongitude, jd0, 5, angle );
00168 }

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal