Exemplo n.º 1
0
        public static JulianDay FindPhase(int year, int month, int day, MoonPhases phase)
        {
            var jd = new JulianDay(year, month, day);
            double length = 365;
            if (jd.IsLeapYear)
            { length = 366; }

            double Y = Math.Round(year + ((double)jd.DayOfYear / length), 2);
            double k = ((Y - 2000) * 12.3685);

            switch (phase)
            {
                case MoonPhases.New:
                    k = Math.Round(k);
                    break;
                case MoonPhases.FirstQuarter:
                    if (k < 0)
                    { k = Math.Round(k) - 0.25; }
                    else
                    { k = Math.Floor(k) + 0.25; }
                    break;
                case MoonPhases.Full:
                    if (k < 0)
                    { k = Math.Round(k) - 0.50; }
                    else
                    { k = Math.Floor(k) + 0.50; }
                    break;
                case MoonPhases.LastQuarter:
                    if (k < 0)
                    { k = Math.Round(k) - 0.75; }
                    else
                    { k = Math.Floor(k) + 0.75; }
                    break;
            }

            Debug.WriteLine("k\t=\t" + Math.Round(k, 2));

            double T = k / 1236.85;
            double T2 = Math.Pow(T, 2);
            double T3 = Math.Pow(T, 3);
            double T4 = Math.Pow(T, 4);

            Debug.WriteLine("T\t=\t" + Math.Round(T, 5));

            double JDE = 2451550.09766 + 29.530588861 * k
            + 0.00015437 * T2
            - 0.000000150 * T3
            + 0.00000000073 * T4;

            Debug.WriteLine("JDE\t=\t" + Math.Round(JDE, 5));

            //Corrections

            double E = 1 - 0.002516 * T - 0.0000074 * T2;

            double M = 2.5534 + 29.10535670 * k
                        - 0.0000014 * T2
                        - 0.00000011 * T3;

            Debug.Write("M\t=\t" + Math.Round(M, 4));
            M = AstroMath.Mod(M, 360);
            Debug.WriteLine("\t=\t" + Math.Round(M, 4));

            double Mp = 201.5643 + (385.81693528 * k)
                        + (0.0107582 * T2)
                        + (0.00001238 * T3)
                        - (0.000000058 * T4);

            Debug.Write("M′\t=\t" + Math.Round(Mp, 4));
            Mp = AstroMath.Mod(Mp, 360);
            Debug.WriteLine("\t=\t" + Math.Round(Mp, 4));

            double F = 160.7180 + 390.67050284 * k
                        - 0.0016118 * T2
                        - 0.00000227 * T3
                        + 0.000000011 * T4;

            Debug.Write("F\t=\t" + Math.Round(F, 4));
            F = AstroMath.Mod(F, 360);
            Debug.WriteLine("\t=\t" + Math.Round(F, 4));

            double Ω = 124.7746 - (1.56375588 * k)
                        + (0.0020672 * T2)
                        + (0.00000215 * T3);

            Debug.Write("Ω\t=\t" + Math.Round(Ω, 4));
            Ω = AstroMath.Mod(Ω, 360);
            Debug.WriteLine("\t=\t" + Math.Round(Ω, 4));

            double correction = 0;
            //switch (phase)
            //{
            //    case MoonPhases.Full:
            //        correction = FullMoonCorrections(E, M, Mp, F, Ω);
            //        break;
            //}

            //PlanetaryArguments
            double additionalCorrection = 0;
            for (int i = 0; i <= 13; i++)
            {
                IList<double> S = PlanetaryArguments[i];
                additionalCorrection += AdditionalCorrections[i] * AstroMath.Sin(S[0] + (S[1] * k) - (S[2] * T2));
            }

            Debug.WriteLine("Additional Corrections:\t" + Math.Round(additionalCorrection, 5));
            JDE = JDE + correction + additionalCorrection;

            return new JulianDay(JDE);
        }
