Skip to main content

@math.gl/earth/sun

From v3.1

@math.gl/earth/sun provides solar and lunar lighting, planetary sky information and shared sky/rendering coordinates.

Usage​

import {getSunDirection} from '@math.gl/earth/sun';
const latitude = 37.7749;
const longitude = -122.4194;
const sunDir = getSunDirection(Date.now(), latitude, longitude);

Features​

FeatureSupportNotes
Sun/Moon positions and Earth-fixed directions✅Solar, lunar and terminator geometry use explicit coordinate conventions.
Solar/lunar lighting and sky atmosphere✅Relative RGB lighting, lux-based sky lighting, atmospheric transmission and published-model approximations.
Cloud illumination✅Cloud lighting includes spherical Earth shadow, spectral dawn/dusk and explicit ray-depth approximations.
Planetary positions and appearance✅Planet sky information, disk/phase/magnitude and lunar/Galilean orientation/event helpers.
Shared observer, horizon and visibility search✅Sky APIs accept terrain horizons and explicit atmosphere settings; searches retain sampling/refinement limits.
UT1/TT, reusable contexts and snapshots✅Explicit time scales and bounded reusable contexts support batch sky evaluation.
Bright-star catalog and motion✅Stars include optional catalog data, proper motion, distance-aware motion and explicitly illustrative Galactic backgrounds/orbits.
Shared atmospheric visibility for stars◐Catalog/rendering data exist; the shared contrast/daylight/atmosphere integration remains tranche 5 work.
Observationally calibrated visibility and event guarantees◐Models and bounded searches exist; grazing/short events and observational uncertainty require broader independent qualification.
Published accuracy/performance tier budgets❌Timing controls and benchmarks exist; formal tier-wide numerical/date/performance budgets remain tranche 6 work.
Full physical radiative-transfer or surface rendering engine❌The API supplies approximate lighting/appearance data, not resolved planetary surface/ring rendering or a general spectral transport solver.

Installation​

npm install @math.gl/earth

Entry points​

Use @math.gl/earth/sun for Sun, Moon, sky, and planet calculations. Use @math.gl/earth/sun-stars for the bright-star catalog, star positions, star colors, and galactic utilities. Bundlers can omit astronomy-engine when the selected functions do not use it.

Coordinates and units​

Observer latitude/longitude are degrees; solar/lunar altitude and azimuth are radians. Local vectors use east/north/up axes. Solar and lunar light directions point inward; sky-body directions point outward. Light colors are linear RGB. getSunLight and getMoonLight return relative intensity, while getSkyLighting returns illuminance in lux. Globe positions are [longitudeDegrees, latitudeDegrees, altitudeMeters].

Sunlight​

Use getSunLight with the altitude returned by getSunPosition to estimate normalized linear RGB and relative direct-light intensity. The Hošek–Wilkie model supplies sun and diffuse sky illumination with configurable turbidity. A separate cloud approximation redistributes direct sunlight into diffuse lighting.

Use getCloudLighting for elevated cloud samples: spherical Earth shadowing, spectral dawn/dusk sunlight, approximate ambient/scattered colors and explicit Sun/view ray depths. High clouds can remain illuminated after ground sunset.

Moon and star field​

The module also provides moon position, direction, phase and direct moonlight, plus a star-field rotation for orienting an equatorial cubemap at the observer’s location and time.

Planets​

The optional planet sky API returns positions, disk sizes, phases and planet magnitudes, including the four Galilean moons. It also estimates twilight visibility and searches rise/set and visible time windows. Import from @math.gl/earth/sun.

Sky​

See sky snapshots, daylight Moon visibility and globe rendering for a shared observer/atmosphere, lux-based lighting, planet and lunar orientations, globe coordinates, reusable contexts and visibility searches.

Attribution​

Sunlight lookup data is derived from the Hošek–Wilkie 1.4a reference implementation under BSD-3-Clause. The full notice is shipped in LICENSE-HOSEK-WILKIE; see the API documentation for model provenance and limits.

The solar position calculation is a fork of Volodymyr Agafonkin's SunCalc under BSD 2-clause license.

The adapted lunar code and numeric reference samples use SunCalc 1.9.0 under BSD-2-Clause. The full notice is shipped in LICENSE-SUNCALC, and SPDX comments record the original owner and provenance. Original moonlight and star-field calculations use math.gl’s MIT license.

The star catalog contains 7,000 bright stars, projected proper motions, distance-aware motion and brightness where measurements exist, an illustrative Galactic orbit model, and a procedural Milky Way background. Numeric Julian epochs support long animations independently of the observer’s rendering date.

See Attributions for the project-wide source inventory and acknowledgments.