MCPcopy
hub / github.com/mourner/suncalc / getMoonPosition

Function getMoonPosition

index.js:393–415  ·  view source on GitHub ↗
(date, lat, lng)

Source from the content-addressed store, hash-verified

391}
392
393export function getMoonPosition(date, lat, lng) {
394 const lw = rad * -lng;
395 const phi = rad * lat;
396 const d = toDays(date);
397 const c = moonCoords(toDaysTT(d)); // position series run on Terrestrial Time
398 const H = siderealTime(d, lw) - c.ra; // sidereal time stays on UT
399
400 // geocentric parallax (Meeus ch.40) lowers the moon along its vertical circle, leaving
401 // azimuth unchanged; sin(parallax) = (Earth radius / distance) * cos(geocentric altitude).
402 const hGeo = altitude(H, phi, c.dec);
403 const h = hGeo - asin(earthRadius / c.dist * cos(hGeo));
404
405 // parallactic angle, Meeus 14.1
406 const pa = atan(sin(H), tan(phi) * cos(c.dec) - sin(c.dec) * cos(H));
407
408 return {
409 azimuth: azimuth(H, phi, c.dec),
410 // apparent (refraction-corrected) altitude in degrees
411 altitude: (h + astroRefraction(h)) / rad,
412 distance: c.dist,
413 parallacticAngle: pa / rad
414 };
415}
416
417// moon illumination parameters, Meeus ch. 48 (and idlastro's mphase.pro)
418export function getMoonIllumination(date = new Date()) {

Callers 1

moonHeightFunction · 0.85

Calls 7

toDaysFunction · 0.85
moonCoordsFunction · 0.85
toDaysTTFunction · 0.85
siderealTimeFunction · 0.85
altitudeFunction · 0.85
azimuthFunction · 0.85
astroRefractionFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…