src/core/astro.js
Positional astronomy for the sky view: time scales, sidereal time, precession and nutation, coordinate
changes, refraction, and low-precision positions of the Sun, Moon and planets. No DOM, no three.js.
Conventions
angles in radians unless a name ends in Deg; time as Unix milliseconds (UTC) or Julian centuries T of TT from J2000
equatorial vectors: x to the equinox, z to the pole; "of date" = true equator and equinox of date
horizontal vectors: [east, north, up]; azimuth from north through east; longitude east positive
UT1 is taken equal to UTC (|UT1 - UTC| < 0.9 s, i.e. < 13.5" of sidereal time)
What each series claims, and what test/astro.test.mjs measures against astropy/ERFA with the JPL DE432s
ephemeris, 1975-2050 (run `node test/astro.test.mjs` for the current numbers):
sidereal time IAU 1982 GMST + 4-term nutation (Meeus, Astronomical Algorithms, ch. 12, 22)
precession IAU 1976 angles (Meeus ch. 21); no frame bias (17 mas)
Sun Meeus ch. 25 "low accuracy" (claimed 0.01 deg)
Moon the larger periodic terms of Meeus ch. 47 (ELP-2000/82 truncated; full table claims 10" in longitude)
planets Keplerian elements of E. M. Standish, "Keplerian Elements for Approximate Positions of the
Major Planets" (JPL Solar System Dynamics), table 1, valid 1800-2050. Claimed errors in
heliocentric longitude: Mercury 15", Venus 20", Earth-Moon 20", Mars 40", Jupiter 400",
Saturn 600", Uranus 50", Neptune 10".
refraction Bennett (1982) / Saemundsson (1986), 1010 hPa and 10 C unless scaled
a night twilight times by bisection on the Sun's altitude; rising, culmination and setting of a fixed
J2000 position from its hour angle (nightOf, fixedRiseSet, trackFixed). Against astropy:
see the "a target through a night" block of the test.
Not modelled: stellar proper motion and parallax, annual aberration of stars (20"), polar motion, UT1-UTC.Import: import { … } from './src/core/astro.js' — no DOM, runs in Node and the browser.
RAD
const RADPositional astronomy for the sky view: time scales, sidereal time, precession and nutation, coordinate
changes, refraction, and low-precision positions of the Sun, Moon and planets. No DOM, no three.js.
Conventions
angles in radians unless a name ends in Deg; time as Unix milliseconds (UTC) or Julian centuries T of TT from J2000
equatorial vectors: x to the equinox, z to the pole; "of date" = true equator and equinox of date
horizontal vectors: [east, north, up]; azimuth from north through east; longitude east positive
UT1 is taken equal to UTC (|UT1 - UTC| < 0.9 s, i.e. < 13.5" of sidereal time)
What each series claims, and what test/astro.test.mjs measures against astropy/ERFA with the JPL DE432s
ephemeris, 1975-2050 (run `node test/astro.test.mjs` for the current numbers):
sidereal time IAU 1982 GMST + 4-term nutation (Meeus, Astronomical Algorithms, ch. 12, 22)
precession IAU 1976 angles (Meeus ch. 21); no frame bias (17 mas)
Sun Meeus ch. 25 "low accuracy" (claimed 0.01 deg)
Moon the larger periodic terms of Meeus ch. 47 (ELP-2000/82 truncated; full table claims 10" in longitude)
planets Keplerian elements of E. M. Standish, "Keplerian Elements for Approximate Positions of the
Major Planets" (JPL Solar System Dynamics), table 1, valid 1800-2050. Claimed errors in
heliocentric longitude: Mercury 15", Venus 20", Earth-Moon 20", Mars 40", Jupiter 400",
Saturn 600", Uranus 50", Neptune 10".
refraction Bennett (1982) / Saemundsson (1986), 1010 hPa and 10 C unless scaled
a night twilight times by bisection on the Sun's altitude; rising, culmination and setting of a fixed
J2000 position from its hour angle (nightOf, fixedRiseSet, trackFixed). Against astropy:
see the "a target through a night" block of the test.
Not modelled: stellar proper motion and parallax, annual aberration of stars (20"), polar motion, UT1-UTC.AU_KM
const AU_KMNo description in the source.
wrap2pi
const wrap2piNo description in the source.
wrapPi
const wrapPiNo description in the source.
julianDate
const julianDateJulian date (UTC) of a Unix time in milliseconds.
fromJulianDate
const fromJulianDateNo description in the source.
ttMinusUtc
function ttMinusUtc(ms)TT - UTC in seconds: 32.184 + leap seconds (table 1972-2017, the last value held after; 42.184 before 1972).
centuriesTT
const centuriesTTJulian centuries of TT since J2000.0 for a Unix time in ms.
gmst
function gmst(jdUT)Greenwich mean sidereal time (IAU 1982) for a Julian date of UT1.
nutation
function nutation(T)Nutation in longitude and obliquity (four largest terms, about 0.5") and the obliquity of the ecliptic.
gast
function gast(jdUT, T = (jdUT - 2451545.0)Greenwich apparent sidereal time: GMST plus the equation of the equinoxes. T defaults to UT-based centuries.
localSiderealTime
const localSiderealTimeLocal apparent sidereal time for a Unix time and an east longitude in radians.
matMul
const matMul---------------------------------------------------------------- 3x3 matrices (row-major arrays of 9) and vectors
matVec
const matVecNo description in the source.
transpose
const transposeNo description in the source.
sphToVec
const sphToVecNo description in the source.
vecToSph
const vecToSphNo description in the source.
separation
function separation(lon1, lat1, lon2, lat2)Angle between two directions given as longitude, latitude pairs.
precessionMatrix
function precessionMatrix(T)Precession matrix from the mean equator and equinox of J2000 to those of date (IAU 1976).
nutationMatrix
function nutationMatrix(T)Nutation matrix from the mean to the true equator and equinox of date.
j2000ToDateMatrix
const j2000ToDateMatrixJ2000 (ICRS to 17 mas) to true equator and equinox of date.
precess
function precess(ra, dec, T)Right ascension and declination of date for J2000 coordinates.
equatorialToHorizontalMatrix
function equatorialToHorizontalMatrix(lat, lst)Matrix taking an equatorial-of-date unit vector to [east, north, up] for latitude and local sidereal time.
equatorialToHorizontal
function equatorialToHorizontal(ra, dec, lat, lst)No description in the source.
horizontalToEquatorial
function horizontalToEquatorial(alt, az, lat, lst)No description in the source.
refraction
function refraction(altTrue, pressure = 1010, tempC = 10)Refraction to add to a true (airless) altitude: Saemundsson's formula. Returns 0 well below the horizon.
refractionFromApparent
function refractionFromApparent(altApparent, pressure = 1010, tempC = 10)Refraction to subtract from an apparent (observed) altitude: Bennett's formula.
sunPosition
function sunPosition(T)Geocentric apparent position of the Sun, true equator and equinox of date. dist in AU.
moonPosition
function moonPosition(T)Geocentric apparent position of the Moon, true equator and equinox of date. dist in km.
PLANETS
const PLANETSNo description in the source.
solveKepler
function solveKepler(M, e)Solve Kepler's equation E - e sin E = M.heliocentric
function heliocentric(name, T)Heliocentric position [AU] in the J2000 equatorial frame from the Keplerian elements. name may be 'emb'.
earthHeliocentric
function earthHeliocentric(T)Heliocentric position of the Earth [AU], J2000 equatorial: the Earth-Moon barycentre minus the Moon's share.
planetPosition
function planetPosition(name, T)Geocentric apparent position of a planet (light time and aberration to first order), true equator and equinox of date. dist and r (heliocentric) in AU; phase is the Sun-planet-Earth angle.
planetMagnitude
function planetMagnitude(name, r, dist, phase)Apparent visual magnitude of a planet (Astronomical Almanac expressions as in Meeus ch. 41; Saturn without its rings, which add up to about -1 mag). r, dist in AU, phase in radians.
moonPhase
function moonPhase(sun, moon)Phase of the Moon from the geocentric positions of the Sun and Moon: elongation, phase angle (Sun-Moon-Earth), illuminated fraction and an approximate visual magnitude.
observerVector
function observerVector(lat, lst, heightM = 0)Geocentric position of an observer [km] in the equatorial frame of date (WGS84).
topocentric
function topocentric(ra, dec, distKm, lat, lst, heightM = 0)Geocentric -> topocentric right ascension, declination and distance. distKm is the geocentric distance.twilight
function twilight(sunAltDeg)Day or twilight class from the true (unrefracted) altitude of the Sun's centre in degrees.
solarSystem
function solarSystem(ms, lat, lon, heightM = 0)The Sun, Moon and planets as seen from a place: topocentric coordinates of date, airless altitude and azimuth, distance, magnitude. Returns { T, lst, sun, moon, planets[] , bodies[] }.
SIDEREAL_RATE
const SIDEREAL_RATERotation of the Earth in radians per millisecond of UT (sidereal rate).
fixedAltAz
function fixedAltAz(ra, dec, ms, lat, lon)Airless altitude and azimuth of a fixed J2000 position (radians) at a Unix time for a latitude and east longitude.
sunAltitude
function sunAltitude(ms, lat, lon, heightM = 0)Airless topocentric altitude of the Sun's centre (radians).
crossings
function crossings(f, ms0, ms1, step = 600000)Times in [ms0, ms1] at which f(ms) changes sign: sampled every step ms, refined by bisection to 0.1 s. Returns [{ t, rising }].
sunCrossings
const sunCrossingsTimes at which the Sun's centre crosses the airless altitude alt (radians) between two Unix times.
noonBefore
const noonBeforeThe last local mean noon at or before a Unix time, for an east longitude in radians.
SUN_LIMITS
const SUN_LIMITSAltitudes of the Sun's centre (degrees) that bound day and the three twilights.
nightOf
function nightOf(ms, lat, lon, heightM = 0)The night that contains a Unix time, or the one that follows it when the Sun is up: for each of sun (set and rise, -0.833 deg), civil, nautical and astronomical, { evening, morning } in Unix ms, null where the Sun does not reach that altitude between the local noon before and the one after (polar day or night).
fixedRiseSet
function fixedRiseSet(ra, dec, ms, lat, lon, alt0 = 0)Rising, culmination and setting (through the airless altitude alt0, radians) of a fixed J2000 position, for the culmination nearest to a Unix time. Returns { culmination, rise, set, altMax, always, never }; rise and set are null when it is always or never above alt0.
trackFixed
function trackFixed(ra, dec, ms0, ms1, lat, lon, n = 96)Airless altitude and azimuth of a fixed J2000 position at n + 1 equally spaced times: [{ t, alt, az }].