Beispiel #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);
        }
Beispiel #2
0
        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   = 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)
            {
                c.AstrologicalSigns.MoonName = moonName;
            }
            else
            {
                c.AstrologicalSigns.MoonName = "";
            }
            CalculateLunarEclipse(date, lat, lng, c);
        }