public static Apogee GetApogeeEvents(DateTime d) { //Iterate in 5 month increments due to formula variations. //Determine closest events to date. //apo1 is last date //apo2 is next date //integrity for new date. if (d.Year <= 0001) { return(new Apogee(new PerigeeApogee(new DateTime(), 0, new Distance(0)), new PerigeeApogee(new DateTime(), 0, new Distance(0)))); } PerigeeApogee apo1 = MoonPerigeeOrApogee(d.AddDays(-45), MoonDistanceType.Apogee); PerigeeApogee apo2 = MoonPerigeeOrApogee(d.AddDays(-45), MoonDistanceType.Apogee); for (int x = -30; x <= 45; x += 15) { PerigeeApogee t = MoonPerigeeOrApogee(d.AddDays(x), MoonDistanceType.Apogee); //Find next apogee after specified date if (t.Date > apo2.Date && t.Date >= d) { apo2 = t; break; } //Find last apogee before specified date if (t.Date > apo1.Date && t.Date < d) { apo1 = t; apo2 = t; } } return(new Apogee(apo1, apo2)); }
private PerigeeApogee Get_Correct_Slipped_Date(PerigeeApogee actual, PerigeeApogee pre, PerigeeApogee post, int i) { switch (i) { case 0: return(pre); case 1: return(actual); case 2: return(post); default: return(actual); } }
public static Perigee GetPerigeeEvents(DateTime d) { //Iterate in 15 day increments due to formula variations. //Determine closest events to date. //per1 is last date //per2 is next date //integrity for new date. if (d.Year <= 0001) { return(new Perigee(new PerigeeApogee(new DateTime(), 0, new Distance(0)), new PerigeeApogee(new DateTime(), 0, new Distance(0)))); } //Start at lowest increment PerigeeApogee per1 = MoonPerigeeOrApogee(d.AddDays(-45), MoonDistanceType.Perigee); PerigeeApogee per2 = MoonPerigeeOrApogee(d.AddDays(-45), MoonDistanceType.Perigee); for (int x = -30; x <= 45; x += 15) { //used for comparison PerigeeApogee t = MoonPerigeeOrApogee(d.AddDays(x), MoonDistanceType.Perigee); //Find the next pergiee after specified date if (t.Date > per2.Date && t.Date >= d) { per2 = t; break; } //Find last perigee before specified date if (t.Date > per1.Date && t.Date < d) { per1 = t; per2 = t; } } return(new Perigee(per1, per2)); }
//v1.1.3 Formulas //The following formulas are either additions //or conversions of SunCalcs formulas into Meeus /// <summary> /// Grabs Perigee or Apogee of Moon based on specified time. /// Results will return event just before, or just after specified DateTime /// </summary> /// <param name="d">DateTime</param> /// <param name="md">Event Type</param> /// <returns>PerigeeApogee</returns> private static PerigeeApogee MoonPerigeeOrApogee(DateTime d, MoonDistanceType md) { //Perigee & Apogee Algorithms from Jean Meeus Astronomical Algorithms Ch. 50 //50.1 //JDE = 2451534.6698 + 27.55454989 * k // -0.0006691 * Math.Pow(T,2) // -0.000.01098 * Math.Pow(T,3) // -0.0000000052 * Math.Pow(T,4) //50.2 //K approx = (yv - 1999.97)*13.2555 //yv is the year + percentage of days that have occured in the year. 1998 Oct 1 is approx 1998.75 //k ending in .0 represent perigee and .5 apogee. Anything > .5 is an error. //50.3 //T = k/1325.55 double yt = 365; //days in year if (DateTime.IsLeapYear(d.Year)) { yt = 366; } //days in year if leap year double f = d.DayOfYear / yt; //Get percentage of year that as passed double yv = d.Year + f; //add percentage of year passed to year. double k = (yv - 1999.97) * 13.2555; //find approximate k using formula 50.2 //Set k decimal based on apogee or perigee if (md == MoonDistanceType.Apogee) { k = Math.Floor(k) + .5; } else { k = Math.Floor(k); } //Find T using formula 50.3 double T = k / 1325.55; //Find JDE using formula 50.1 double JDE = 2451534.6698 + 27.55454989 * k - 0.0006691 * Math.Pow(T, 2) - 0.00001098 * Math.Pow(T, 3) - 0.0000000052 * Math.Pow(T, 4); //Find Moon's mean elongation at time JDE. double D = 171.9179 + 335.9106046 * k - 0.0100383 * Math.Pow(T, 2) - 0.00001156 * Math.Pow(T, 3) + 0.000000055 * Math.Pow(T, 4); //Find Sun's mean anomaly at time JDE double M = 347.3477 + 27.1577721 * k - 0.0008130 * Math.Pow(T, 2) - 0.0000010 * Math.Pow(T, 3); //Find Moon's argument of latitude at Time JDE double F = 316.6109 + 364.5287911 * k - 0.0125053 * Math.Pow(T, 2) - 0.0000148 * Math.Pow(T, 3); //Normalize DMF to a 0-360 degree number D %= 360; if (D < 0) { D += 360; } M %= 360; if (M < 0) { M += 360; } F %= 360; if (F < 0) { F += 360; } //Convert DMF to radians D = D * Math.PI / 180; M = M * Math.PI / 180; F = F * Math.PI / 180; double termsA; //Find Terms A from Table 50.A if (md == MoonDistanceType.Apogee) { termsA = MeeusTables.ApogeeTermsA(D, M, F, T); } else { termsA = MeeusTables.PerigeeTermsA(D, M, F, T); } JDE += termsA; double termsB; if (md == MoonDistanceType.Apogee) { termsB = MeeusTables.ApogeeTermsB(D, M, F, T); } else { termsB = MeeusTables.PerigeeTermsB(D, M, F, T); } //Convert julian back to date DateTime date = JulianConversions.GetDate_FromJulian(JDE).Value; //Obtain distance Distance dist = GetMoonDistance(date); PerigeeApogee ap = new PerigeeApogee(date, termsB, dist); return(ap); }
/// <summary> /// Initializes an Apogee object. /// </summary> /// <param name="last"></param> /// <param name="next"></param> public Apogee(PerigeeApogee last, PerigeeApogee next) { lastApogee = last; nextApogee = next; }