Example #1
0
void
sunpos(double jd, int apparent, double *ra, double *dec, double *rv, double* slong)
{
    double t, t2, t3, l, m, e, ea, v, theta, omega, eps;

    // Time, in Julian centuries of 36525 ephemeris days,
    // measured from the epoch 1900 January 0.5 ET.
    t = (jd - 2415020.0) / 36525.0;
    t2 = t * t;
    t3 = t2 * t;

    // Geometric mean longitude of the Sun, referred to the
    // mean equinox of the date.
    l = fixangle(279.69668 + 36000.76892 * t + 0.0003025 * t2);

    // Sun's mean anomaly.
    m = fixangle(358.47583 + 35999.04975*t - 0.000150*t2 - 0.0000033*t3);

    // Eccentricity of the Earth's orbit.
    e = 0.01675104 - 0.0000418 * t - 0.000000126 * t2;

    // Eccentric anomaly.
    ea = kepler(m, e);

    // True anomaly
    v = fixangle(2 * rtd(atan(sqrt((1 + e) / (1 - e))  * tan(ea / 2))));

    // Sun's true longitude.
    theta = l + v - m;

    // Obliquity of the ecliptic.
    eps = 23.452294 - 0.0130125 * t - 0.00000164 * t2 + 0.000000503 * t3;

    // Corrections for Sun's apparent longitude, if desired.
    if (apparent) {
        omega = fixangle(259.18 - 1934.142 * t);
        theta = theta - 0.00569 - 0.00479 * sin(dtr(omega));
        eps += 0.00256 * cos(dtr(omega));
    }

    // Return Sun's longitude and radius vector
    *slong = theta;
    *rv = (1.0000002 * (1 - e * e)) / (1 + e * cos(dtr(v)));

    // Determine solar co-ordinates.
    *ra = fixangle(rtd(atan2(cos(dtr(eps)) * sin(dtr(theta)), cos(dtr(theta)))));
    *dec = rtd(asin(sin(dtr(eps)) * sin(dtr(theta))));
}
Example #2
0
EXPORT double sun_ecliptic_longitude (double jday)
{ /* Calculate ecliptic longitude of the sun */
	double T, O, M, L;
	T = (jday - 2451545.0) / 36525.0;
	O = deg2rad(282.9400);
	M = deg2rad(357.5256 + 35999.049 * T);
	L = O + M + (6191.2 * T + 6893.0 * sin(M) + 72.0 * sin(2.0 * M))
		/ 1296000.0 * 2.0 * M_PI;
	return fixangle(rad2deg(L));
}
Example #3
0
static double
phase( double pdate,
       double *pphase,      /* Illuminated fraction        */
       double *mage,        /* Age of moon in days         */
       double *dist,        /* Distance in kilometres      */
       double *angdia,      /* Angular diameter in degrees */
       double *sudist,      /* Distance to Sun             */
       double *suangdia )   /* Sun's angular diameter      */
{
    double  Day, N, M, Ec, Lambdasun, ml, MM, MN, Ev, Ae, A3, MmP,
            mEc, A4, lP, V, lPP, NP, y, x, Lambdamoon,
            MoonAge, MoonPhase,
            MoonDist, MoonDFrac, MoonAng,
            F, SunDist, SunAng;

    /* Calculation of the Sun's position */

    Day = pdate - epoch;                    /* Date within epoch */
    N = fixangle((360.0 / 365.2422) * Day); /* Mean anomaly of the Sun */
    M = fixangle(N + elonge - elongp);      /* Convert from perigee
                                               co-ordinates to epoch 1980.0 */
    Ec = kepler(M, eccent);                 /* Solve equation of Kepler */
    Ec = sqrt((1.0 + eccent) / (1.0 - eccent)) * tan(Ec / 2.0);
    Ec = 2.0 * todeg(atan(Ec));             /* True anomaly */
    Lambdasun = fixangle(Ec + elongp);      /* Sun's geocentric ecliptic
                                               longitude */
    /* Orbital distance factor */
    F = ((1.0 + eccent * cos(torad(Ec))) / (1.0 - eccent * eccent));
    SunDist = sunsmax / F;              /* Distance to Sun in km */
    SunAng = F * sunangsiz;             /* Sun's angular size in degrees */

    /* Calculation of the Moon's position */
    /* Moon's mean longitude */
    ml = fixangle(13.1763966 * Day + mmlong);

    /* Moon's mean anomaly */
    MM = fixangle(ml - 0.1114041 * Day - mmlongp);

    /* Moon's ascending node mean longitude */
    MN = fixangle(mlnode - 0.0529539 * Day);

    /* Evection */
    Ev = 1.2739 * sin(torad(2.0 * (ml - Lambdasun) - MM));

    /* Annual equation */
    Ae = 0.1858 * sin(torad(M));

    /* Correction term */
    A3 = 0.37 * sin(torad(M));

    /* Corrected anomaly */
    MmP = MM + Ev - Ae - A3;

    /* Correction for the equation of the centre */
    mEc = 6.2886 * sin(torad(MmP));

    /* Another correction term */
    A4 = 0.214 * sin(torad(2.0 * MmP));

    /* Corrected longitude */
    lP = ml + Ev + mEc - Ae + A4;

    /* Variation */
    V = 0.6583 * sin(torad(2.0 * (lP - Lambdasun)));

    /* True longitude */
    lPP = lP + V;

    /* Corrected longitude of the node */
    NP = MN - 0.16 * sin(torad(M));

    /* Y inclination coordinate */
    y = sin(torad(lPP - NP)) * cos(torad(minc));

    /* X inclination coordinate */
    x = cos(torad(lPP - NP));

    /* Ecliptic longitude */
    Lambdamoon = todeg(atan2(y, x));
    Lambdamoon += NP;

#if 0
    /* Ecliptic latitude */
    (void)todeg(asin(sin(torad(lPP - NP)) * sin(torad(minc))));
#endif

    /* Calculation of the phase of the Moon */
    /* Age of the Moon in degrees */
    MoonAge = lPP - Lambdasun;

    /* Phase of the Moon */
    MoonPhase = (1.0 - cos(torad(MoonAge))) / 2.0;

    /* Calculate distance of moon from the centre of the Earth */

    MoonDist = (msmax * (1.0 - mecc * mecc)) /
                   (1.0 + mecc * cos(torad(MmP + mEc)));

    /* Calculate Moon's angular diameter */

    MoonDFrac = MoonDist / msmax;
    MoonAng = mangsiz / MoonDFrac;

#if	0
    /* Calculate Moon's parallax */
    MoonPar = mparallax / MoonDFrac;
#endif
    *pphase   = MoonPhase;
    *mage     = synmonth * (fixangle(MoonAge) / 360.0);
    *dist     = MoonDist;
    *angdia   = MoonAng;
    *sudist   = SunDist;
    *suangdia = SunAng;
    return fixangle(MoonAge) / 360.0;
}