Exemplo n.º 2
0
        public static IslamicCalendar FromJulianDay(JulianDay JD)
        {
            int X = JD.Year;
            int M = JD.Month;
            int D = JD.Day;
            if (M < 3)
            {
                X = X - 1;
                M = M + 12;
            }

            int α = AstroMath.Int(X / 100);
            int β = 2 - α + AstroMath.Int(α / 4);

            int b = AstroMath.Int(365.25 * X) + AstroMath.Int(30.6001 * (M + 1)) + D + 1722519 + β;
            int c = AstroMath.Int((b - 122.1) / 365.25);
            int d = AstroMath.Int(365.25 * c);
            int e = AstroMath.Int((b - d) / 30.6001);

            D = b - d - AstroMath.Int(30.6001 * e);
            if (e < 14)
            { M = e - 1; }
            else
            { M = e - 13; }

            X = c - 4716;

            int W = 2;
            if (X % 4 == 0)
            { W = 1; }
            int N = AstroMath.Int((275 * M) / 9) - W * AstroMath.Int((M + 9) / 12) + D - 30;
            int A = X - 623;
            int B = AstroMath.Int(A / 4);
            int C = A % 4;
            double C1 = 365.2501 * C;
            int C2 = AstroMath.Int(C1);

            if (C1 - C2 > 0.5)
            { C2 = C2 + 1; }

            int D1 = (1461 * B) + 170 + C2;

            int Q = AstroMath.Int(D1 / 10631);
            int R = D1 % 10631;
            int J = AstroMath.Int(R / 354);
            int K = R % 354;

            int O = AstroMath.Int(((11 * J) + 14) / 30);

            int H = (30 * Q) + J + 1;
            int JJ = K - O + N - 1;

            int CL = H % 30;
            int DL = ((11 * CL) + 3) % 30;
            if (DL < 19)
            {
                JJ = JJ - 354;
                H = H + 1;
            }

            if (DL > 18)
            {
                JJ = JJ - 355;
                H = H + 1;
            }

            int S = AstroMath.Int((JJ - 1) / 29.5);

            int m = 1 + S;
            d = AstroMath.Int(JJ - (29.5 * S));

            if (JJ == 355)
            {
                m = 12;
                d = 30;
            }

            return new IslamicCalendar(H, m, d);
        }
Exemplo n.º 3
0
        public static JulianDay FindPhase(int year, int month, int day, MoonPhases phase)
        {
            var    jd     = new JulianDay(year, month, day);
            double length = 365;

            if (jd.IsLeapYear)
            {
                length = 366;
            }

            double Y = Math.Round(year + ((double)jd.DayOfYear / length), 2);
            double k = ((Y - 2000) * 12.3685);

            switch (phase)
            {
            case MoonPhases.New:
                k = Math.Round(k);
                break;

            case MoonPhases.FirstQuarter:
                if (k < 0)
                {
                    k = Math.Round(k) - 0.25;
                }
                else
                {
                    k = Math.Floor(k) + 0.25;
                }
                break;

            case MoonPhases.Full:
                if (k < 0)
                {
                    k = Math.Round(k) - 0.50;
                }
                else
                {
                    k = Math.Floor(k) + 0.50;
                }
                break;

            case MoonPhases.LastQuarter:
                if (k < 0)
                {
                    k = Math.Round(k) - 0.75;
                }
                else
                {
                    k = Math.Floor(k) + 0.75;
                }
                break;
            }

            Debug.WriteLine("k\t=\t" + Math.Round(k, 2));

            double T  = k / 1236.85;
            double T2 = Math.Pow(T, 2);
            double T3 = Math.Pow(T, 3);
            double T4 = Math.Pow(T, 4);

            Debug.WriteLine("T\t=\t" + Math.Round(T, 5));

            double JDE = 2451550.09766 + 29.530588861 * k
                         + 0.00015437 * T2
                         - 0.000000150 * T3
                         + 0.00000000073 * T4;

            Debug.WriteLine("JDE\t=\t" + Math.Round(JDE, 5));

            //Corrections

            double E = 1 - 0.002516 * T - 0.0000074 * T2;

            double M = 2.5534 + 29.10535670 * k
                       - 0.0000014 * T2
                       - 0.00000011 * T3;

            Debug.Write("M\t=\t" + Math.Round(M, 4));
            M = AstroMath.Mod(M, 360);
            Debug.WriteLine("\t=\t" + Math.Round(M, 4));

            double Mp = 201.5643 + (385.81693528 * k)
                        + (0.0107582 * T2)
                        + (0.00001238 * T3)
                        - (0.000000058 * T4);


            Debug.Write("M′\t=\t" + Math.Round(Mp, 4));
            Mp = AstroMath.Mod(Mp, 360);
            Debug.WriteLine("\t=\t" + Math.Round(Mp, 4));

            double F = 160.7180 + 390.67050284 * k
                       - 0.0016118 * T2
                       - 0.00000227 * T3
                       + 0.000000011 * T4;

            Debug.Write("F\t=\t" + Math.Round(F, 4));
            F = AstroMath.Mod(F, 360);
            Debug.WriteLine("\t=\t" + Math.Round(F, 4));

            double Ω = 124.7746 - (1.56375588 * k)
                       + (0.0020672 * T2)
                       + (0.00000215 * T3);

            Debug.Write("Ω\t=\t" + Math.Round(Ω, 4));
            Ω = AstroMath.Mod(Ω, 360);
            Debug.WriteLine("\t=\t" + Math.Round(Ω, 4));

            double correction = 0;
            //switch (phase)
            //{
            //    case MoonPhases.Full:
            //        correction = FullMoonCorrections(E, M, Mp, F, Ω);
            //        break;
            //}

            //PlanetaryArguments
            double additionalCorrection = 0;

            for (int i = 0; i <= 13; i++)
            {
                IList <double> S = PlanetaryArguments[i];
                additionalCorrection += AdditionalCorrections[i] * AstroMath.Sin(S[0] + (S[1] * k) - (S[2] * T2));
            }

            Debug.WriteLine("Additional Corrections:\t" + Math.Round(additionalCorrection, 5));
            JDE = JDE + correction + additionalCorrection;

            return(new JulianDay(JDE));
        }
