Exemplo n.º 1
0
        private static MoonPosition GetMoonPosition(DateTime date, double lat, double lng, Celestial cel)
        {
            //Set UTC date integrity
            date = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, DateTimeKind.Utc);

            double d = JulianConversions.GetJulian_Epoch2000(date);

            //Ch 47
            double JDE = JulianConversions.GetJulian(date); //Get julian

            double T = (JDE - 2451545) / 36525;             //Get dynamic time.

            double[]  LDMNF = Get_Moon_LDMNF(T);
            CelCoords c     = GetMoonCoords(d, cel, LDMNF, T);
            Distance  dist  = GetMoonDistance(date);
            double    lw    = rad * -lng;
            double    phi   = rad * lat;

            double H = rad * Get_Sidereal_Time(JDE, lw) - lw - c.ra;

            double ra  = c.ra;  //Adjust current RA formula to avoid needless RAD conversions
            double dec = c.dec; //Adjust current RA formula to avoid needless RAD conversions

            //Adjust for parallax (low accuracry increases may not be worth cost)
            //Investigate
            double pSinE = Get_pSinE(dec, dist.Meters) * Math.PI / 180;
            double pCosE = Get_pCosE(dec, dist.Meters) * Math.PI / 180;
            double cRA   = Parallax_RA(dist.Meters, H, pCosE, dec, ra);
            double tDEC  = Parallax_Dec(dist.Meters, H, pCosE, pSinE, dec, cRA);
            double tRA   = ra - cRA;

            dec = tDEC;
            ra  = tRA;

            //Get true altitude
            double h = altitude(H, phi, dec);

            // formula 14.1 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998.
            double pa = Math.Atan2(Math.Sin(H), Math.Tan(phi) * Math.Cos(dec) - Math.Sin(dec) * Math.Cos(H));

            //altitude correction for refraction
            h = h + astroRefraction(h);

            MoonPosition mp = new MoonPosition();

            mp.Azimuth          = azimuth(H, phi, dec);
            mp.Altitude         = h / Math.PI * 180;
            mp.Distance         = dist;
            mp.ParallacticAngle = pa;

            double horParal = 8.794 / (dist.Meters / 149.59787E6);                // horizontal parallax (arcseconds), Meeus S. 263
            double p        = Math.Asin(Math.Cos(h) * Math.Sin(horParal / 3600)); // parallax in altitude (degrees)

            p *= 1000;

            mp.ParallaxCorection = p;
            mp.Altitude         *= rad;

            return(mp);
        }
        //Moon Time Functions
        private static CelCoords GetSunCoords(double d)
        {
            double M    = solarMeanAnomaly(d),
                   L    = eclipticLongitude(M);
            CelCoords c = new CelCoords();

            c.dec = declination(L, 0);
            c.ra  = rightAscension(L, 0);
            return(c);
        }
        public static void GetMoonDistance(DateTime date, Celestial c)
        {
            date = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, DateTimeKind.Utc);

            double d = toDays(date);

            CelCoords cel = GetMoonCoords(d, c);

            c.MoonDistance = cel.dist;
        }
        static CelCoords GetMoonCoords(double d)
        {                                                 // geocentric ecliptic coordinates of the moon
            double L = rad * (218.316 + 13.176396 * d),   // ecliptic longitude
                   M = rad * (134.963 + 13.064993 * d),   // mean anomaly
                   F = rad * (93.272 + 13.229350 * d),    // mean distance

                   l     = L + rad * 6.289 * Math.Sin(M), // longitude
                   b     = rad * 5.128 * Math.Sin(F),     // latitude
                   dt    = 385001 - 20905 * Math.Cos(M);  // distance to the moon in km
            CelCoords mc = new CelCoords();

            mc.ra   = rightAscension(l, b);
            mc.dec  = declination(l, b);
            mc.dist = dt;
            return(mc);
        }
        public static void GetMoonIllumination(DateTime date, Celestial c)
        {
            date = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0, DateTimeKind.Utc);
            double    d = toDays(date);
            CelCoords s = GetSunCoords(d);
            CelCoords m = GetMoonCoords(d);

            double sdist = 149598000,
                   phi   = Math.Acos(Math.Sin(s.dec) * Math.Sin(m.dec) + Math.Cos(s.dec) * Math.Cos(m.dec) * Math.Cos(s.ra - m.ra)),
                   inc   = Math.Atan2(sdist * Math.Sin(phi), m.dist - sdist * Math.Cos(phi)),
                   angle = Math.Atan2(Math.Cos(s.dec) * Math.Sin(s.ra - m.ra), Math.Sin(s.dec) * Math.Cos(m.dec) -
                                      Math.Cos(s.dec) * Math.Sin(m.dec) * Math.Cos(s.ra - m.ra));
            MoonIllum mi = new MoonIllum();

            mi.Fraction = (1 + Math.Cos(inc)) / 2;
            mi.Phase    = 0.5 + 0.5 * inc * (angle < 0 ? -1 : 1) / Math.PI;
            mi.Angle    = angle;
            c.MoonPhase = mi.Phase;
        }
        static CelCoords GetMoonCoords(double d, Celestial c)
        {
            // geocentric ecliptic coordinates of the moon
            //Formulas used from http://aa.quae.nl/en/reken/hemelpositie.html#1_3
            double L = rad * (218.316 + 13.176396 * d), // ecliptic longitude
                   M = rad * (134.963 + 13.064993 * d), // mean anomaly
                   F = rad * (93.272 + 13.229350 * d),  // mean distance

                   l  = L + rad * 6.289 * Math.Sin(M),  // longitude
                   b  = rad * 5.128 * Math.Sin(F),      // latitude
                   dt = 385001 - 20905 * Math.Cos(M);   // distance to the moon in km
            //c.MoonSign = MoonSign(l);
            CelCoords mc = new CelCoords();

            mc.ra   = rightAscension(l, b);
            mc.dec  = declination(l, b);
            mc.dist = dt;
            return(mc);
        }
