/// <summary> /// In place time slip /// </summary> /// <param name="c">Coordinate</param> /// <param name="offset">hour offset</param> private void Local_Convert(Coordinate c, double offset) { //Find new lunar set rise times if (MoonSet.HasValue) { moonSet = moonSet.Value.AddHours(offset); } if (MoonRise.HasValue) { moonRise = moonRise.Value.AddHours(offset); } //Perigee Perigee.ConvertTo_Local_Time(offset); //Apogee Apogee.ConvertTo_Local_Time(offset); //Eclipse LunarEclipse.ConvertTo_LocalTime(offset); ////Solar if (sunSet.HasValue) { sunSet = sunSet.Value.AddHours(offset); } if (SunRise.HasValue) { sunRise = SunRise.Value.AddHours(offset); } AdditionalSolarTimes.Convert_To_Local_Time(offset); //Eclipse SolarEclipse.ConvertTo_LocalTime(offset); SunCalc.CalculateZodiacSign(c.GeoDate.AddHours(offset), this); MoonCalc.GetMoonSign(c.GeoDate.AddHours(offset), this); }
/// <summary> /// Calculates all celestial data. Coordinates will notify as changes occur /// </summary> /// <param name="lat">Decimal format latitude</param> /// <param name="longi">Decimal format longitude</param> /// <param name="date">Geographic DateTime</param> /// <param name="el">EagerLoading Info for Auto-Calculations</param> internal void CalculateCelestialTime(double lat, double longi, DateTime date, EagerLoad el) { date = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, DateTimeKind.Utc); SunCalc.CalculateSunTime(lat, longi, date, this, el); if (el.Extensions.Lunar_Cycle) { MoonCalc.GetMoonTimes(date, lat, longi, this); MoonCalc.GetMoonDistance(date, this); perigee = MoonCalc.GetPerigeeEvents(date); apogee = MoonCalc.GetApogeeEvents(date); } MoonCalc.GetMoonIllumination(date, this, lat, longi, el); if (el.Extensions.Zodiac) { SunCalc.CalculateZodiacSign(date, this); MoonCalc.GetMoonSign(date, this); } Calculate_Celestial_IsUp_Booleans(date, this); }
/// <summary> /// Calculate sun data based on lat/long and date /// </summary> /// <param name="lat">Decimal format latitude</param> /// <param name="longi">Decimal format longitude</param> /// <param name="date">Geographic DateTime</param> /// <returns>Partially populated Celestial Object</returns> public static Celestial CalculateSunData(double lat, double longi, DateTime date) { Celestial c = new Celestial(false); SunCalc.CalculateSunTime(lat, longi, date, c); return(c); }
/// <summary> /// Calculate celestial data based on lat/long and date /// </summary> /// <param name="lat">Decimal format latitude</param> /// <param name="longi">Decimal format longitude</param> /// <param name="date">Geographic DateTime</param> /// <returns>Fully populated Celestial object</returns> public static Celestial CalculateCelestialTimes(double lat, double longi, DateTime date) { Celestial c = new Celestial(false); SunCalc.CalculateSunTime(lat, longi, date, c); MoonCalc.GetMoonTimes(date, lat, longi, c); MoonCalc.GetMoonIllumination(date, c); return(c); }
/// <summary> /// Calculates all celestial data. Coordinates will notify as changes occur /// </summary> /// <param name="lat">Decimal format latitude</param> /// <param name="longi">Decimal format longitude</param> /// <param name="date">Geographic DateTime</param> /// <param name="el">EagerLoading Info for Auto-Calculations</param> /// <param name="offset">UTC offset in hours</param> internal void CalculateCelestialTime(double lat, double longi, DateTime date, EagerLoad el, double offset) { if (offset < -12 || offset > 12) { throw new ArgumentOutOfRangeException("Time offsets cannot be greater than 12 or less than -12."); } date = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, DateTimeKind.Utc); if (el.Extensions.Solar_Cycle || el.Extensions.Solar_Eclipse) { SunCalc.CalculateSunTime(lat, longi, date, this, el, offset); } if (el.Extensions.Lunar_Cycle) { MoonCalc.GetMoonTimes(date, lat, longi, this, offset); MoonCalc.GetMoonDistance(date, this, offset); perigee = MoonCalc.GetPerigeeEvents(date); apogee = MoonCalc.GetApogeeEvents(date); //Shift perigee / apogee is working outside UTC if (offset != 0) { perigee.ConvertTo_Local_Time(offset); apogee.ConvertTo_Local_Time(offset); } } if (el.Extensions.Lunar_Cycle || el.Extensions.Zodiac || el.Extensions.Lunar_Eclipse) { MoonCalc.GetMoonIllumination(date, this, lat, longi, el, offset); } if (el.Extensions.Zodiac) { SunCalc.CalculateZodiacSign(date, this); MoonCalc.GetMoonSign(date, this); } if (el.Extensions.Lunar_Cycle || el.Extensions.Solar_Cycle) { Calculate_Celestial_IsUp_Booleans(date, this); } //Shift eclipses if eagerloaded and offset is not 0 if (el.Extensions.Lunar_Eclipse && offset != 0) { lunarEclipse.ConvertTo_LocalTime(offset); } if (el.Extensions.Solar_Eclipse && offset != 0) { solarEclipse.ConvertTo_LocalTime(offset); } }
/// <summary> /// Calculate sun data based on latitude, longitude and UTC date at the location. /// </summary> /// <param name="lat">latitude</param> /// <param name="longi">longitude</param> /// <param name="date">DateTime</param> /// <returns>Celestial (Partially Populated)</returns> /// <example> /// The following example demonstrates how to create a partially populated Celestial object /// that only calculates solar data using static functions. /// <code> /// //Get Celestial data at N 39, W 72 on 19-Mar-2019 10:10:12 UTC /// Celestial cel = Celestial.CalculateSunData(39, -72, new DateTime(2019, 3, 19, 10, 10, 12)); /// /// Console.WriteLine(cel.SunRise); //3/19/2019 10:54:50 AM /// </code> /// </example> public static Celestial CalculateSunData(double lat, double longi, DateTime date) { date = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, DateTimeKind.Utc); Celestial c = new Celestial(false); SunCalc.CalculateSunTime(lat, longi, date, c, new EagerLoad()); SunCalc.CalculateZodiacSign(date, c); return(c); }
/// <summary> /// Calculates all celestial data. Coordinates will notify as changes occur /// </summary> /// <param name="lat">Decimal format latitude</param> /// <param name="longi">Decimal format longitude</param> /// <param name="date">Geographic DateTime</param> internal void CalculateCelestialTime(double lat, double longi, DateTime date) { date = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, DateTimeKind.Utc); SunCalc.CalculateSunTime(lat, longi, date, this); MoonCalc.GetMoonTimes(date, lat, longi, this); MoonCalc.GetMoonDistance(date, this); SunCalc.CalculateZodiacSign(date, this); MoonCalc.GetMoonSign(date, this); MoonCalc.GetMoonIllumination(date, this, lat, longi); SunCalc.CalculateAdditionSolarTimes(date, longi, lat, this); }
/// <summary> /// Calculate celestial data based on lat/long and utc date /// </summary> /// <param name="lat">Decimal format latitude</param> /// <param name="longi">Decimal format longitude</param> /// <param name="date">Geographic DateTime</param> /// <returns>Fully populated Celestial object</returns> public static Celestial CalculateCelestialTimes(double lat, double longi, DateTime date) { date = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, DateTimeKind.Utc); Celestial c = new Celestial(false); SunCalc.CalculateSunTime(lat, longi, date, c); MoonCalc.GetMoonTimes(date, lat, longi, c); MoonCalc.GetMoonDistance(date, c); SunCalc.CalculateZodiacSign(date, c); MoonCalc.GetMoonSign(date, c); MoonCalc.GetMoonIllumination(date, c, lat, longi); SunCalc.CalculateAdditionSolarTimes(date, longi, lat, c); return(c); }
/// <summary> /// Calculate celestial data based on lat/long and date. /// </summary> /// <param name="lat">Decimal format latitude</param> /// <param name="longi">Decimal format longitude</param> /// <param name="date">Geographic DateTime</param> /// <returns>Fully populated Celestial object</returns> public static Celestial CalculateCelestialTimes(double lat, double longi, DateTime date) { date = new DateTime(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, DateTimeKind.Utc); Celestial c = new Celestial(false); SunCalc.CalculateSunTime(lat, longi, date, c); MoonCalc.GetMoonTimes(date, lat, longi, c); MoonCalc.GetMoonDistance(date, c); SunCalc.CalculateZodiacSign(date, c); MoonCalc.GetMoonSign(date, c); MoonCalc.GetMoonIllumination(date, c, lat, longi); c.perigee = MoonCalc.GetPerigeeEvents(date); c.apogee = MoonCalc.GetApogeeEvents(date); Calculate_Celestial_IsUp_Booleans(date, c); return(c); }
/// <summary> /// In place time slip /// </summary> /// <param name="c">Coordinate</param> /// <param name="offset">hour offset</param> /// <param name="el">Celestial EagerLoad Option</param> private void Local_Convert(Coordinate c, double offset, Celestial_EagerLoad el) { //Find new lunar set rise times if (el == Celestial_EagerLoad.All || el == Celestial_EagerLoad.Lunar) { if (MoonSet.HasValue) { moonSet = moonSet.Value.AddHours(offset); } if (MoonRise.HasValue) { moonRise = moonRise.Value.AddHours(offset); } Perigee.ConvertTo_Local_Time(offset); Apogee.ConvertTo_Local_Time(offset); LunarEclipse.ConvertTo_LocalTime(offset); MoonCalc.GetMoonSign(c.GeoDate.AddHours(offset), this); } ////Solar if (el == Celestial_EagerLoad.All || el == Celestial_EagerLoad.Solar) { if (sunSet.HasValue) { sunSet = sunSet.Value.AddHours(offset); } if (SunRise.HasValue) { sunRise = SunRise.Value.AddHours(offset); } AdditionalSolarTimes.Convert_To_Local_Time(offset); //Eclipse SolarEclipse.ConvertTo_LocalTime(offset); SunCalc.CalculateZodiacSign(c.GeoDate.AddHours(offset), this); } }
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); } }
/// <summary> /// Calculates all celestial data. Coordinates will notify as changes occur /// </summary> /// <param name="lat">Decimal format latitude</param> /// <param name="longi">Decimal format longitude</param> /// <param name="date">Geographic DateTime</param> public void CalculateCelestialTime(double lat, double longi, DateTime date) { SunCalc.CalculateSunTime(lat, longi, date, this); MoonCalc.GetMoonTimes(date, lat, longi, this); MoonCalc.GetMoonIllumination(date, this); }