Hacker News new | past | comments | ask | show | jobs | submit login

It basically depends on how accurate you want to be. I looked into this so I could generate lunar calendars for friends. I got the phases of the moon predictions from the BSD Games program pom by Keith E. Brandt[0], which is itself based on 'Practical Astronomy with Your Calculator'[1] by Peter Duffett-Smith. Lunar eclipse predictions came from the Basic Lunar Eclipse and Phase Calculator by Xavier Jubier[2]. These work well for the near future and with a reasonable amount of precision for regular people. You can get much more accurate using Astronomy Engine[3], but that was already a lot more complex than I wanted to get into

[0] https://manpages.debian.org/bullseye/bsdgames/pom.6.en.html

[1] https://www.cambridge.org/core/books/practical-astronomy-wit...

[2] http://xjubier.free.fr/en/site_pages/LunarEclipseCalculator....

[3] https://github.com/cosinekitty/astronomy




I'd agree about accuracy but it is also worth mentioning the time reach. Plus or minus half a century from now (or J2000.0 epoch) is fine but if you wanted to explore historical eclipses then you will need to look at higher precision series. This whole thing is about truncating trigonometric series with amplitudes and angles that change over time.

For sunrise/set and moonrise/set calculations you also need to allow for refraction in the Earth's atmosphere (around half a degree or so). Also for moonrise/set you need to allow for the parallax of the Moon's position because you are standing on the surface of the Earth not the centre (up to 1 degree difference in position). This all assumes a spherical Earth and an Ocean horizon. And the rise/set time can changes a little bit with your altitude above the horizon.

For latitudes near the Arctic/Antarctic circles any method based on iteration (as in Duffett-Smith's lovely book) is going to have convergence issues because there might not actually be a rise/set event near that day so if you really want an algorithm that will work anywhere on Earth you'll need to use a method based on fitting a quadratic curve to (say) 24 positions calculated for the day. Have a look at [1] in a library. The code is in Pascal, but it is the search method using a quadratic fit to sets of 3 consecutive positions you want.

Just for low-precision lunar positions, an interesting alternative that also summarises the various methods was produced by NASA [2] for space craft use.

[1] https://link.springer.com/book/10.1007/978-3-642-03436-7

[2] https://caps.gsfc.nasa.gov/simpson/pubs/slunar.pdf




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: