TEMPEST.114 Posted March 9, 2023 Posted March 9, 2023 So this was suggested by @cfrag solareqns.PDF (noaa.gov) I'm trying to find if a game time is during the day or night, so I need to convert local time to zulu and time in seconds (game time) to hours and get the date and lat/long. All that is working correctly. I'm also correctly working out if the year is a leap and what the 'Day of the Year' is - that's all working correctly and checked. The problem I'm having is not understanding the main formulas and not getting the right numbers out of it. Here's my coding implementation of the formulas in that document: local fractionalYear = (( 2 * math.pi ) / numberOfDaysInThisYear) * ( dayOfYear - 1 + ( (hour - 12) / 24 ) ) local equationOfTimeInMinutes = 229.18 * (0.000075 + 0.001868 * math.cos(fractionalYear) - 0.032077 * math.sin(fractionalYear) - 0.014615 * math.cos(2 * fractionalYear) - 0.040849 * math.sin(2 * fractionalYear) ) local solarDeclinationAngleInRadians = 0.006918 - 0.399912 * math.cos(fractionalYear) + 0.070257 * math.sin(fractionalYear) - 0.006758 * math.cos(2 * fractionalYear) + 0.000907 * math.sin(2 * fractionalYear) - 0.002697 * math.cos(3 * fractionalYear) + 0.00148 * math.sin(3 * fractionalYear) local hourAngleInDegrees = math.acos( (math.cos(90.833) / (math.cos(lat) * math.cos(solarDeclinationAngleInRadians))) - (math.tan(lat) * math.tan(solarDeclinationAngleInRadians)) ) local sunriseOrSunsetInMinutesZulu = 720 - 4 * (long + hourAngleInDegrees) - equationOfTimeInMinutes The output from this for the following date and time 30th of July, 2020 for the Marianas map (Lat 13, Long, 144) is: (Main): DayOfYear 211 (Main): fractionalYear 3.626565 (Main): equationOfTimeInMinutes -6.550151 (Main): solarDeclinationAngleInRadians 0.323732 (Main): hourAngleInDegrees -nan(ind) I *think* the fractionalYear is wrong but I've done the maths by hand and it's coming out the same... It just seems like a small number for 1/2 a year. Anyway, the hourAngleInDegrees is Not A Number... but I don't see where I'm going wrong. Could somebody give me a 2nd pair of eyes on this please?
Dragon1-1 Posted March 9, 2023 Posted March 9, 2023 Off the top of my head, you put 90.833 in math.cos, and in other places you calculate declination angle in radians. Are those functions supposed to take radians or degrees? Also, is longitude and latitude in radians or degrees? Make sure you've got correct angular measurements everywhere. The NAN suggests an error of that sort, acos will give you NAN if the thing under it is not between -1 and 1.
TEMPEST.114 Posted March 9, 2023 Author Posted March 9, 2023 14 hours ago, Dragon1-1 said: Off the top of my head, you put 90.833 in math.cos, and in other places you calculate declination angle in radians. Are those functions supposed to take radians or degrees? Also, is longitude and latitude in radians or degrees? Make sure you've got correct angular measurements everywhere. The NAN suggests an error of that sort, acos will give you NAN if the thing under it is not between -1 and 1. did you look at the source link? The 90.833 is the figure from Nasa for the solar disk at twilight. Lat Long in degrees as the source doc says.
Dragon1-1 Posted March 9, 2023 Posted March 9, 2023 Yeah, but NASA doc is all in degrees. That is, itself, not a problem. The problem is whether the functions you're using take degrees or radians, because different programming languages might make different assumptions. I'm not sure about DCS, but I know Wolfram defaults to radians, which had tripped me up quite a few times, with similar symptoms (although you'll sometimes get imaginary values instead, the default data type in Wolfram is a complex number).
Recommended Posts