Exemplo n.º 1
0
        private static LunarCoordinates GetMoonCoords(double[] LDMNF, double t, double JD)
        {
            LunarCoordinates cel = new LunarCoordinates();

            // 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



            double geocentricLongitude = l.ToDegrees();

            cel.julianDayDecimal       = JD - .5 - Math.Floor(JD - .5);
            cel.latitude               = b.ToDegrees();
            cel.rightAscension         = RightAscension(l, b).ToDegrees().NormalizeDegrees360();
            cel.declination            = Declination(l, b).ToDegrees();
            cel.geometricMeanLongitude = LDMNF[0].NormalizeDegrees360();



            //APPARENTS
            //Get longitutde of the acsencing node of the moon's mean orbit on the ecliptic, measure from the mean equinox of the date
            double lngAscendingNode = 125.04452 - 1934.136261 * t;
            double la = lngAscendingNode.ToRadians();

            //Mean Longitudes
            double sunL  = 280.4665 + 36000.7698 * t;
            double moonL = 218.3165 + 481267.8813 * t;

            cel.sunMeanLongitude = sunL.NormalizeDegrees360();
            //nutations in longitude
            double lngNutation = (-17.20).ToSeconds() * Math.Sin(la) - (1.32).ToSeconds() * Math.Sin(2 * sunL) - (.23).ToSeconds() * Math.Sin(2 * moonL) + (.21).ToSeconds() * Math.Sin(2 * la);

            cel.longitude = geocentricLongitude + lngNutation;

            ////nutations in obliquity
            //double obNutation = (9.20).ToSeconds() * Math.Cos(la) + (.57).ToSeconds() * Math.Cos(2 * sunL) + (.10).ToSeconds() * Math.Cos(2 * moonL) - (.09).ToSeconds() * Math.Cos(2 * la);

            ////Obliquity of the ecliptic 22.2 (MAY NEED TO SWITCH TO 22.3 in future as it is higher accuracy)
            //double U = t / 100;
            //double E0 = Format.ToDegrees(23, 23, 21.488) - (46.8150).ToSeconds() * t - (.00059).ToSeconds() * Math.Pow(t, 2) + (.001813).ToSeconds() * Math.Pow(t, 3);
            //double E = E0 + obNutation; //true Obliquity


            return(cel);
        }
