//------------------------------------------------------------------------------------ double GMST(DayTime t) { try { // days' since epoch = +/-(integer+0.5) double days = t.JD() - 2451545; int d=int(days); if(d < 0 && days==double(d)) d++; days = d + (days<0.0 ? -0.5 : 0.5); double Tp = days/36525.0; // Compute GMST double G; //G = 24060.0 + 50.54841 + 8640184.812866*Tp; // seconds (24060s = 6h 41min) //G /= 86400.0; // instead, divide the above equation by 86400.0 manually... G = 0.27847222 + 0.00058505104167 + 100.0021390378009*Tp; G += (0.093104 - 6.2e-6*Tp)*Tp*Tp/86400.0; // seconds/86400 = circles double r=1.002737909350795 + (5.9006e-11 - 5.9e-15*Tp)*Tp; G += r*t.secOfDay()/86400.0; // circles G *= 360.0; // degrees //G = fmod(G,360.0); //if(G < -180.0) G += 360.0; //if(G > 180.0) G -= 360.0; return G; } catch(Exception& e) { GPSTK_RETHROW(e); } catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); } catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); } }
//------------------------------------------------------------------------------------ // Solar ephemeris, in ECEF coordinates. // Accuracy is about 1 arcminute, when t is within 2 centuries of 2000. // Ref. Astronomical Almanac pg C24, as presented on USNO web site. // input // t epoch of interest // output // lat,lon,R latitude, longitude and distance (deg,deg,m in ECEF) of sun at t. // AR apparent angular radius of sun as seen at Earth (deg) at t. void SolarPosition(DayTime t, double& lat, double& lon, double& R, double& AR) { try { //const double mPerAU = 149598.0e6; double D; // days since J2000 double g,q; double L; // sun's geocentric apparent ecliptic longitude (deg) //double b=0; // sun's geocentric apparent ecliptic latitude (deg) double e; // mean obliquity of the ecliptic (deg) //double R; // sun's distance from Earth (m) double RA; // sun's right ascension (deg) double DEC; // sun's declination (deg) //double AR; // sun's apparent angular radius as seen at Earth (deg) D = t.JD() - 2451545.0; g = (357.529 + 0.98560028 * D) * DEG_TO_RAD; q = 280.459 + 0.98564736 * D; L = (q + 1.915 * ::sin(g) + 0.020 * ::sin(2*g)) * DEG_TO_RAD; e = (23.439 - 0.00000036 * D) * DEG_TO_RAD; RA = atan2(::cos(e)*::sin(L),::cos(L)) * RAD_TO_DEG; DEC = ::asin(::sin(e)*::sin(L)) * RAD_TO_DEG; //equation of time = apparent solar time minus mean solar time //= [q-RA (deg)]/(15deg/hr) // compute the hour angle of the vernal equinox = GMST and convert RA to lon lon = fmod(RA-GMST(t),360.0); if(lon < -180.0) lon += 360.0; if(lon > 180.0) lon -= 360.0; lat = DEC; // ECEF unit vector in direction Earth to sun //xhat = ::cos(lat*DEG_TO_RAD)*::cos(lon*DEG_TO_RAD); //yhat = ::cos(lat*DEG_TO_RAD)*::sin(lon*DEG_TO_RAD); //zhat = ::sin(lat*DEG_TO_RAD); // R in AU R = 1.00014 - 0.01671 * ::cos(g) - 0.00014 * ::cos(2*g); // apparent angular radius in degrees AR = 0.2666/R; // convert to meters R *= 149598.0e6; } catch(Exception& e) { GPSTK_RETHROW(e); } catch(exception& e) { Exception E("std except: "+string(e.what())); GPSTK_THROW(E); } catch(...) { Exception e("Unknown exception"); GPSTK_THROW(e); } }