/// <summary> /// return Nearest (30 days period) FullMoon Date and NewMoon Date /// </summary> /// <returns>Full Moon Date and New Moon Date</returns> public static Tuple <DateTime, DateTime> GetFullNewMoonDate(DateTime date, double latitude, double longitude, TimeZoneInfo timezone) { //go to the night 00:00 DateTime new_date = new DateTime(date.Year, date.Month, date.Day, 0, 0, 0); Sun sun = new Sun(new_date, latitude, longitude, timezone); Moon moon = new Moon(new_date, latitude, longitude, timezone); double illumination = GetMoonPhase(moon, sun); //FULL MOON DateTime fullmoon_date = new_date.AddHours((1.0 + illumination) * Moonmonth_hourcount / 2); //NEW MOON DateTime newmoon_date; if (illumination < 0) { newmoon_date = new_date.AddHours((2.0 + illumination) * Moonmonth_hourcount / 2); } else { newmoon_date = new_date.AddHours((illumination) * Moonmonth_hourcount / 2); } return(new Tuple <DateTime, DateTime>(fullmoon_date, newmoon_date)); }
public static string GetMoonXml(Moon moon, Sun sun) { double illumination = Astro.GetMoonPhase(moon, sun); var result = Astro.GetMoonPhase(illumination); return(@" <tile> <visual branding='nameAndLogo' displayName='" + App.res.GetString("Moon") + @"'> <binding template = 'TileSmall' > <image src='Assets\tile-bg.png' placement='background'/> <image src = '" + result.Item2 + @"' hint-removeMargin='true'/> </binding > <binding template='TileMedium'> <image src='Assets\tile-bg.png' placement='background'/> <group> <subgroup hint-weight='1'> <image src = '" + result.Item2 + @"' hint-removeMargin='true'/> </subgroup> <subgroup hint-weight='2' hint-textStacking='bottom'> <text hint-align='center' hint-style='subtitle' >" + (moon.Result.NoDawn ? "--:--" : moon.Dawn.ToString("HH:mm")) + @"</text> <text hint-align='center' hint-style='subtitle'>" + (moon.Result.NoDusk ? "--:--" : moon.Dusk.ToString("HH:mm")) + @"</text> </subgroup> </group> </binding> <binding template = 'TileWide' > <image src='Assets\tile-bg.png' placement='background'/> <group > <subgroup hint-weight='1'> <image src = '" + result.Item2 + @"' hint-removeMargin='true'/> </subgroup> <subgroup hint-weight='3'> <text hint-align='center' hint-style='title'>" + (moon.Result.NoDawn ? "--:--" : moon.Dawn.ToString("HH:mm")) + @"</text> <text hint-align='center' hint-style='title'>" + (moon.Result.NoDusk ? "--:--" : moon.Dusk.ToString("HH:mm")) + @"</text> </subgroup> </group> </binding> <binding template = 'TileLarge' > <image src='Assets\tile-bg.png' placement='background'/> <group > <subgroup hint-weight='1'></subgroup> <subgroup hint-weight='2' > <image src='" + result.Item2 + @"' /> </subgroup> <subgroup hint-weight='1'></subgroup> </group> <text hint-align='center' hint-style='base'>" + App.res.GetString("MoonDailyDawnTimeTxt/Text") + (moon.Result.NoDawn ? "--:--" : moon.Dawn.ToString("HH:mm")) + @"</text> <text hint-align='center' hint-style='base'>" + App.res.GetString("MoonDailyDuskTimeTxt/Text") + (moon.Result.NoDusk ? "--:--" : moon.Dusk.ToString("HH:mm")) + @"</text> </binding> </visual> </tile> "); }
//return percent of illumination (from 0 to +-1.0) //return positive value if moon is waxing crescent //and negative - if waning moon public static double GetMoonPhase(Moon m, Sun s) { var delta_lon = s.EclipLon - m.EclipLon; if (delta_lon < 0) { delta_lon += 2 * Math.PI; } if (delta_lon <= Math.PI) { return(delta_lon / Math.PI); } else { return((delta_lon - 2 * Math.PI) / Math.PI); } }