Exemplo n.º 2
0
        public static void GetMoonIllumination(DateTime date, Celestial c, double lat, double lng, EagerLoad el, double offset)
        {
            //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);
                offset *= -1;
                double julianOffset = offset * .04166667;

                SolarCoordinates s     = SunCalc.Get_Solar_Coordinates(date, offset);
                double           JDE   = JulianConversions.GetJulian(date) + julianOffset; //Get julian
                double           T     = (JDE - 2451545) / 36525;                          //Get dynamic time.
                double[]         LDMNF = Get_Moon_LDMNF(T);

                LunarCoordinates m = GetMoonCoords(LDMNF, T, JDE);

                double sdist = 149598000,
                       phi   = Math.Acos(Math.Sin(s.declination.ToRadians()) * Math.Sin(m.declination.ToRadians()) + Math.Cos(s.declination.ToRadians()) * Math.Cos(m.declination.ToRadians()) * Math.Cos(s.rightAscension.ToRadians() - m.rightAscension.ToRadians())),
                       inc   = Math.Atan2(sdist * Math.Sin(phi), 0 - sdist * Math.Cos(phi)),
                       angle = Math.Atan2(Math.Cos(s.declination.ToRadians()) * Math.Sin(s.rightAscension.ToRadians() - m.rightAscension.ToRadians()), Math.Sin(s.declination.ToRadians()) * Math.Cos(m.declination.ToRadians()) -
                                          Math.Cos(s.declination.ToRadians()) * Math.Sin(m.declination.ToRadians()) * Math.Cos(s.rightAscension.ToRadians() - m.rightAscension.ToRadians()));


                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);

                    s     = SunCalc.Get_Solar_Coordinates(date, offset);
                    JDE   = JulianConversions.GetJulian(nDate) + julianOffset; //Get julian
                    T     = (JDE - 2451545) / 36525;                           //Get dynamic time.
                    LDMNF = Get_Moon_LDMNF(T);
                    m     = GetMoonCoords(LDMNF, T, JDE);

                    phi   = Math.Acos(Math.Sin(s.declination.ToRadians()) * Math.Sin(m.declination.ToRadians()) + Math.Cos(s.declination.ToRadians()) * Math.Cos(m.declination.ToRadians()) * Math.Cos(s.rightAscension.ToRadians() - m.rightAscension.ToRadians()));
                    inc   = Math.Atan2(sdist * Math.Sin(phi), 0 - sdist * Math.Cos(phi));
                    angle = Math.Atan2(Math.Cos(s.declination.ToRadians()) * Math.Sin(s.rightAscension.ToRadians() - m.rightAscension.ToRadians()), Math.Sin(s.declination.ToRadians()) * Math.Cos(m.declination.ToRadians()) -
                                       Math.Cos(s.declination.ToRadians()) * Math.Sin(m.declination.ToRadians()) * Math.Cos(s.rightAscension.ToRadians() - m.rightAscension.ToRadians()));

                    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);

                    s     = SunCalc.Get_Solar_Coordinates(date, offset);
                    JDE   = JulianConversions.GetJulian(nDate) + julianOffset; //Get julian
                    T     = (JDE - 2451545) / 36525;                           //Get dynamic time.
                    LDMNF = Get_Moon_LDMNF(T);
                    m     = GetMoonCoords(LDMNF, T, JDE);

                    phi   = Math.Acos(Math.Sin(s.declination.ToRadians()) * Math.Sin(m.declination.ToRadians()) + Math.Cos(s.declination.ToRadians()) * Math.Cos(m.declination.ToRadians()) * Math.Cos(s.rightAscension.ToRadians() - m.rightAscension.ToRadians()));
                    inc   = Math.Atan2(sdist * Math.Sin(phi), 0 - sdist * Math.Cos(phi));
                    angle = Math.Atan2(Math.Cos(s.declination.ToRadians()) * Math.Sin(s.rightAscension.ToRadians() - m.rightAscension.ToRadians()), Math.Sin(s.declination.ToRadians()) * Math.Cos(m.declination.ToRadians()) -
                                       Math.Cos(s.declination.ToRadians()) * Math.Sin(m.declination.ToRadians()) * Math.Cos(s.rightAscension.ToRadians() - m.rightAscension.ToRadians()));

                    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);
            }
        }
Exemplo n.º 3
0
        private static MoonPosition GetMoonPosition(DateTime date, double lat, double lng, Celestial cel, double offset, bool setCelC)
        {
            //Set UTC date integrity
            date = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, DateTimeKind.Utc);

            double julianOffset = offset * .04166667;

            //Ch 47
            double JDE  = JulianConversions.GetJulian(date);                //Get julian
            double oJDE = JulianConversions.GetJulian(date) + julianOffset; //Get julian
            double T    = (oJDE - 2451545) / 36525;                         //Get dynamic time.

            double[]         LDMNF = Get_Moon_LDMNF(T);
            LunarCoordinates celC  = GetMoonCoords(LDMNF, T, oJDE);

            if (setCelC)
            {
                cel.lunarCoordinates = celC;
            }
            Distance dist = GetMoonDistance(date.AddHours(offset));
            double   lw   = rad * -lng;
            double   phi  = rad * lat;

            double H = rad * MeeusFormulas.Get_Sidereal_Time(oJDE) - lw - celC.rightAscension.ToRadians();

            double ra  = celC.rightAscension.ToRadians(); //Adjust current RA formula to avoid needless RAD conversions
            double dec = celC.declination.ToRadians();    //Adjust current RA formula to avoid needless RAD conversions

            //Adjust for parallax (low accuracy 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);
            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 += 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);
        }