There are quite some sources for astronomical calculation formulas, e.g. Astronomy Answers: Position of the Sun, which is e.g. used by KDE's Night Color plugin to calculate the time of a sunset or sunrise (when the sun's elevation is equal to a given value).
I want to do such a calculation on an Arduino Uno board. The problem is that all those formulas depend on double
precision calculations, because they take and return a Julian day with the time being the fraction part. The Arduino Uno only has float
precision, so the interesting part, the fraction representing the time, is lost (the Julian day alone takes all the decimal places).
Apparently, it's possible to avoid this problem, e.g. Dr. David Brooks published code to do elevation and azimuth calculations using float
precision only in Arduino Uno solar calculations. He splits the Julian day into an integer
day part and a float
time part.
However, those formulas only work for the current position of the sun at a given date, time and location, not vice versa. I'm interested in calculating the moment in time where the sun has e.g. a given elevation (a defined sunrise and sunset).
I thought that one approach to solve this could be to find the very first Julian day with the very same Earth-Sun constellation, where e.g. the sun had the same elevation at the same time. The day itself is not interesting, as I already know it – I only want to get the time. This way, the Julian day would be <= 365, leaving at least four digits to the time fraction. This would lead to a precision of about 10 s, which would be more than sufficient for my use-case.
So: Is it possible to find the first Julian day with the same Earth-Sun constellation as a given date? Like some modulo operation for a Julian day?
Thanks for all help!
float
is IEEE-754 binary32, which has a 24 bit significand. $\endgroup$float
forT
(Julian centuries since 2000.1.1) currently gives a granularity of ~90 seconds. That is, if $T=0.22$ then the smallest time step that makes a difference to $T$ is around 90 seconds. I'll put a live demo program (in Python) in the next comment. $\endgroup$