@math.gl/earth 0.0.0-stage → 5.0.0-alpha.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1015 -0
- package/README.md +19 -2
- package/THIRD-PARTY-NOTICES.md +25 -0
- package/dist/geoid/create-geoid-from-grid.d.ts +15 -0
- package/dist/geoid/create-geoid-from-grid.d.ts.map +1 -0
- package/dist/geoid/create-geoid-from-grid.js +38 -0
- package/dist/geoid/create-geoid-from-grid.js.map +1 -0
- package/dist/geoid/geoid.d.ts +60 -0
- package/dist/geoid/geoid.d.ts.map +1 -0
- package/dist/geoid/geoid.js +261 -0
- package/dist/geoid/geoid.js.map +1 -0
- package/dist/geoid/index.cjs +727 -0
- package/dist/geoid/index.cjs.map +6 -0
- package/dist/geoid/index.d.ts +5 -0
- package/dist/geoid/index.d.ts.map +1 -0
- package/dist/geoid/index.js +7 -0
- package/dist/geoid/index.js.map +1 -0
- package/dist/geoid/parse-pgm.d.ts +12 -0
- package/dist/geoid/parse-pgm.d.ts.map +1 -0
- package/dist/geoid/parse-pgm.js +183 -0
- package/dist/geoid/parse-pgm.js.map +1 -0
- package/dist/index.cjs +2646 -0
- package/dist/index.cjs.map +6 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/sun/astronomy.cjs +1729 -0
- package/dist/sun/astronomy.cjs.map +6 -0
- package/dist/sun/astronomy.d.ts +359 -0
- package/dist/sun/astronomy.d.ts.map +1 -0
- package/dist/sun/astronomy.js +181 -0
- package/dist/sun/astronomy.js.map +1 -0
- package/dist/sun/celestial.d.ts +4 -0
- package/dist/sun/celestial.d.ts.map +1 -0
- package/dist/sun/celestial.js +18 -0
- package/dist/sun/celestial.js.map +1 -0
- package/dist/sun/cloud-lighting.d.ts +49 -0
- package/dist/sun/cloud-lighting.d.ts.map +1 -0
- package/dist/sun/cloud-lighting.js +121 -0
- package/dist/sun/cloud-lighting.js.map +1 -0
- package/dist/sun/cloud-spectral.d.ts +3 -0
- package/dist/sun/cloud-spectral.d.ts.map +1 -0
- package/dist/sun/cloud-spectral.js +45 -0
- package/dist/sun/cloud-spectral.js.map +1 -0
- package/dist/sun/data/bright-stars.d.ts +3 -0
- package/dist/sun/data/bright-stars.d.ts.map +1 -0
- package/dist/sun/data/bright-stars.js +7015 -0
- package/dist/sun/data/bright-stars.js.map +1 -0
- package/dist/sun/data/sunlight.d.ts +2 -0
- package/dist/sun/data/sunlight.d.ts.map +1 -0
- package/dist/sun/data/sunlight.js +970 -0
- package/dist/sun/data/sunlight.js.map +1 -0
- package/dist/sun/index.cjs +1744 -0
- package/dist/sun/index.cjs.map +6 -0
- package/dist/sun/index.d.ts +23 -0
- package/dist/sun/index.d.ts.map +1 -0
- package/dist/sun/index.js +17 -0
- package/dist/sun/index.js.map +1 -0
- package/dist/sun/moon-appearance.d.ts +25 -0
- package/dist/sun/moon-appearance.d.ts.map +1 -0
- package/dist/sun/moon-appearance.js +50 -0
- package/dist/sun/moon-appearance.js.map +1 -0
- package/dist/sun/moon-sky-brightness.d.ts +7 -0
- package/dist/sun/moon-sky-brightness.d.ts.map +1 -0
- package/dist/sun/moon-sky-brightness.js +50 -0
- package/dist/sun/moon-sky-brightness.js.map +1 -0
- package/dist/sun/moon.d.ts +26 -0
- package/dist/sun/moon.d.ts.map +1 -0
- package/dist/sun/moon.js +74 -0
- package/dist/sun/moon.js.map +1 -0
- package/dist/sun/moonlight.d.ts +23 -0
- package/dist/sun/moonlight.d.ts.map +1 -0
- package/dist/sun/moonlight.js +48 -0
- package/dist/sun/moonlight.js.map +1 -0
- package/dist/sun/planet-position.d.ts +63 -0
- package/dist/sun/planet-position.d.ts.map +1 -0
- package/dist/sun/planet-position.js +189 -0
- package/dist/sun/planet-position.js.map +1 -0
- package/dist/sun/planet-times.d.ts +41 -0
- package/dist/sun/planet-times.d.ts.map +1 -0
- package/dist/sun/planet-times.js +86 -0
- package/dist/sun/planet-times.js.map +1 -0
- package/dist/sun/planet-visibility.d.ts +39 -0
- package/dist/sun/planet-visibility.d.ts.map +1 -0
- package/dist/sun/planet-visibility.js +82 -0
- package/dist/sun/planet-visibility.js.map +1 -0
- package/dist/sun/planets.cjs +411 -0
- package/dist/sun/planets.cjs.map +6 -0
- package/dist/sun/planets.d.ts +7 -0
- package/dist/sun/planets.d.ts.map +1 -0
- package/dist/sun/planets.js +7 -0
- package/dist/sun/planets.js.map +1 -0
- package/dist/sun/sky-brightness.d.ts +32 -0
- package/dist/sun/sky-brightness.d.ts.map +1 -0
- package/dist/sun/sky-brightness.js +108 -0
- package/dist/sun/sky-brightness.js.map +1 -0
- package/dist/sun/sky-events.d.ts +16 -0
- package/dist/sun/sky-events.d.ts.map +1 -0
- package/dist/sun/sky-events.js +60 -0
- package/dist/sun/sky-events.js.map +1 -0
- package/dist/sun/sky-globe.d.ts +15 -0
- package/dist/sun/sky-globe.d.ts.map +1 -0
- package/dist/sun/sky-globe.js +51 -0
- package/dist/sun/sky-globe.js.map +1 -0
- package/dist/sun/sky-lighting.d.ts +27 -0
- package/dist/sun/sky-lighting.d.ts.map +1 -0
- package/dist/sun/sky-lighting.js +88 -0
- package/dist/sun/sky-lighting.js.map +1 -0
- package/dist/sun/sky-observer.d.ts +22 -0
- package/dist/sun/sky-observer.d.ts.map +1 -0
- package/dist/sun/sky-observer.js +57 -0
- package/dist/sun/sky-observer.js.map +1 -0
- package/dist/sun/sky-time.d.ts +9 -0
- package/dist/sun/sky-time.d.ts.map +1 -0
- package/dist/sun/sky-time.js +38 -0
- package/dist/sun/sky-time.js.map +1 -0
- package/dist/sun/star-galactic.d.ts +15 -0
- package/dist/sun/star-galactic.d.ts.map +1 -0
- package/dist/sun/star-galactic.js +98 -0
- package/dist/sun/star-galactic.js.map +1 -0
- package/dist/sun/star-milky-way.d.ts +14 -0
- package/dist/sun/star-milky-way.d.ts.map +1 -0
- package/dist/sun/star-milky-way.js +32 -0
- package/dist/sun/star-milky-way.js.map +1 -0
- package/dist/sun/star-render.d.ts +38 -0
- package/dist/sun/star-render.d.ts.map +1 -0
- package/dist/sun/star-render.js +98 -0
- package/dist/sun/star-render.js.map +1 -0
- package/dist/sun/star-types.d.ts +60 -0
- package/dist/sun/star-types.d.ts.map +1 -0
- package/dist/sun/star-types.js +5 -0
- package/dist/sun/star-types.js.map +1 -0
- package/dist/sun/starfield.d.ts +13 -0
- package/dist/sun/starfield.d.ts.map +1 -0
- package/dist/sun/starfield.js +86 -0
- package/dist/sun/starfield.js.map +1 -0
- package/dist/sun/stars.cjs +7519 -0
- package/dist/sun/stars.cjs.map +6 -0
- package/dist/sun/stars.d.ts +26 -0
- package/dist/sun/stars.d.ts.map +1 -0
- package/dist/sun/stars.js +188 -0
- package/dist/sun/stars.js.map +1 -0
- package/dist/sun/suncalc.d.ts +26 -0
- package/dist/sun/suncalc.d.ts.map +1 -0
- package/dist/sun/suncalc.js +94 -0
- package/dist/sun/suncalc.js.map +1 -0
- package/dist/sun/sunlight.d.ts +25 -0
- package/dist/sun/sunlight.d.ts.map +1 -0
- package/dist/sun/sunlight.js +76 -0
- package/dist/sun/sunlight.js.map +1 -0
- package/dist/timezone/index.cjs +205 -0
- package/dist/timezone/index.cjs.map +6 -0
- package/dist/timezone/index.d.ts +6 -0
- package/dist/timezone/index.d.ts.map +1 -0
- package/dist/timezone/index.js +8 -0
- package/dist/timezone/index.js.map +1 -0
- package/dist/timezone/instant.d.ts +4 -0
- package/dist/timezone/instant.d.ts.map +1 -0
- package/dist/timezone/instant.js +20 -0
- package/dist/timezone/instant.js.map +1 -0
- package/dist/timezone/local-date-time.d.ts +4 -0
- package/dist/timezone/local-date-time.d.ts.map +1 -0
- package/dist/timezone/local-date-time.js +34 -0
- package/dist/timezone/local-date-time.js.map +1 -0
- package/dist/timezone/lookup-async.d.ts +3 -0
- package/dist/timezone/lookup-async.d.ts.map +1 -0
- package/dist/timezone/lookup-async.js +14 -0
- package/dist/timezone/lookup-async.js.map +1 -0
- package/dist/timezone/lookup.cjs +83 -0
- package/dist/timezone/lookup.cjs.map +6 -0
- package/dist/timezone/lookup.d.ts +3 -0
- package/dist/timezone/lookup.d.ts.map +1 -0
- package/dist/timezone/lookup.js +18 -0
- package/dist/timezone/lookup.js.map +1 -0
- package/dist/timezone/temporal.cjs +5696 -0
- package/dist/timezone/temporal.cjs.map +6 -0
- package/dist/timezone/temporal.d.ts +9 -0
- package/dist/timezone/temporal.d.ts.map +1 -0
- package/dist/timezone/temporal.js +60 -0
- package/dist/timezone/temporal.js.map +1 -0
- package/dist/timezone/timezone-label.d.ts +5 -0
- package/dist/timezone/timezone-label.d.ts.map +1 -0
- package/dist/timezone/timezone-label.js +27 -0
- package/dist/timezone/timezone-label.js.map +1 -0
- package/dist/timezone/timezone-offset.d.ts +3 -0
- package/dist/timezone/timezone-offset.d.ts.map +1 -0
- package/dist/timezone/timezone-offset.js +22 -0
- package/dist/timezone/timezone-offset.js.map +1 -0
- package/dist/timezone/types.d.ts +23 -0
- package/dist/timezone/types.d.ts.map +1 -0
- package/dist/timezone/types.js +5 -0
- package/dist/timezone/types.js.map +1 -0
- package/dist/timezone/vendor/temporal/runtime.d.ts +3 -0
- package/dist/timezone/vendor/temporal/runtime.d.ts.map +1 -0
- package/dist/timezone/vendor/temporal/runtime.js +5649 -0
- package/dist/timezone/vendor/temporal/runtime.js.map +1 -0
- package/dist/timezone/vendor/temporal/types.d.ts +939 -0
- package/dist/timezone/vendor/temporal/types.d.ts.map +1 -0
- package/dist/timezone/vendor/temporal/types.js +4 -0
- package/dist/timezone/vendor/temporal/types.js.map +1 -0
- package/dist/timezone/vendor/tz-lookup/runtime.d.ts +3 -0
- package/dist/timezone/vendor/tz-lookup/runtime.d.ts.map +1 -0
- package/dist/timezone/vendor/tz-lookup/runtime.js +53 -0
- package/dist/timezone/vendor/tz-lookup/runtime.js.map +1 -0
- package/geoid/data/README.md +28 -0
- package/geoid/data/geoid-egm96-hi.pgm +0 -0
- package/geoid/data/geoid-egm96-low.pgm +0 -0
- package/geoid/data/geoid-manifest.json +22 -0
- package/package.json +102 -4
- package/src/geoid/create-geoid-from-grid.ts +51 -0
- package/src/geoid/geoid.ts +297 -0
- package/src/geoid/index.ts +8 -0
- package/src/geoid/parse-pgm.ts +189 -0
- package/src/index.ts +7 -0
- package/src/sun/astronomy.ts +272 -0
- package/src/sun/celestial.ts +22 -0
- package/src/sun/cloud-lighting.ts +198 -0
- package/src/sun/cloud-spectral.ts +54 -0
- package/src/sun/data/bright-stars.ts +7024 -0
- package/src/sun/data/sunlight.ts +969 -0
- package/src/sun/index.ts +43 -0
- package/src/sun/moon-appearance.ts +81 -0
- package/src/sun/moon-sky-brightness.ts +64 -0
- package/src/sun/moon.ts +122 -0
- package/src/sun/moonlight.ts +88 -0
- package/src/sun/planet-position.ts +305 -0
- package/src/sun/planet-times.ts +142 -0
- package/src/sun/planet-visibility.ts +143 -0
- package/src/sun/planets.ts +18 -0
- package/src/sun/sky-brightness.ts +148 -0
- package/src/sun/sky-events.ts +66 -0
- package/src/sun/sky-globe.ts +72 -0
- package/src/sun/sky-lighting.ts +118 -0
- package/src/sun/sky-observer.ts +66 -0
- package/src/sun/sky-time.ts +42 -0
- package/src/sun/star-galactic.ts +111 -0
- package/src/sun/star-milky-way.ts +61 -0
- package/src/sun/star-render.ts +149 -0
- package/src/sun/star-types.ts +66 -0
- package/src/sun/starfield.ts +100 -0
- package/src/sun/stars.ts +260 -0
- package/src/sun/suncalc.ts +141 -0
- package/src/sun/sunlight.ts +112 -0
- package/src/timezone/index.ts +9 -0
- package/src/timezone/instant.ts +21 -0
- package/src/timezone/local-date-time.ts +40 -0
- package/src/timezone/lookup-async.ts +15 -0
- package/src/timezone/lookup.ts +21 -0
- package/src/timezone/temporal.ts +81 -0
- package/src/timezone/timezone-label.ts +30 -0
- package/src/timezone/timezone-offset.ts +21 -0
- package/src/timezone/types.ts +30 -0
- package/src/timezone/vendor/temporal/JSBI-LICENSE.txt +179 -0
- package/src/timezone/vendor/temporal/LICENSE.txt +16 -0
- package/src/timezone/vendor/temporal/README.md +23 -0
- package/src/timezone/vendor/temporal/runtime.ts +5070 -0
- package/src/timezone/vendor/temporal/types.ts +1146 -0
- package/src/timezone/vendor/tz-lookup/LICENSE.txt +119 -0
- package/src/timezone/vendor/tz-lookup/README.md +22 -0
- package/src/timezone/vendor/tz-lookup/runtime.ts +53 -0
- package/sun/LICENSE-BRIGHT-STARS +21 -0
- package/sun/LICENSE-HOSEK-WILKIE +30 -0
- package/sun/LICENSE-SUNCALC +24 -0
- package/timezone/data/LICENSE-ODbL.txt +538 -0
- package/timezone/data/README.md +50 -0
- package/timezone/data/manifest.json +37 -0
- package/timezone/data/timezone-geometry-hi.json +1 -0
- package/timezone/data/timezone-geometry-hi.parquet +0 -0
- package/timezone/data/timezone-geometry-low.json +1 -0
- package/timezone/data/timezone-geometry-low.parquet +0 -0
package/src/sun/index.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
export {getMoonPosition, getMoonDirection, getMoonIllumination} from './moon';
|
|
5
|
+
export type {MoonPosition, MoonIllumination} from './moon';
|
|
6
|
+
export {getMoonLight} from './moonlight';
|
|
7
|
+
export type {MoonLight, MoonLightOptions} from './moonlight';
|
|
8
|
+
export {getStarfieldRotation} from './starfield';
|
|
9
|
+
export type {StarfieldOptions} from './starfield';
|
|
10
|
+
export {getSunPosition, getSunDirection} from './suncalc';
|
|
11
|
+
export {getSunLight} from './sunlight';
|
|
12
|
+
export type {LightColor, SunLight, SunLightOptions} from './sunlight';
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
createSkyObserver,
|
|
16
|
+
getSkyDirection,
|
|
17
|
+
reverseSkyDirection,
|
|
18
|
+
getSkyHorizonAltitude
|
|
19
|
+
} from './sky-observer';
|
|
20
|
+
export type {SkyObserver, SkyHorizonProfile} from './sky-observer';
|
|
21
|
+
export {
|
|
22
|
+
createSkyAtmosphere,
|
|
23
|
+
getSkyAirMass,
|
|
24
|
+
getSkyTransmission,
|
|
25
|
+
getSkyLuminance,
|
|
26
|
+
getSkyContrastThreshold
|
|
27
|
+
} from './sky-brightness';
|
|
28
|
+
export type {SkyAtmosphereOptions} from './sky-brightness';
|
|
29
|
+
export {getMoonAppearance} from './moon-appearance';
|
|
30
|
+
export type {MoonAppearanceOptions} from './moon-appearance';
|
|
31
|
+
export {getSkyLighting} from './sky-lighting';
|
|
32
|
+
export type {SkyLightingOptions} from './sky-lighting';
|
|
33
|
+
export {searchSkyVisibility} from './sky-events';
|
|
34
|
+
export {getScatteredMoonLuminance} from './moon-sky-brightness';
|
|
35
|
+
export {
|
|
36
|
+
SKY_GLOBE_EARTH_RADIUS,
|
|
37
|
+
getSkyGlobeRotation,
|
|
38
|
+
skyDirectionToGlobe,
|
|
39
|
+
getSkyGlobePosition,
|
|
40
|
+
skyRotationToGlobe
|
|
41
|
+
} from './sky-globe';
|
|
42
|
+
export {getCloudLighting} from './cloud-lighting';
|
|
43
|
+
export type {CloudLighting, CloudLightingOptions} from './cloud-lighting';
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileComment: Original implementation of lunar photometry and extended-target contrast.
|
|
5
|
+
// Phase law: Krisciunas & Schaefer (1991), https://doi.org/10.1086/132921
|
|
6
|
+
// Photometric conversion and contrast: Crumey (2014), https://arxiv.org/abs/1405.4209
|
|
7
|
+
import {validateRange} from './celestial';
|
|
8
|
+
import {getSkyContrastThreshold, getSkyLuminance, getSkyTransmission} from './sky-brightness';
|
|
9
|
+
import type {SkyAtmosphereOptions} from './sky-brightness';
|
|
10
|
+
import {getScatteredMoonLuminance} from './moon-sky-brightness';
|
|
11
|
+
|
|
12
|
+
export type MoonAppearanceOptions = SkyAtmosphereOptions & {
|
|
13
|
+
phaseAngle: number;
|
|
14
|
+
distance?: number;
|
|
15
|
+
/** Moon/Sun angular separation, radians. Required for directional glare. */
|
|
16
|
+
sunSeparation: number;
|
|
17
|
+
/** Human contrast threshold field factor. Default 2. */
|
|
18
|
+
observerFactor?: number;
|
|
19
|
+
/** Terrain horizon altitude in this direction, radians. Default 0. */
|
|
20
|
+
horizonAltitude?: number;
|
|
21
|
+
};
|
|
22
|
+
/** Physical light and apparent contrast are separate; daylight never forces a zero. */
|
|
23
|
+
export function getMoonAppearance(
|
|
24
|
+
moonAltitude: number,
|
|
25
|
+
sunAltitude: number,
|
|
26
|
+
options: MoonAppearanceOptions
|
|
27
|
+
) {
|
|
28
|
+
const {
|
|
29
|
+
phaseAngle,
|
|
30
|
+
sunSeparation,
|
|
31
|
+
distance = 384400,
|
|
32
|
+
observerFactor = 2,
|
|
33
|
+
horizonAltitude = 0
|
|
34
|
+
} = options;
|
|
35
|
+
validateRange('Moon altitude', moonAltitude, -Math.PI / 2, Math.PI / 2);
|
|
36
|
+
validateRange('Phase angle', phaseAngle, 0, Math.PI);
|
|
37
|
+
validateRange('Moon distance', distance, 1737.4, Number.MAX_VALUE);
|
|
38
|
+
validateRange('Horizon altitude', horizonAltitude, -Math.PI / 2, Math.PI / 2);
|
|
39
|
+
const backgroundLuminance =
|
|
40
|
+
getSkyLuminance(sunAltitude, moonAltitude, sunSeparation, options) +
|
|
41
|
+
getScatteredMoonLuminance(phaseAngle, moonAltitude, moonAltitude, 0, {...options, distance});
|
|
42
|
+
const radius = Math.asin(1737.4 / distance);
|
|
43
|
+
const illuminatedFraction = (1 + Math.cos(phaseAngle)) / 2;
|
|
44
|
+
const degrees = (phaseAngle * 180) / Math.PI;
|
|
45
|
+
const phaseBrightness = Math.min(
|
|
46
|
+
Math.pow(10, -0.4 * (0.026 * degrees + 4e-9 * degrees ** 4)),
|
|
47
|
+
illuminatedFraction
|
|
48
|
+
);
|
|
49
|
+
const h = Math.max(-1, Math.min(1, (moonAltitude - horizonAltitude) / radius));
|
|
50
|
+
const visibleDiskFraction = (Math.acos(-h) + h * Math.sqrt(1 - h * h)) / Math.PI;
|
|
51
|
+
// Full Moon mV=-12.73 at mean distance, E[lux]=10^(-0.4*(mV+13.99)).
|
|
52
|
+
const illuminance =
|
|
53
|
+
Math.pow(10, -0.4 * 1.26) *
|
|
54
|
+
phaseBrightness *
|
|
55
|
+
(384400 / distance) ** 2 *
|
|
56
|
+
getSkyTransmission(moonAltitude, options) *
|
|
57
|
+
visibleDiskFraction;
|
|
58
|
+
const solidAngle =
|
|
59
|
+
2 * Math.PI * (1 - Math.cos(radius)) * illuminatedFraction * visibleDiskFraction;
|
|
60
|
+
const diskLuminance = solidAngle > 0 ? illuminance / solidAngle : 0;
|
|
61
|
+
const contrast = diskLuminance / Math.max(1e-5, backgroundLuminance);
|
|
62
|
+
const contrastThreshold = getSkyContrastThreshold(
|
|
63
|
+
backgroundLuminance,
|
|
64
|
+
Math.max(1e-15, solidAngle),
|
|
65
|
+
observerFactor
|
|
66
|
+
);
|
|
67
|
+
const ratio = contrast / contrastThreshold;
|
|
68
|
+
const t = Math.max(0, Math.min(1, (Math.log2(Math.max(1e-30, ratio)) + 1) / 2));
|
|
69
|
+
return {
|
|
70
|
+
illuminance,
|
|
71
|
+
horizontalIlluminance: illuminance * Math.max(0, Math.sin(moonAltitude)),
|
|
72
|
+
backgroundLuminance,
|
|
73
|
+
diskLuminance,
|
|
74
|
+
contrast,
|
|
75
|
+
contrastThreshold,
|
|
76
|
+
illuminatedFraction,
|
|
77
|
+
visibleDiskFraction,
|
|
78
|
+
visible: ratio >= 1 && illuminance > 0,
|
|
79
|
+
fade: t * t * (3 - 2 * t)
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileComment: Independently implemented Krisciunas & Schaefer (1991), Equations 3, 15, 19–21; no reference code copied.
|
|
5
|
+
// https://doi.org/10.1086/132921
|
|
6
|
+
import {validateRange} from './celestial';
|
|
7
|
+
import {createSkyAtmosphere} from './sky-brightness';
|
|
8
|
+
import type {SkyAtmosphereOptions} from './sky-brightness';
|
|
9
|
+
/** Scattered moonlight luminance, cd/m²; empirical clear-sky model with averaged clouds. */
|
|
10
|
+
export function getScatteredMoonLuminance(
|
|
11
|
+
phaseAngle: number,
|
|
12
|
+
moonAltitude: number,
|
|
13
|
+
viewAltitude: number,
|
|
14
|
+
separation: number,
|
|
15
|
+
options: SkyAtmosphereOptions & {distance?: number; extinction?: number} = {}
|
|
16
|
+
): number {
|
|
17
|
+
validateRange('Phase angle', phaseAngle, 0, Math.PI);
|
|
18
|
+
validateRange('Moon altitude', moonAltitude, -Math.PI / 2, Math.PI / 2);
|
|
19
|
+
validateRange('View altitude', viewAltitude, -Math.PI / 2, Math.PI / 2);
|
|
20
|
+
validateRange('Moon separation', separation, 0, Math.PI);
|
|
21
|
+
const atmosphere = createSkyAtmosphere(options);
|
|
22
|
+
const distance = options.distance ?? 384400;
|
|
23
|
+
validateRange('Moon distance', distance, 1737.4, Number.MAX_VALUE);
|
|
24
|
+
const k =
|
|
25
|
+
options.extinction ??
|
|
26
|
+
1.085736 *
|
|
27
|
+
((0.008735 * 0.55 ** -4.08 * atmosphere.pressure) / 1013.25 + atmosphere.aerosolOpticalDepth);
|
|
28
|
+
validateRange('Extinction', k, 0, 20);
|
|
29
|
+
const radius = Math.asin(1737.4 / distance);
|
|
30
|
+
if (moonAltitude <= -radius || viewAltitude < 0 || phaseAngle === Math.PI) return 0;
|
|
31
|
+
// Original uniform-disk horizon blend; the published model uses center altitude.
|
|
32
|
+
const h = Math.max(-1, Math.min(1, moonAltitude / radius));
|
|
33
|
+
const visibleFraction = (Math.acos(-h) + h * Math.sqrt(1 - h * h)) / Math.PI;
|
|
34
|
+
const degrees = (phaseAngle * 180) / Math.PI;
|
|
35
|
+
const brightness =
|
|
36
|
+
Math.min(
|
|
37
|
+
10 ** (-0.4 * (0.026 * degrees + 4e-9 * degrees ** 4)),
|
|
38
|
+
(1 + Math.cos(phaseAngle)) / 2
|
|
39
|
+
) *
|
|
40
|
+
10 ** (-0.4 * 3.84);
|
|
41
|
+
const rho = Math.max(0.25, (separation * 180) / Math.PI);
|
|
42
|
+
const scattering =
|
|
43
|
+
10 ** 5.36 * (1.06 + Math.cos(separation) ** 2) +
|
|
44
|
+
(rho < 10 ? 6.2e7 / rho ** 2 : 10 ** (6.15 - rho / 40));
|
|
45
|
+
// Scattering air mass is the paper's Eq. 3, deliberately distinct from
|
|
46
|
+
// direct-beam Kasten–Young air mass: different emitting height distributions.
|
|
47
|
+
const x = (altitude: number) => 1 / Math.sqrt(1 - 0.96 * Math.cos(altitude) ** 2);
|
|
48
|
+
const clouds =
|
|
49
|
+
1 -
|
|
50
|
+
atmosphere.cloudCover +
|
|
51
|
+
atmosphere.cloudCover *
|
|
52
|
+
Math.exp(-atmosphere.cloudOpticalDepth / Math.max(0.05, Math.sin(moonAltitude)));
|
|
53
|
+
return (
|
|
54
|
+
(scattering *
|
|
55
|
+
brightness *
|
|
56
|
+
10 ** (-0.4 * k * x(moonAltitude)) *
|
|
57
|
+
(1 - 10 ** (-0.4 * k * x(viewAltitude))) *
|
|
58
|
+
(384400 / distance) ** 2 *
|
|
59
|
+
clouds *
|
|
60
|
+
visibleFraction *
|
|
61
|
+
1e-5) /
|
|
62
|
+
Math.PI
|
|
63
|
+
);
|
|
64
|
+
}
|
package/src/sun/moon.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: BSD-2-Clause
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileCopyrightText: 2011-2015 Vladimir Agafonkin
|
|
5
|
+
// SPDX-FileCopyrightText: 2014 Vladimir Agafonkin
|
|
6
|
+
// SPDX-FileComment: Adapted from SunCalc 1.9.0 with topocentric parallax and USNO sidereal time; full copyright, conditions and disclaimer in ../../sun/LICENSE-SUNCALC.
|
|
7
|
+
// Reference: https://github.com/mourner/suncalc/tree/v1.9.0
|
|
8
|
+
import {getAzimuth, getDeclination, getRightAscension, getSunCoords, toDays} from './suncalc';
|
|
9
|
+
import {getLocalSiderealTime} from './starfield';
|
|
10
|
+
import {validateObserver} from './celestial';
|
|
11
|
+
|
|
12
|
+
export type MoonPosition = {
|
|
13
|
+
/** Geometric topocentric altitude in radians, without atmospheric refraction. */
|
|
14
|
+
altitude: number;
|
|
15
|
+
/** Azimuth in radians, measured from south towards west (same as getSunPosition). */
|
|
16
|
+
azimuth: number;
|
|
17
|
+
/** Observer-to-Moon distance in kilometers, with spherical-Earth parallax correction. */
|
|
18
|
+
distance: number;
|
|
19
|
+
/** Approximate parallactic angle in radians. */
|
|
20
|
+
parallacticAngle: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type MoonIllumination = {
|
|
24
|
+
/** Illuminated fraction of the lunar disk, in [0, 1]. Not relative light intensity. */
|
|
25
|
+
fraction: number;
|
|
26
|
+
/** Cycle position: 0 = new, 0.25 = first quarter, 0.5 = full, 0.75 = last quarter. */
|
|
27
|
+
phase: number;
|
|
28
|
+
/** Bright-limb position angle in radians. */
|
|
29
|
+
angle: number;
|
|
30
|
+
/** Sun-Moon-Earth phase angle in radians: 0 = full, PI = new. */
|
|
31
|
+
phaseAngle: number;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** Low-order lunar ephemeris with spherical-Earth observer parallax. */
|
|
35
|
+
export function getMoonPosition(
|
|
36
|
+
timestamp: number | Date,
|
|
37
|
+
latitude: number,
|
|
38
|
+
longitude: number
|
|
39
|
+
): MoonPosition {
|
|
40
|
+
validateObserver(timestamp, latitude, longitude);
|
|
41
|
+
const phi = (latitude * Math.PI) / 180;
|
|
42
|
+
const moon = getMoonCoords(toDays(timestamp));
|
|
43
|
+
const hourAngle = getLocalSiderealTime(timestamp, longitude) - moon.rightAscension;
|
|
44
|
+
const altitudeSine =
|
|
45
|
+
Math.sin(phi) * Math.sin(moon.declination) +
|
|
46
|
+
Math.cos(phi) * Math.cos(moon.declination) * Math.cos(hourAngle);
|
|
47
|
+
const geocentricAltitude = Math.asin(Math.max(-1, Math.min(1, altitudeSine)));
|
|
48
|
+
const horizontal = moon.distance * Math.cos(geocentricAltitude);
|
|
49
|
+
const vertical = moon.distance * Math.sin(geocentricAltitude) - 6378.14;
|
|
50
|
+
return {
|
|
51
|
+
azimuth: getAzimuth(hourAngle, phi, moon.declination),
|
|
52
|
+
altitude: Math.atan2(vertical, horizontal),
|
|
53
|
+
distance: Math.hypot(horizontal, vertical),
|
|
54
|
+
parallacticAngle: Math.atan2(
|
|
55
|
+
Math.sin(hourAngle),
|
|
56
|
+
Math.tan(phi) * Math.cos(moon.declination) - Math.sin(moon.declination) * Math.cos(hourAngle)
|
|
57
|
+
)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Incoming light direction in east/north/up coordinates, matching getSunDirection. */
|
|
62
|
+
export function getMoonDirection(
|
|
63
|
+
timestamp: number | Date,
|
|
64
|
+
latitude: number,
|
|
65
|
+
longitude: number
|
|
66
|
+
): number[] {
|
|
67
|
+
const {azimuth, altitude} = getMoonPosition(timestamp, latitude, longitude);
|
|
68
|
+
return [
|
|
69
|
+
Math.sin(azimuth) * Math.cos(altitude),
|
|
70
|
+
Math.cos(azimuth) * Math.cos(altitude),
|
|
71
|
+
-Math.sin(altitude)
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function getMoonIllumination(timestamp: number | Date): MoonIllumination {
|
|
76
|
+
validateObserver(timestamp, 0, 0);
|
|
77
|
+
const days = toDays(timestamp);
|
|
78
|
+
const sun = getSunCoords(days);
|
|
79
|
+
const moon = getMoonCoords(days);
|
|
80
|
+
const separationCosine =
|
|
81
|
+
Math.sin(sun.declination) * Math.sin(moon.declination) +
|
|
82
|
+
Math.cos(sun.declination) *
|
|
83
|
+
Math.cos(moon.declination) *
|
|
84
|
+
Math.cos(sun.rightAscension - moon.rightAscension);
|
|
85
|
+
const separation = Math.acos(Math.max(-1, Math.min(1, separationCosine)));
|
|
86
|
+
const sunDistance = 149598000;
|
|
87
|
+
const phaseAngle = Math.atan2(
|
|
88
|
+
sunDistance * Math.sin(separation),
|
|
89
|
+
moon.distance - sunDistance * Math.cos(separation)
|
|
90
|
+
);
|
|
91
|
+
const angle = Math.atan2(
|
|
92
|
+
Math.cos(sun.declination) * Math.sin(sun.rightAscension - moon.rightAscension),
|
|
93
|
+
Math.sin(sun.declination) * Math.cos(moon.declination) -
|
|
94
|
+
Math.cos(sun.declination) *
|
|
95
|
+
Math.sin(moon.declination) *
|
|
96
|
+
Math.cos(sun.rightAscension - moon.rightAscension)
|
|
97
|
+
);
|
|
98
|
+
return {
|
|
99
|
+
fraction: (1 + Math.cos(phaseAngle)) / 2,
|
|
100
|
+
phase: 0.5 + (0.5 * phaseAngle * (angle < 0 ? -1 : 1)) / Math.PI,
|
|
101
|
+
angle,
|
|
102
|
+
phaseAngle
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function getMoonCoords(days: number): {
|
|
107
|
+
rightAscension: number;
|
|
108
|
+
declination: number;
|
|
109
|
+
distance: number;
|
|
110
|
+
} {
|
|
111
|
+
const radians = Math.PI / 180;
|
|
112
|
+
const meanLongitude = radians * (218.316 + 13.176396 * days);
|
|
113
|
+
const anomaly = radians * (134.963 + 13.064993 * days);
|
|
114
|
+
const argumentOfLatitude = radians * (93.272 + 13.22935 * days);
|
|
115
|
+
const longitude = meanLongitude + radians * 6.289 * Math.sin(anomaly);
|
|
116
|
+
const latitude = radians * 5.128 * Math.sin(argumentOfLatitude);
|
|
117
|
+
return {
|
|
118
|
+
rightAscension: getRightAscension(longitude, latitude),
|
|
119
|
+
declination: getDeclination(longitude, latitude),
|
|
120
|
+
distance: 385001 - 20905 * Math.cos(anomaly)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileComment: Independently implemented equations, not copied reference code:
|
|
5
|
+
// Krisciunas & Schaefer (1991), Equation 9: https://doi.org/10.1086/132921
|
|
6
|
+
// Kasten & Young (1989): https://doi.org/10.1364/AO.28.004735
|
|
7
|
+
import {validateRange} from './celestial';
|
|
8
|
+
|
|
9
|
+
export type MoonLightOptions = {
|
|
10
|
+
/** Lunar phase angle in radians: 0 full, PI new. Default 0. */
|
|
11
|
+
phaseAngle?: number;
|
|
12
|
+
/** Observer-to-Moon distance in kilometers. Default 384400. Must be at least the lunar radius. */
|
|
13
|
+
distance?: number;
|
|
14
|
+
/** Aerosol optical depth at 550 nm. Default 0.1. */
|
|
15
|
+
aerosolOpticalDepth?: number;
|
|
16
|
+
/** Atmospheric pressure in hPa. Default 1013.25. */
|
|
17
|
+
pressure?: number;
|
|
18
|
+
/** Averaged cloud coverage in [0, 1]. Default 0. */
|
|
19
|
+
cloudCover?: number;
|
|
20
|
+
/** Vertical cloud optical depth, nonnegative. Default 10. */
|
|
21
|
+
cloudOpticalDepth?: number;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type MoonLight = {
|
|
25
|
+
/** Normalized linear RGB, not gamma-encoded. */
|
|
26
|
+
color: [number, number, number];
|
|
27
|
+
/** Relative to unattenuated full moon at 384400 km; not the sunlight intensity scale. */
|
|
28
|
+
intensity: number;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** Direct moonlight approximation: phase law, distance, atmospheric extinction and clouds. */
|
|
32
|
+
export function getMoonLight(altitude: number, options: MoonLightOptions = {}): MoonLight {
|
|
33
|
+
const {
|
|
34
|
+
phaseAngle = 0,
|
|
35
|
+
distance = 384400,
|
|
36
|
+
aerosolOpticalDepth = 0.1,
|
|
37
|
+
pressure = 1013.25,
|
|
38
|
+
cloudCover = 0,
|
|
39
|
+
cloudOpticalDepth = 10
|
|
40
|
+
} = options;
|
|
41
|
+
validateRange('Moon altitude', altitude, -Math.PI / 2, Math.PI / 2);
|
|
42
|
+
validateRange('Phase angle', phaseAngle, 0, Math.PI);
|
|
43
|
+
validateRange('Moon distance', distance, 1737.4, Number.MAX_VALUE);
|
|
44
|
+
validateRange('Aerosol optical depth', aerosolOpticalDepth, 0, Number.MAX_VALUE);
|
|
45
|
+
validateRange('Pressure', pressure, 0, 1100);
|
|
46
|
+
validateRange('Cloud cover', cloudCover, 0, 1);
|
|
47
|
+
validateRange('Cloud optical depth', cloudOpticalDepth, 0, Number.MAX_VALUE);
|
|
48
|
+
const radius = Math.asin(1737.4 / distance);
|
|
49
|
+
if (altitude <= -radius || phaseAngle === Math.PI) return {color: [0, 0, 0], intensity: 0};
|
|
50
|
+
const phaseDegrees = (phaseAngle * 180) / Math.PI;
|
|
51
|
+
const magnitudeDifference = 0.026 * phaseDegrees + 4e-9 * Math.pow(phaseDegrees, 4);
|
|
52
|
+
// The empirical phase law is unreliable at extreme crescents. Cap by illuminated area
|
|
53
|
+
// to give a continuous zero at new moon; this cap is an additional rendering approximation.
|
|
54
|
+
const phaseBrightness = Math.min(
|
|
55
|
+
Math.pow(10, -0.4 * magnitudeDifference),
|
|
56
|
+
(1 + Math.cos(phaseAngle)) / 2
|
|
57
|
+
);
|
|
58
|
+
const elevation = Math.max(0, altitude);
|
|
59
|
+
const airMass =
|
|
60
|
+
1 / (Math.sin(elevation) + 0.50572 * Math.pow((elevation * 180) / Math.PI + 6.07995, -1.6364));
|
|
61
|
+
const diskHeight = Math.min(1, altitude / radius);
|
|
62
|
+
const visibility =
|
|
63
|
+
(Math.acos(-diskHeight) + diskHeight * Math.sqrt(1 - diskHeight * diskHeight)) / Math.PI;
|
|
64
|
+
const cloudTransmission =
|
|
65
|
+
1 -
|
|
66
|
+
cloudCover +
|
|
67
|
+
cloudCover * Math.exp(-cloudOpticalDepth / Math.max(0.05, Math.sin(elevation)));
|
|
68
|
+
const scale = phaseBrightness * Math.pow(384400 / distance, 2) * visibility * cloudTransmission;
|
|
69
|
+
// Neutral extraterrestrial moonlight, three representative wavelengths in micrometers.
|
|
70
|
+
// Atmospheric warming is approximate; lunar reflectance and scotopic perception are omitted.
|
|
71
|
+
const channels = [0.68, 0.55, 0.44].map(
|
|
72
|
+
wavelength =>
|
|
73
|
+
scale *
|
|
74
|
+
Math.exp(
|
|
75
|
+
-airMass *
|
|
76
|
+
((0.008735 * Math.pow(wavelength, -4.08) * pressure) / 1013.25 +
|
|
77
|
+
aerosolOpticalDepth * Math.pow(wavelength / 0.55, -1.3))
|
|
78
|
+
)
|
|
79
|
+
);
|
|
80
|
+
const intensity = Math.max(...channels);
|
|
81
|
+
return {
|
|
82
|
+
color:
|
|
83
|
+
intensity > 0
|
|
84
|
+
? [channels[0] / intensity, channels[1] / intensity, channels[2] / intensity]
|
|
85
|
+
: [0, 0, 0],
|
|
86
|
+
intensity
|
|
87
|
+
};
|
|
88
|
+
}
|