posts:2024:2024_04_03_practical_astronomy_various_languages

Practical Astronomy Algorithms in Various Languages

Wednesday April 3, 2024

For several years, I've worked off-and-on to implement astronomical algorithms from the Practical Astronomy book in various languages. I've just completed a JavaScript version, and I've published it to NPM. I've included a couple of simple code examples in the repo README, including how to calculate details for the April 8 solar eclipse.

The algorithms are described in detail in the Practical Astronomy with your Calculator or Spreadsheet book, by Peter Duffett-Smith. I highly recommend that you get a copy of the book, as it provides lots of explanations and context that you won't get by looking at the code alone. I worked with the 4th edition.

My code is actually a translation of macros from accompanying spreadsheet resources. You can download the spreadsheets from here.

These are all the languages for which I've implemented the Practical Astronomy algorithms, and the status of each function's completion1). Each language name in the column header is a clickable link to its respective GitHub repository. The .NET version also has a NuGet package.

Language
Function C C++ .NET/C# PHP Python Java JavaScript Rust
Date/Time
Calculate → Date of Easter
Convert → Civil Date to Day Number
Convert → Civil Time ↔ Decimal Hours
Extract → Hour, Minutes, and Seconds parts of Decimal Hours
Convert → Local Civil Time ↔ Universal Time
Convert → Universal Time ↔ Greenwich Sidereal Time
Convert → Greenwich Sidereal Time ↔ Local Sidereal Time
Coordinates
Convert → Angle ↔ Decimal Degrees
Convert → Right Ascension ↔ Hour Angle
Convert → Equatorial Coordinates ↔ Horizon Coordinates
Calculate → Obliquity of the Ecliptic
Convert → Ecliptic Coordinates ↔ Equatorial Coordinates
Convert → Equatorial Coordinates ↔ Galactic Coordinates
Calculate → Angle between two objects
Calculate → Rising and Setting times for an object
Calculate → Precession (corrected coordinates between two epochs)
Calculate → Nutation (in ecliptic longitude and obliquity) for a Greenwich date
Calculate → Effects of aberration for ecliptic coordinates
Calculate → RA and Declination values, corrected for atmospheric refraction
Calculate → RA and Declination values, corrected for geocentric parallax
Calculate → Heliographic coordinates
Calculate → Carrington rotation number
Calculate → Selenographic (lunar) coordinates (sub-Earth and sub-Solar)
The Sun
Calculate → Approximate and precise positions of the Sun
Calculate → Sun's distance and angular size
Calculate → Local sunrise and sunset
Calculate → Morning and evening twilight
Calculate → Equation of time
Calculate → Solar elongation
Planets
Calculate → Approximate position of planet
Calculate → Precise position of planet
Calculate → Visual aspects of planet (distance, angular diameter, phase, light time, position angle of bright limb, and apparent magnitude)
Comets
Calculate → Position of comet (elliptical)
Calculate → Position of comet (parabolic)
Binary Stars
Calculate → Binary star orbit data
The Moon
Calculate → Approximate and precise position of Moon
Calculate → Moon phase and position angle of bright limb
Calculate → Times of new Moon and full Moon
Calculate → Moon's distance, angular diameter, and horizontal parallax
Calculate → Local moonrise and moonset
Eclipses
Calculate → Lunar eclipse occurrence and circumstances
Calculate → Solar eclipse occurrence and circumstances

1)
As of June 1, 2024
  • posts/2024/2024_04_03_practical_astronomy_various_languages.txt
  • Last modified: 2025/03/31 17:56
  • by jimc