Exemplo n.º 7
0
        private static CelCoords GetMoonCoords(double d, Celestial c, double[] LDMNF, double t)
        {
            // Legacy function. Updated with Meeus Calcs for increased accuracy.
            // geocentric ecliptic coordinates of the moon
            // Meeus Ch 47
            double[] cs = Get_Moon_Coordinates(LDMNF, t);

            double l = cs[0]; // longitude
            double b = cs[1]; // latitude

            CelCoords mc = new CelCoords();

            mc.ra = rightAscension(l, b);
            double ra = mc.ra / Math.PI * 180;

            mc.dec = declination(l, b);
            double dec = mc.dec / Math.PI * 180;

            return(mc);
        }
        static MoonPosition GetMoonPosition(DateTime date, double lat, double lng)
        {
            double d = toDays(date);

            CelCoords c   = GetMoonCoords(d);
            double    lw  = rad * -lng;
            double    phi = rad * lat;
            double    H   = siderealTime(d, lw) - c.ra;
            double    h   = altitude(H, phi, c.dec);

            // formula 14.1 of "Astronomical Algorithms" 2nd edition by Jean Meeus (Willmann-Bell, Richmond) 1998.
            double pa = Math.Atan2(Math.Sin(H), Math.Tan(phi) * Math.Cos(c.dec) - Math.Sin(c.dec) * Math.Cos(H));

            h = h + astroRefraction(h); // altitude correction for refraction

            MoonPosition mp = new MoonPosition();

            mp.Azimuth          = azimuth(H, phi, c.dec);
            mp.Altitude         = h;
            mp.Distance         = c.dist;
            mp.ParallacticAngle = pa;
            return(mp);
        }
        public static void GetMoonIllumination(DateTime date, Celestial c, double lat, double lng)
        {
            date = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, DateTimeKind.Utc);

            double    d = toDays(date);
            CelCoords s = GetSunCoords(d);
            CelCoords m = GetMoonCoords(d, c);

            double sdist = 149598000,
                   phi   = Math.Acos(Math.Sin(s.dec) * Math.Sin(m.dec) + Math.Cos(s.dec) * Math.Cos(m.dec) * Math.Cos(s.ra - m.ra)),
                   inc   = Math.Atan2(sdist * Math.Sin(phi), m.dist - sdist * Math.Cos(phi)),
                   angle = Math.Atan2(Math.Cos(s.dec) * Math.Sin(s.ra - m.ra), Math.Sin(s.dec) * Math.Cos(m.dec) -
                                      Math.Cos(s.dec) * Math.Sin(m.dec) * Math.Cos(s.ra - m.ra));


            MoonIllum mi = new MoonIllum();

            mi.Fraction = (1 + Math.Cos(inc)) / 2;
            mi.Phase    = 0.5 + 0.5 * inc * (angle < 0 ? -1 : 1) / Math.PI;
            mi.Angle    = angle;


            c.MoonIllum = mi;

            string moonName = "";
            int    moonDate = 0;
            //GET PHASE NAME

            //CHECK MOON AT BEGINNING AT END OF DAY TO GET DAY PHASE IN UTC
            DateTime dMon = new DateTime(date.Year, date.Month, 1);

            for (int x = 1; x <= date.Day; x++)
            {
                DateTime nDate = new DateTime(dMon.Year, dMon.Month, x, 0, 0, 0, DateTimeKind.Utc);
                d = toDays(nDate);
                s = GetSunCoords(d);
                m = GetMoonCoords(d, c);

                phi   = Math.Acos(Math.Sin(s.dec) * Math.Sin(m.dec) + Math.Cos(s.dec) * Math.Cos(m.dec) * Math.Cos(s.ra - m.ra));
                inc   = Math.Atan2(sdist * Math.Sin(phi), m.dist - sdist * Math.Cos(phi));
                angle = Math.Atan2(Math.Cos(s.dec) * Math.Sin(s.ra - m.ra), Math.Sin(s.dec) * Math.Cos(m.dec) -
                                   Math.Cos(s.dec) * Math.Sin(m.dec) * Math.Cos(s.ra - m.ra));

                double startPhase = 0.5 + 0.5 * inc * (angle < 0 ? -1 : 1) / Math.PI;

                nDate = new DateTime(dMon.Year, dMon.Month, x, 23, 59, 59, DateTimeKind.Utc);
                d     = toDays(nDate);
                s     = GetSunCoords(d);
                m     = GetMoonCoords(d, c);

                phi   = Math.Acos(Math.Sin(s.dec) * Math.Sin(m.dec) + Math.Cos(s.dec) * Math.Cos(m.dec) * Math.Cos(s.ra - m.ra));
                inc   = Math.Atan2(sdist * Math.Sin(phi), m.dist - sdist * Math.Cos(phi));
                angle = Math.Atan2(Math.Cos(s.dec) * Math.Sin(s.ra - m.ra), Math.Sin(s.dec) * Math.Cos(m.dec) -
                                   Math.Cos(s.dec) * Math.Sin(m.dec) * Math.Cos(s.ra - m.ra));

                double endPhase = 0.5 + 0.5 * inc * (angle < 0 ? -1 : 1) / Math.PI;
                //Determine Moon Name.
                if (startPhase <= .5 && endPhase >= .5)
                {
                    moonDate = x;
                    moonName = GetMoonName(dMon.Month, moonName);
                }
                //Get Moon Name (month, string);
                //Get Moon Phase Name
                if (date.Day == x)
                {
                    if (startPhase > endPhase)
                    {
                        mi.PhaseName = "New Moon";
                        break;
                    }
                    if (startPhase <= .25 && endPhase >= .25)
                    {
                        mi.PhaseName = "First Quarter";
                        break;
                    }
                    if (startPhase <= .5 && endPhase >= .5)
                    {
                        mi.PhaseName = "Full Moon";
                        break;
                    }
                    if (startPhase <= .75 && endPhase >= .75)
                    {
                        mi.PhaseName = "Last Quarter";
                        break;
                    }

                    if (startPhase > 0 && startPhase < .25 && endPhase > 0 && endPhase < .25)
                    {
                        mi.PhaseName = "Waxing Crescent";
                        break;
                    }
                    if (startPhase > .25 && startPhase < .5 && endPhase > .25 && endPhase < .5)
                    {
                        mi.PhaseName = "Waxing Gibbous";
                        break;
                    }
                    if (startPhase > .5 && startPhase < .75 && endPhase > .5 && endPhase < .75)
                    {
                        mi.PhaseName = "Waning Gibbous";
                        break;
                    }
                    if (startPhase > .75 && startPhase < 1 && endPhase > .75 && endPhase < 1)
                    {
                        mi.PhaseName = "Waning Crescent";
                        break;
                    }
                }
            }
            if (date.Day == moonDate)
            {
                c.AstrologicalSigns.MoonName = moonName;
            }
            else
            {
                c.AstrologicalSigns.MoonName = "";
            }
            CalculateLunarEclipse(date, lat, lng, c);
        }
