コード例 #1
0
ファイル: SunCalculations.cs プロジェクト: Punchcards/Sphere
        public static SolarCoordinates Get_Solar_Coordinates(DateTime d, double offset)
        {
            double julianOffset = offset * .04166667;
            double JD           = JulianConversions.GetJulian(d) + julianOffset;
            double T            = (JD - 2451545.0) / 36525;                                   //25.1 Time
            double L0           = 280.46646 + 36000.76983 * T + .0003032 * Math.Pow(T, 2);    //25.2 Geometric Mean Longitude
            double M            = 357.52911 + 35999.05029 * T - .0001537 * Math.Pow(T, 2);    //25.3 Mean Anomaly
            double e            = .016708634 - .000042037 * T - .0000001267 * Math.Pow(T, 2); //25.4 Eccentricity
            double C            = +(1.914602 - .004817 * T - .000014 * Math.Pow(T, 2)) * Math.Sin(M.ToRadians()) +
                                  (.019993 - .000101 * T) * Math.Sin(2 * M.ToRadians()) +
                                  .000289 * Math.Sin(3 * M.ToRadians());                                   //25.4 Equation of the center

            double trueLongitude = L0 + C;                                                                 //25.4
            double trueAnomaly   = M + C;                                                                  //25.4 "v"

            double R = (1.000001018 * (1 - Math.Pow(e, 2))) / (1 + e * Math.Cos(trueAnomaly.ToRadians())); //25.5 Radius Vector

            double ascendingNode     = 125.04 - 1934.136 * T;
            double apparentLongitude = trueLongitude - .00569 - .00478 * Math.Sin(ascendingNode.ToRadians());

            double E = Format.ToDegrees(23, 26, 21.488) - (46.8150 / 3600) * T - (.00059 / 3600) * Math.Pow(T, 2) + (.001813 / 3600) * Math.Pow(T, 3); //22.2 Obliquity of the ecliptic

            double tra = Math.Atan2(Math.Cos(E.ToRadians()) * Math.Sin(trueLongitude.ToRadians()), Math.Cos(trueLongitude.ToRadians()));               //25.6 True Right Ascensions. Using Atan2 we can move tan to the right side of the function with Numerator, Denominator

            double tdec = Math.Asin(Math.Sin(E.ToRadians()) * Math.Sin(trueLongitude.ToRadians()));                                                    //25.7 True declination. Asin used in liu of sin.

            double CE = E + .00256 * Math.Cos(ascendingNode.ToRadians());                                                                              //22.2 Obliquity of the ecliptic

            double ara  = Math.Atan2(Math.Cos(CE.ToRadians()) * Math.Sin(apparentLongitude.ToRadians()), Math.Cos(apparentLongitude.ToRadians()));     //25.8 Apparent Right Ascensions. Using Atan2 we can move tan to the right side of the function with Numerator, Denominator
            double adec = Math.Asin(Math.Sin(CE.ToRadians()) * Math.Sin(apparentLongitude.ToRadians()));                                               //25.8 Apparent declination. Asin used in liu of sin.

            SolarCoordinates celC = new SolarCoordinates();

            //Set to degrees
            //celC.trueRightAscension = tra.ToDegrees();
            //celC.trueDeclination = tdec.ToDegrees();
            celC.rightAscension         = ara.ToDegrees().NormalizeDegrees360();
            celC.declination            = adec.ToDegrees();
            celC.julianDayDecimal       = JD - .5 - Math.Floor(JD - .5);
            celC.trueLongitude          = trueLongitude.NormalizeDegrees360();
            celC.longitude              = apparentLongitude.NormalizeDegrees360();
            celC.radiusVector           = R;
            celC.geometricMeanLongitude = L0.NormalizeDegrees360();
            //Latitude is always 0 for sun as perturbations no accounted for in low accuracy formulas
            celC.latitude     = 0;
            celC.trueLatitude = 0;

            return(celC);
        }
コード例 #2
0
ファイル: SunCalculations.cs プロジェクト: Punchcards/Sphere
        public static double[] CalculateSunAngle(DateTime date, double longi, double lat, SolarCoordinates solC)
        {
            TimeSpan ts  = date - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            double   dms = (ts.TotalMilliseconds / dayMS - .5 + j1970) - j2000;

            double lw  = rad * -longi;
            double phi = rad * lat;
            double e   = rad * 23.4397;

            double H = SideRealTime(dms, lw) - solC.rightAscension.ToRadians();

            double azimuth  = Math.Atan2(Math.Sin(H), Math.Cos(H) * Math.Sin(phi) - Math.Tan(solC.declination.ToRadians()) * Math.Cos(phi)) * 180 / Math.PI + 180;
            double altitude = Math.Asin(Math.Sin(phi) * Math.Sin(solC.declination.ToRadians()) + Math.Cos(phi) * Math.Cos(solC.declination.ToRadians()) * Math.Cos(H)) * 180 / Math.PI;

            return(new double[] { azimuth, altitude });
        }
コード例 #3
0
ファイル: SunCalculations.cs プロジェクト: Punchcards/Sphere
        private static void CalculateSunAngle(DateTime date, double longi, double lat, Celestial c, SolarCoordinates solC)
        {
            double[] ang = CalculateSunAngle(date, longi, lat, solC);

            c.sunAzimuth  = ang[0];
            c.sunAltitude = ang[1];
        }
コード例 #4
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);
            }
        }