public JulianDay ToJulianDay() { int N = this.Day + AstroMath.Int(29.5001 * (this.Month - 1) + 0.99); int Q = AstroMath.Int(this.Year / 30); int R = this.Year % 30; int A = AstroMath.Int(((11 * R) + 3) / 30); int W = (404 * Q) + (354 * R) + 208 + A; int Q1 = AstroMath.Int(W / 1461); int Q2 = W % 1461; int G = 621 + 4 * (AstroMath.Int((7 * Q) + Q1)); int K = AstroMath.Int(Q2 / 365.2422); int E = AstroMath.Int(365.2422 * K); int J = Q2 - E + N - 1; int X = G + K; if ((J > 366) && (X % 4 == 0)) { J = J - 366; X = X + 1; } if ((J > 354) && (X % 4 > 0)) { J = J - 365; X = X + 1; } double JD = AstroMath.Int(365.25 * (X - 1)) + 1721423 + J; return(new JulianDay(JD)); }
public static JulianDay Pesach(int Year) { if (Year < -3761) { throw new ArgumentOutOfRangeException("Year", "The Hebrew Calendar is not valid prior to 3761 BCE"); } int X = Year; int month = 3; int C = AstroMath.Int(X / 100); int S = AstroMath.Int((C * 3 - 5) / 4); int A = X + 3760; int a = AstroMath.Mod(X * 12 + 12, 19); int b = AstroMath.Mod(X, 4); if (X < 1583) { S = 0; } double Q = -1.904412361576 + 1.554241796621 * a + 0.25 * b - 0.003177784022 * X + S; int j = AstroMath.Mod(AstroMath.Int(Q) + 3 * X + 5 * b + 2 - S, 7); double r = Q - AstroMath.Int(Q); int D; if (j == 2 || j == 4 || j == 6) { D = AstroMath.Int(Q) + 23; } else if (j == 1 && a > 6 && r >= 0.632870370) { D = AstroMath.Int(Q) + 24; } else if (j == 0 && a > 11 && r >= 0.897723765) { D = AstroMath.Int(Q) + 23; } else { D = AstroMath.Int(Q) + 22; } if (D > 31) { month = month + 1; D = D - 31; } /* Debug information */ Debug.WriteLine("X\t= " + X); Debug.WriteLine("C\t= " + C); Debug.WriteLine("S\t= " + S); Debug.WriteLine("A\t= " + A); Debug.WriteLine("a\t= " + a); Debug.WriteLine("b\t= " + b); Debug.WriteLine("Q\t= " + Q); Debug.WriteLine("j\t= " + j); Debug.WriteLine("r\t= " + r); Debug.WriteLine("D\t= " + D); return(new JulianDay(Year, month, D)); }
public static double Approximate(int year, Season season) { double JDE0; double T; double W; double Δλ; double S; double JDE; JDE0 = Mean(year, season); Debug.WriteLine("Calculating Approximate Equinox/Solstice for " + season + ", " + year + " from JDE0"); T = (JDE0 - 2451545.0) / 36525; T = Math.Round(T, 9); W = 35999.373 * T - 2.47; Δλ = 1 + 0.0334 * AstroMath.Cos(W) + 0.0007 * AstroMath.Cos(2 * W); S = 0; /* S = Σ[A Cos(B + (C * T))] */ foreach (List <double> s in TableC) { S += s[0] * AstroMath.Cos(s[1] + (s[2] * T)); } S = Math.Floor(S); JDE = Math.Round(JDE0 + ((0.00001 * S) / Δλ), 5); /* Debug information */ Debug.WriteLine("T\t= " + T); Debug.WriteLine("W\t= " + W); Debug.WriteLine("Δλ\t= " + Δλ); Debug.WriteLine("S\t= " + S); Debug.WriteLine("JDE\t= " + JDE); return(JDE); }
public override int GetHashCode() { return(AstroMath.Int(this.JulianDayNumber)); }
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)); }
private static double Correction(double Term1, double Term2) { return(Term1 * AstroMath.Sin(Term2)); }
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)); }