Exemplo n.º 10
0
        public static void GetMoonIllumination(DateTime date, Celestial c, double lat, double lng, EagerLoad el)
        {
            //Moon Illum must be done for both the Moon Name and Phase so either will trigger it to load
            if (el.Extensions.Lunar_Cycle || el.Extensions.Zodiac)
            {
                date = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, DateTimeKind.Utc);

                double    d     = JulianConversions.GetJulian_Epoch2000(date);
                CelCoords s     = GetSunCoords(d);
                double    JDE   = JulianConversions.GetJulian(date); //Get julian
                double    T     = (JDE - 2451545) / 36525;           //Get dynamic time.
                double[]  LDMNF = Get_Moon_LDMNF(T);

                CelCoords m = GetMoonCoords(d, c, LDMNF, T);

                double sdist = 149598000,
                       phi   = Math.Acos(Math.Sin(s.dec) * Math.Sin(m.dec) + Math.Cos(s.dec) * Math.Cos(m.dec) * Math.Cos(s.ra - m.ra)),
                       inc   = Math.Atan2(sdist * Math.Sin(phi), m.dist - sdist * Math.Cos(phi)),
                       angle = Math.Atan2(Math.Cos(s.dec) * Math.Sin(s.ra - m.ra), Math.Sin(s.dec) * Math.Cos(m.dec) -
                                          Math.Cos(s.dec) * Math.Sin(m.dec) * Math.Cos(s.ra - m.ra));


                MoonIllum mi = new MoonIllum();

                mi.Fraction = (1 + Math.Cos(inc)) / 2;
                mi.Phase    = 0.5 + 0.5 * inc * (angle < 0 ? -1 : 1) / Math.PI;
                mi.Angle    = angle;


                c.moonIllum = mi;

                string moonName = "";
                int    moonDate = 0;
                //GET PHASE NAME

                //CHECK MOON AT BEGINNING AT END OF DAY TO GET DAY PHASE
                DateTime dMon = new DateTime(date.Year, date.Month, 1);
                for (int x = 1; x <= date.Day; x++)
                {
                    DateTime nDate = new DateTime(dMon.Year, dMon.Month, x, 0, 0, 0, DateTimeKind.Utc);
                    d     = JulianConversions.GetJulian_Epoch2000(nDate);
                    s     = GetSunCoords(d);
                    JDE   = JulianConversions.GetJulian(nDate); //Get julian
                    T     = (JDE - 2451545) / 36525;            //Get dynamic time.
                    LDMNF = Get_Moon_LDMNF(T);
                    m     = GetMoonCoords(d, c, LDMNF, T);

                    phi   = Math.Acos(Math.Sin(s.dec) * Math.Sin(m.dec) + Math.Cos(s.dec) * Math.Cos(m.dec) * Math.Cos(s.ra - m.ra));
                    inc   = Math.Atan2(sdist * Math.Sin(phi), m.dist - sdist * Math.Cos(phi));
                    angle = Math.Atan2(Math.Cos(s.dec) * Math.Sin(s.ra - m.ra), Math.Sin(s.dec) * Math.Cos(m.dec) -
                                       Math.Cos(s.dec) * Math.Sin(m.dec) * Math.Cos(s.ra - m.ra));

                    double startPhase = 0.5 + 0.5 * inc * (angle < 0 ? -1 : 1) / Math.PI;

                    nDate = new DateTime(dMon.Year, dMon.Month, x, 23, 59, 59, DateTimeKind.Utc);
                    d     = JulianConversions.GetJulian_Epoch2000(nDate);
                    s     = GetSunCoords(d);
                    JDE   = JulianConversions.GetJulian(nDate); //Get julian
                    T     = (JDE - 2451545) / 36525;            //Get dynamic time.
                    LDMNF = Get_Moon_LDMNF(T);
                    m     = GetMoonCoords(d, c, LDMNF, T);

                    phi   = Math.Acos(Math.Sin(s.dec) * Math.Sin(m.dec) + Math.Cos(s.dec) * Math.Cos(m.dec) * Math.Cos(s.ra - m.ra));
                    inc   = Math.Atan2(sdist * Math.Sin(phi), m.dist - sdist * Math.Cos(phi));
                    angle = Math.Atan2(Math.Cos(s.dec) * Math.Sin(s.ra - m.ra), Math.Sin(s.dec) * Math.Cos(m.dec) -
                                       Math.Cos(s.dec) * Math.Sin(m.dec) * Math.Cos(s.ra - m.ra));

                    double endPhase = 0.5 + 0.5 * inc * (angle < 0 ? -1 : 1) / Math.PI;
                    //Determine Moon Name.
                    if (startPhase <= .5 && endPhase >= .5)
                    {
                        moonDate = x;
                        moonName = GetMoonName(dMon.Month, moonName);
                    }
                    //Get Moon Name (month, string);
                    //Get Moon Phase Name
                    if (date.Day == x)
                    {
                        if (startPhase > endPhase)
                        {
                            mi.PhaseName = "New Moon";
                            break;
                        }
                        if (startPhase <= .25 && endPhase >= .25)
                        {
                            mi.PhaseName = "First Quarter";
                            break;
                        }
                        if (startPhase <= .5 && endPhase >= .5)
                        {
                            mi.PhaseName = "Full Moon";
                            break;
                        }
                        if (startPhase <= .75 && endPhase >= .75)
                        {
                            mi.PhaseName = "Last Quarter";
                            break;
                        }

                        if (startPhase > 0 && startPhase < .25 && endPhase > 0 && endPhase < .25)
                        {
                            mi.PhaseName = "Waxing Crescent";
                            break;
                        }
                        if (startPhase > .25 && startPhase < .5 && endPhase > .25 && endPhase < .5)
                        {
                            mi.PhaseName = "Waxing Gibbous";
                            break;
                        }
                        if (startPhase > .5 && startPhase < .75 && endPhase > .5 && endPhase < .75)
                        {
                            mi.PhaseName = "Waning Gibbous";
                            break;
                        }
                        if (startPhase > .75 && startPhase < 1 && endPhase > .75 && endPhase < 1)
                        {
                            mi.PhaseName = "Waning Crescent";
                            break;
                        }
                    }
                }
                if (date.Day == moonDate)
                {
                    if (el.Extensions.Zodiac)
                    {
                        c.AstrologicalSigns.moonName = moonName;
                    }
                }
                else
                {
                    if (el.Extensions.Zodiac)
                    {
                        c.AstrologicalSigns.moonName = "";
                    }
                }
            }
            if (el.Extensions.Lunar_Eclipse)
            {
                CalculateLunarEclipse(date, lat, lng, c);
            }
        }