Exemplo n.º 4
0
        public static IslamicCalendar FromJulianDay(JulianDay JD)
        {
            int X = JD.Year;
            int M = JD.Month;
            int D = JD.Day;

            if (M < 3)
            {
                X = X - 1;
                M = M + 12;
            }

            int α = AstroMath.Int(X / 100);
            int β = 2 - α + AstroMath.Int(α / 4);

            int b = AstroMath.Int(365.25 * X) + AstroMath.Int(30.6001 * (M + 1)) + D + 1722519 + β;
            int c = AstroMath.Int((b - 122.1) / 365.25);
            int d = AstroMath.Int(365.25 * c);
            int e = AstroMath.Int((b - d) / 30.6001);

            D = b - d - AstroMath.Int(30.6001 * e);
            if (e < 14)
            {
                M = e - 1;
            }
            else
            {
                M = e - 13;
            }

            X = c - 4716;

            int W = 2;

            if (X % 4 == 0)
            {
                W = 1;
            }
            int    N  = AstroMath.Int((275 * M) / 9) - W * AstroMath.Int((M + 9) / 12) + D - 30;
            int    A  = X - 623;
            int    B  = AstroMath.Int(A / 4);
            int    C  = A % 4;
            double C1 = 365.2501 * C;
            int    C2 = AstroMath.Int(C1);

            if (C1 - C2 > 0.5)
            {
                C2 = C2 + 1;
            }

            int D1 = (1461 * B) + 170 + C2;

            int Q = AstroMath.Int(D1 / 10631);
            int R = D1 % 10631;
            int J = AstroMath.Int(R / 354);
            int K = R % 354;

            int O = AstroMath.Int(((11 * J) + 14) / 30);

            int H  = (30 * Q) + J + 1;
            int JJ = K - O + N - 1;


            int CL = H % 30;
            int DL = ((11 * CL) + 3) % 30;

            if (DL < 19)
            {
                JJ = JJ - 354;
                H  = H + 1;
            }

            if (DL > 18)
            {
                JJ = JJ - 355;
                H  = H + 1;
            }

            int S = AstroMath.Int((JJ - 1) / 29.5);

            int m = 1 + S;

            d = AstroMath.Int(JJ - (29.5 * S));

            if (JJ == 355)
            {
                m = 12;
                d = 30;
            }

            return(new IslamicCalendar(H, m, d));
        }