@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
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileComment: Independently implemented published equations; no reference code copied.
|
|
5
|
+
// Patat et al. (2006), V-band twilight fit, Table 1: https://arxiv.org/abs/astro-ph/0604128
|
|
6
|
+
// Crumey (2014), Blackwell contrast thresholds: https://arxiv.org/abs/1405.4209
|
|
7
|
+
// Kasten & Young (1989): https://doi.org/10.1364/AO.28.004735
|
|
8
|
+
import {validateRange} from './celestial';
|
|
9
|
+
|
|
10
|
+
export type SkyAtmosphereOptions = {
|
|
11
|
+
/** Pressure in hPa. Default 1013.25. */
|
|
12
|
+
pressure?: number;
|
|
13
|
+
/** Aerosol optical depth at 550 nm. Default 0.1. */
|
|
14
|
+
aerosolOpticalDepth?: number;
|
|
15
|
+
cloudCover?: number;
|
|
16
|
+
cloudOpticalDepth?: number;
|
|
17
|
+
/** Natural zenith night-sky luminance, cd/m². Default 0.0002. */
|
|
18
|
+
darkSkyLuminance?: number;
|
|
19
|
+
/** Additional artificial sky luminance, cd/m². Default 0. */
|
|
20
|
+
lightPollutionLuminance?: number;
|
|
21
|
+
};
|
|
22
|
+
export function createSkyAtmosphere(options: SkyAtmosphereOptions = {}) {
|
|
23
|
+
const {
|
|
24
|
+
pressure = 1013.25,
|
|
25
|
+
aerosolOpticalDepth = 0.1,
|
|
26
|
+
cloudCover = 0,
|
|
27
|
+
cloudOpticalDepth = 10,
|
|
28
|
+
darkSkyLuminance = 0.0002,
|
|
29
|
+
lightPollutionLuminance = 0
|
|
30
|
+
} = options;
|
|
31
|
+
const atmosphere = {
|
|
32
|
+
pressure,
|
|
33
|
+
aerosolOpticalDepth,
|
|
34
|
+
cloudCover,
|
|
35
|
+
cloudOpticalDepth,
|
|
36
|
+
darkSkyLuminance,
|
|
37
|
+
lightPollutionLuminance
|
|
38
|
+
};
|
|
39
|
+
validateRange('Pressure', atmosphere.pressure, 0, 1100);
|
|
40
|
+
validateRange('Aerosol optical depth', atmosphere.aerosolOpticalDepth, 0, 10);
|
|
41
|
+
validateRange('Cloud cover', atmosphere.cloudCover, 0, 1);
|
|
42
|
+
validateRange('Cloud optical depth', atmosphere.cloudOpticalDepth, 0, 1000);
|
|
43
|
+
validateRange('Dark sky luminance', atmosphere.darkSkyLuminance, 0, 100);
|
|
44
|
+
validateRange('Light pollution luminance', atmosphere.lightPollutionLuminance, 0, 100);
|
|
45
|
+
return Object.freeze(atmosphere);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Relative optical air mass; finite horizon value, geometric altitude in radians. */
|
|
49
|
+
export function getSkyAirMass(altitude: number): number {
|
|
50
|
+
validateRange('Altitude', altitude, -Math.PI / 2, Math.PI / 2);
|
|
51
|
+
const a = Math.max(0, altitude);
|
|
52
|
+
return 1 / (Math.sin(a) + 0.50572 * Math.pow((a * 180) / Math.PI + 6.07995, -1.6364));
|
|
53
|
+
}
|
|
54
|
+
/** V-band direct transmission; opaque partial coverage is averaged, not a weather map. */
|
|
55
|
+
export function getSkyTransmission(altitude: number, options: SkyAtmosphereOptions = {}): number {
|
|
56
|
+
const a = createSkyAtmosphere(options);
|
|
57
|
+
const tau = (0.008735 * Math.pow(0.55, -4.08) * a.pressure) / 1013.25 + a.aerosolOpticalDepth;
|
|
58
|
+
return (
|
|
59
|
+
Math.exp(-getSkyAirMass(altitude) * tau) *
|
|
60
|
+
(1 -
|
|
61
|
+
a.cloudCover +
|
|
62
|
+
a.cloudCover * Math.exp(-a.cloudOpticalDepth / Math.max(0.05, Math.sin(altitude))))
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Directional sky luminance in cd/m². Twilight zenith fit is measured; daylight,
|
|
68
|
+
* glare, haze, clouds and non-zenith extrapolations are rendering approximations.
|
|
69
|
+
*/
|
|
70
|
+
export function getSkyLuminance(
|
|
71
|
+
sunAltitude: number,
|
|
72
|
+
viewAltitude: number,
|
|
73
|
+
sunSeparation: number,
|
|
74
|
+
options: SkyAtmosphereOptions = {}
|
|
75
|
+
): number {
|
|
76
|
+
validateRange('Sun altitude', sunAltitude, -Math.PI / 2, Math.PI / 2);
|
|
77
|
+
validateRange('View altitude', viewAltitude, -Math.PI / 2, Math.PI / 2);
|
|
78
|
+
validateRange('Sun separation', sunSeparation, 0, Math.PI);
|
|
79
|
+
const a = createSkyAtmosphere(options);
|
|
80
|
+
const degrees = (sunAltitude * 180) / Math.PI;
|
|
81
|
+
if (a.pressure === 0) return a.darkSkyLuminance + a.lightPollutionLuminance;
|
|
82
|
+
const fit = (depression: number) =>
|
|
83
|
+
(Math.pow(
|
|
84
|
+
10,
|
|
85
|
+
(12.58 - (11.84 + 1.518 * (depression - 5) - 0.057 * Math.pow(depression - 5, 2))) / 2.5
|
|
86
|
+
) *
|
|
87
|
+
a.pressure) /
|
|
88
|
+
743;
|
|
89
|
+
let zenith: number;
|
|
90
|
+
if (degrees >= -5) {
|
|
91
|
+
// Smoothly connect the measured -5° twilight luminance to an approximate
|
|
92
|
+
// clear daytime zenith. Do not extrapolate the quadratic into daylight.
|
|
93
|
+
zenith = fit(5) * Math.exp(((degrees + 5) * Math.log(3000 / fit(5))) / 5);
|
|
94
|
+
if (degrees > 0) zenith = 3000 + 7000 * Math.sin(sunAltitude);
|
|
95
|
+
} else if (degrees >= -15) zenith = fit(-degrees);
|
|
96
|
+
else {
|
|
97
|
+
const t = Math.min(1, (-degrees - 15) / 3);
|
|
98
|
+
const smooth = t * t * (3 - 2 * t);
|
|
99
|
+
zenith = fit(15) * (1 - smooth) + a.darkSkyLuminance * smooth;
|
|
100
|
+
}
|
|
101
|
+
const night = a.darkSkyLuminance + a.lightPollutionLuminance;
|
|
102
|
+
const daylightWeight = Math.max(0, Math.min(1, (degrees + 15) / 10));
|
|
103
|
+
// Forward-scattering lobe, normalized at the zenith for this solar altitude.
|
|
104
|
+
const g = 0.8;
|
|
105
|
+
const phase = (angle: number) => (1 - g * g) / Math.pow(1 + g * g - 2 * g * Math.cos(angle), 1.5);
|
|
106
|
+
const scattering = (angle: number) =>
|
|
107
|
+
1 + Math.cos(angle) ** 2 + 0.1 * (1 + a.aerosolOpticalDepth * 10) * phase(angle);
|
|
108
|
+
const directional = scattering(sunSeparation) / scattering(Math.PI / 2 - sunAltitude);
|
|
109
|
+
const horizon = 1 + daylightWeight * Math.max(0, getSkyAirMass(viewAltitude) - 1) * 0.08;
|
|
110
|
+
const clear =
|
|
111
|
+
night +
|
|
112
|
+
Math.max(0, zenith - a.darkSkyLuminance) *
|
|
113
|
+
(1 - daylightWeight + daylightWeight * directional) *
|
|
114
|
+
horizon;
|
|
115
|
+
const cloudTransmission = 1 / (1 + 0.12 * a.cloudOpticalDepth);
|
|
116
|
+
// Cloud-covered sky is more isotropic; artificial light is reflected back.
|
|
117
|
+
const cloudy =
|
|
118
|
+
a.darkSkyLuminance +
|
|
119
|
+
a.lightPollutionLuminance * (1 + a.cloudOpticalDepth * 0.1) +
|
|
120
|
+
Math.max(0, zenith - a.darkSkyLuminance) * cloudTransmission;
|
|
121
|
+
return clear * (1 - a.cloudCover) + cloudy * a.cloudCover;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Crumey/Blackwell threshold for a uniform extended target of solid angle in sr. */
|
|
125
|
+
export function getSkyContrastThreshold(
|
|
126
|
+
backgroundLuminance: number,
|
|
127
|
+
solidAngle: number,
|
|
128
|
+
observerFactor = 2
|
|
129
|
+
): number {
|
|
130
|
+
validateRange('Background luminance', backgroundLuminance, 0, Number.MAX_VALUE);
|
|
131
|
+
validateRange('Solid angle', solidAngle, Number.MIN_VALUE, 4 * Math.PI);
|
|
132
|
+
validateRange('Observer factor', observerFactor, 1, 100);
|
|
133
|
+
const b = Math.max(1e-5, backgroundLuminance);
|
|
134
|
+
const r =
|
|
135
|
+
b <= 0.0708
|
|
136
|
+
? Math.pow(6.505e-4 * Math.pow(b, -0.25) - 8.461e-4, 2)
|
|
137
|
+
: Math.pow(1.772e-4 * Math.pow(b, -0.25) + 7.167e-5, 2);
|
|
138
|
+
const largeTarget = b < 0.354 ? 7.633e-3 * Math.pow(b, -0.25) - 7.174e-3 : 2.72e-3;
|
|
139
|
+
const q =
|
|
140
|
+
b < 0.193 ? 0.6 : b < 3.4 ? 0.8861 + 0.4 * Math.log10(b) : 1.146 - 0.0885 * Math.log10(b);
|
|
141
|
+
// The empirical q fit covers terrestrial sky backgrounds, not arbitrarily
|
|
142
|
+
// luminous sources; cap to its positive range for finite numerical behavior.
|
|
143
|
+
const exponent = Math.max(0.2, q);
|
|
144
|
+
return (
|
|
145
|
+
observerFactor *
|
|
146
|
+
Math.pow(Math.pow(r / solidAngle, exponent) + Math.pow(largeTarget, exponent), 1 / exponent)
|
|
147
|
+
);
|
|
148
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileComment: Original bounded sampling and adaptive transition refinement.
|
|
5
|
+
import {validateRange} from './celestial';
|
|
6
|
+
/** Search any continuous visibility predicate, including Moon contrast or a terrain horizon. */
|
|
7
|
+
export function searchSkyVisibility(
|
|
8
|
+
start: number | Date,
|
|
9
|
+
end: number | Date,
|
|
10
|
+
visible: (timestamp: number) => boolean,
|
|
11
|
+
options: {sampleSeconds?: number; transitionSeconds?: number} = {}
|
|
12
|
+
) {
|
|
13
|
+
const first = new Date(start).getTime(),
|
|
14
|
+
last = new Date(end).getTime();
|
|
15
|
+
validateRange('Start time', first, -8.64e15, 8.64e15);
|
|
16
|
+
validateRange('End time', last, first + 1, 8.64e15);
|
|
17
|
+
const sampleSeconds = options.sampleSeconds ?? 30;
|
|
18
|
+
const transitionSeconds = options.transitionSeconds ?? 1;
|
|
19
|
+
validateRange('Sample seconds', sampleSeconds, 0.1, 3600);
|
|
20
|
+
validateRange('Transition seconds', transitionSeconds, 0.001, sampleSeconds);
|
|
21
|
+
if ((last - first) / (sampleSeconds * 1000) > 100000)
|
|
22
|
+
throw new RangeError('Search would exceed 100000 samples');
|
|
23
|
+
const intervals: {start: number; end: number; startClipped: boolean; endClipped: boolean}[] = [];
|
|
24
|
+
const cache = new Map<number, boolean>();
|
|
25
|
+
const at = (time: number) => {
|
|
26
|
+
if (!cache.has(time)) {
|
|
27
|
+
const state = visible(time);
|
|
28
|
+
if (typeof state !== 'boolean')
|
|
29
|
+
throw new TypeError('Visibility predicate must return boolean');
|
|
30
|
+
cache.set(time, state);
|
|
31
|
+
}
|
|
32
|
+
return cache.get(time)!;
|
|
33
|
+
};
|
|
34
|
+
let time = first,
|
|
35
|
+
state = at(first),
|
|
36
|
+
active: number | null = state ? first : null;
|
|
37
|
+
while (time < last) {
|
|
38
|
+
const next = Math.min(last, time + sampleSeconds * 1000),
|
|
39
|
+
after = at(next);
|
|
40
|
+
if (state !== after) {
|
|
41
|
+
let lower = time,
|
|
42
|
+
upper = next;
|
|
43
|
+
while (upper - lower > transitionSeconds * 1000) {
|
|
44
|
+
const middle = (lower + upper) / 2;
|
|
45
|
+
if (at(middle) === state) lower = middle;
|
|
46
|
+
else upper = middle;
|
|
47
|
+
}
|
|
48
|
+
const transition = (lower + upper) / 2;
|
|
49
|
+
if (after) active = transition;
|
|
50
|
+
else {
|
|
51
|
+
intervals.push({
|
|
52
|
+
start: active!,
|
|
53
|
+
end: transition,
|
|
54
|
+
startClipped: active === first,
|
|
55
|
+
endClipped: false
|
|
56
|
+
});
|
|
57
|
+
active = null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
time = next;
|
|
61
|
+
state = after;
|
|
62
|
+
}
|
|
63
|
+
if (active !== null)
|
|
64
|
+
intervals.push({start: active, end: last, startClipped: active === first, endClipped: true});
|
|
65
|
+
return {intervals, evaluations: cache.size, sampleSeconds, transitionSeconds};
|
|
66
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileComment: Original spherical coordinate transforms, compatible with deck.gl GlobeViewport.
|
|
5
|
+
// Frame/scale reference (MIT): https://github.com/visgl/deck.gl/blob/master/modules/core/src/viewports/globe-viewport.ts
|
|
6
|
+
import {createSkyObserver, reverseSkyDirection} from './sky-observer';
|
|
7
|
+
import type {SkyObserver} from './sky-observer';
|
|
8
|
+
import {validateRange} from './celestial';
|
|
9
|
+
|
|
10
|
+
/** deck.gl's spherical Earth radius in meters; this is not the WGS84 ellipsoid. */
|
|
11
|
+
export const SKY_GLOBE_EARTH_RADIUS = 6370972;
|
|
12
|
+
/** Column-major rotation from observer ENU to deck.gl globe common-space axes. */
|
|
13
|
+
export function getSkyGlobeRotation(observer: SkyObserver): number[] {
|
|
14
|
+
const {latitude, longitude} = createSkyObserver(observer);
|
|
15
|
+
const phi = (latitude * Math.PI) / 180;
|
|
16
|
+
const lambda = (longitude * Math.PI) / 180;
|
|
17
|
+
const s = Math.sin(lambda),
|
|
18
|
+
c = Math.cos(lambda),
|
|
19
|
+
sp = Math.sin(phi),
|
|
20
|
+
cp = Math.cos(phi);
|
|
21
|
+
// Globe axes: +X at 90°E, -Y at Greenwich, +Z at the north pole.
|
|
22
|
+
return [c, s, 0, -s * sp, c * sp, cp, s * cp, -c * cp, sp];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Rotate an ENU vector (including lighting and ring normals) into globe axes. */
|
|
26
|
+
export function skyDirectionToGlobe(
|
|
27
|
+
direction: readonly number[],
|
|
28
|
+
observer: SkyObserver
|
|
29
|
+
): [number, number, number] {
|
|
30
|
+
reverseSkyDirection(direction); // shared finite/nonzero vector validation
|
|
31
|
+
const m = getSkyGlobeRotation(observer);
|
|
32
|
+
return [0, 1, 2].map(
|
|
33
|
+
row => m[row] * direction[0] + m[row + 3] * direction[1] + m[row + 6] * direction[2]
|
|
34
|
+
) as [number, number, number];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Place a sky object along its observer ray, returning LNGLAT for GlobeView layers.
|
|
39
|
+
* distance is a rendering distance in meters, independent of astronomical distance.
|
|
40
|
+
*/
|
|
41
|
+
export function getSkyGlobePosition(
|
|
42
|
+
direction: readonly number[],
|
|
43
|
+
observer: SkyObserver,
|
|
44
|
+
distance: number
|
|
45
|
+
): [number, number, number] {
|
|
46
|
+
validateRange('Rendering distance', distance, Number.MIN_VALUE, Number.MAX_VALUE);
|
|
47
|
+
const location = createSkyObserver(observer);
|
|
48
|
+
const ray = skyDirectionToGlobe(direction, location);
|
|
49
|
+
const length = Math.hypot(...ray);
|
|
50
|
+
const up = skyDirectionToGlobe([0, 0, 1], location);
|
|
51
|
+
const position = ray.map(
|
|
52
|
+
(value, i) =>
|
|
53
|
+
(value / length) * distance + up[i] * (SKY_GLOBE_EARTH_RADIUS + location.elevation)
|
|
54
|
+
);
|
|
55
|
+
const radius = Math.hypot(...position);
|
|
56
|
+
if (!Number.isFinite(radius) || radius === 0)
|
|
57
|
+
throw new RangeError('Sky position must have finite nonzero radius');
|
|
58
|
+
return [
|
|
59
|
+
(Math.atan2(position[0], -position[1]) * 180) / Math.PI,
|
|
60
|
+
(Math.atan2(position[2], Math.hypot(position[0], position[1])) * 180) / Math.PI,
|
|
61
|
+
radius - SKY_GLOBE_EARTH_RADIUS
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Rotate a column-major ENU orientation (e.g. starfieldRotation) into globe axes. */
|
|
66
|
+
export function skyRotationToGlobe(rotation: readonly number[], observer: SkyObserver): number[] {
|
|
67
|
+
if (rotation.length !== 9 || rotation.some(value => !Number.isFinite(value)))
|
|
68
|
+
throw new RangeError('Rotation must contain nine finite values');
|
|
69
|
+
return [0, 3, 6].flatMap(offset =>
|
|
70
|
+
skyDirectionToGlobe(rotation.slice(offset, offset + 3), observer)
|
|
71
|
+
);
|
|
72
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileComment: Original photometric composition; derived solar data attribution in ../../sun/LICENSE-HOSEK-WILKIE.
|
|
5
|
+
import {getSunLight} from './sunlight';
|
|
6
|
+
import {getMoonLight} from './moonlight';
|
|
7
|
+
import {getMoonAppearance} from './moon-appearance';
|
|
8
|
+
import {createSkyAtmosphere, getSkyLuminance} from './sky-brightness';
|
|
9
|
+
import type {SkyAtmosphereOptions} from './sky-brightness';
|
|
10
|
+
import {SUNLIGHT_DATA} from './data/sunlight';
|
|
11
|
+
import {getScatteredMoonLuminance} from './moon-sky-brightness';
|
|
12
|
+
|
|
13
|
+
export type SkyLightingOptions = SkyAtmosphereOptions & {
|
|
14
|
+
moonPhaseAngle: number;
|
|
15
|
+
moonDistance?: number;
|
|
16
|
+
moonSunSeparation: number;
|
|
17
|
+
};
|
|
18
|
+
/** Shared weather with explicit photometric units; diffuse twilight stays continuous. */
|
|
19
|
+
export function getSkyLighting(
|
|
20
|
+
sunAltitude: number,
|
|
21
|
+
moonAltitude: number,
|
|
22
|
+
options: SkyLightingOptions
|
|
23
|
+
) {
|
|
24
|
+
const atmosphere = createSkyAtmosphere(options);
|
|
25
|
+
// Rendering mapping from aerosol optical depth to lookup turbidity, not Linke turbidity.
|
|
26
|
+
const sunlight = getSunLight(sunAltitude, {
|
|
27
|
+
turbidity: Math.min(10, 1 + 20 * atmosphere.aerosolOpticalDepth),
|
|
28
|
+
cloudCover: atmosphere.cloudCover,
|
|
29
|
+
cloudOpticalDepth: atmosphere.cloudOpticalDepth
|
|
30
|
+
});
|
|
31
|
+
const moonlight = getMoonLight(moonAltitude, {
|
|
32
|
+
...atmosphere,
|
|
33
|
+
phaseAngle: options.moonPhaseAngle,
|
|
34
|
+
distance: options.moonDistance
|
|
35
|
+
});
|
|
36
|
+
const appearance = getMoonAppearance(moonAltitude, sunAltitude, {
|
|
37
|
+
...atmosphere,
|
|
38
|
+
phaseAngle: options.moonPhaseAngle,
|
|
39
|
+
distance: options.moonDistance,
|
|
40
|
+
sunSeparation: options.moonSunSeparation
|
|
41
|
+
});
|
|
42
|
+
const reference = Math.max(...SUNLIGHT_DATA[0][90].slice(0, 3));
|
|
43
|
+
const directSunIlluminance =
|
|
44
|
+
sunlight.intensity *
|
|
45
|
+
reference *
|
|
46
|
+
683 *
|
|
47
|
+
(0.2126 * sunlight.color[0] + 0.7152 * sunlight.color[1] + 0.0722 * sunlight.color[2]);
|
|
48
|
+
// Hemisphere integral of directional luminance with projected solid angle.
|
|
49
|
+
// Sun is on azimuth zero by rotational symmetry; midpoint quadrature in sin(alt).
|
|
50
|
+
let diffuseSkyIlluminance = 0;
|
|
51
|
+
let diffuseMoonIlluminance = 0;
|
|
52
|
+
for (let i = 0; i < 8; i++) {
|
|
53
|
+
const u = (i + 0.5) / 8;
|
|
54
|
+
const altitude = Math.asin(u);
|
|
55
|
+
for (let j = 0; j < 16; j++) {
|
|
56
|
+
const azimuth = ((j + 0.5) * 2 * Math.PI) / 16;
|
|
57
|
+
const separation = Math.acos(
|
|
58
|
+
Math.max(
|
|
59
|
+
-1,
|
|
60
|
+
Math.min(
|
|
61
|
+
1,
|
|
62
|
+
u * Math.sin(sunAltitude) +
|
|
63
|
+
Math.cos(altitude) * Math.cos(sunAltitude) * Math.cos(azimuth)
|
|
64
|
+
)
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
diffuseSkyIlluminance +=
|
|
68
|
+
(getSkyLuminance(sunAltitude, altitude, separation, atmosphere) * u * 2 * Math.PI) / 128;
|
|
69
|
+
const moonSeparation = Math.acos(
|
|
70
|
+
Math.max(
|
|
71
|
+
-1,
|
|
72
|
+
Math.min(
|
|
73
|
+
1,
|
|
74
|
+
u * Math.sin(moonAltitude) +
|
|
75
|
+
Math.cos(altitude) * Math.cos(moonAltitude) * Math.cos(azimuth)
|
|
76
|
+
)
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
// Lunar integral is rotationally symmetric and can use azimuth zero
|
|
80
|
+
// independently of the solar integral; no Sun/Moon angle reconstruction.
|
|
81
|
+
diffuseMoonIlluminance +=
|
|
82
|
+
(getScatteredMoonLuminance(options.moonPhaseAngle, moonAltitude, altitude, moonSeparation, {
|
|
83
|
+
...atmosphere,
|
|
84
|
+
distance: options.moonDistance
|
|
85
|
+
}) *
|
|
86
|
+
u *
|
|
87
|
+
2 *
|
|
88
|
+
Math.PI) /
|
|
89
|
+
128;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const twilightColor = [0.65, 0.75, 1];
|
|
93
|
+
const daylight = Math.max(0, Math.min(1, ((sunAltitude * 180) / Math.PI + 5) / 5));
|
|
94
|
+
const diffuseSkyColor = twilightColor.map(
|
|
95
|
+
(value, i) =>
|
|
96
|
+
((1 - daylight) * value + daylight * sunlight.diffuse.color[i]) *
|
|
97
|
+
(1 - atmosphere.cloudCover) +
|
|
98
|
+
atmosphere.cloudCover
|
|
99
|
+
) as [number, number, number];
|
|
100
|
+
const peak = Math.max(...diffuseSkyColor);
|
|
101
|
+
return {
|
|
102
|
+
sun: {
|
|
103
|
+
...sunlight,
|
|
104
|
+
illuminance: directSunIlluminance,
|
|
105
|
+
horizontalIlluminance: directSunIlluminance * Math.max(0, Math.sin(sunAltitude))
|
|
106
|
+
},
|
|
107
|
+
moon: {
|
|
108
|
+
...moonlight,
|
|
109
|
+
illuminance: appearance.illuminance,
|
|
110
|
+
horizontalIlluminance: appearance.horizontalIlluminance
|
|
111
|
+
},
|
|
112
|
+
diffuseSkyIlluminance: diffuseSkyIlluminance + diffuseMoonIlluminance,
|
|
113
|
+
diffuseMoonIlluminance,
|
|
114
|
+
// RGB tint is an illustrative rendering approximation, separate from V-band photometry.
|
|
115
|
+
diffuseSkyColor: diffuseSkyColor.map(value => value / peak) as [number, number, number],
|
|
116
|
+
photometricUnits: 'lux' as const
|
|
117
|
+
};
|
|
118
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import {validateRange} from './celestial';
|
|
5
|
+
|
|
6
|
+
/** Shared observer for celestial snapshots, batch calculations and event searches. */
|
|
7
|
+
export type SkyObserver = Readonly<{latitude: number; longitude: number; elevation: number}>;
|
|
8
|
+
export type SkyHorizonProfile = readonly {azimuth: number; altitude: number}[];
|
|
9
|
+
|
|
10
|
+
/** Periodic linear terrain horizon, with azimuth/altitude in radians. Empty means flat. */
|
|
11
|
+
export function getSkyHorizonAltitude(azimuth: number, profile: SkyHorizonProfile = []): number {
|
|
12
|
+
validateRange('Azimuth', azimuth, -Number.MAX_VALUE, Number.MAX_VALUE);
|
|
13
|
+
const tau = 2 * Math.PI;
|
|
14
|
+
const wrap = (angle: number) => ((angle % tau) + tau) % tau;
|
|
15
|
+
const points = profile
|
|
16
|
+
.map(point => {
|
|
17
|
+
validateRange('Horizon azimuth', point.azimuth, -Number.MAX_VALUE, Number.MAX_VALUE);
|
|
18
|
+
validateRange('Horizon altitude', point.altitude, -Math.PI / 2, Math.PI / 2);
|
|
19
|
+
return {azimuth: wrap(point.azimuth), altitude: point.altitude};
|
|
20
|
+
})
|
|
21
|
+
.sort((a, b) => a.azimuth - b.azimuth);
|
|
22
|
+
if (points.length === 0) return 0;
|
|
23
|
+
if (points.length === 1) return points[0].altitude;
|
|
24
|
+
if (points.some((point, i) => i > 0 && point.azimuth === points[i - 1].azimuth))
|
|
25
|
+
throw new RangeError('Horizon azimuths must be distinct modulo 2PI');
|
|
26
|
+
const angle = wrap(azimuth);
|
|
27
|
+
const index = points.findIndex(point => point.azimuth > angle);
|
|
28
|
+
const upper = index < 0 ? {...points[0], azimuth: points[0].azimuth + tau} : points[index];
|
|
29
|
+
const lower =
|
|
30
|
+
index === 0
|
|
31
|
+
? {...points[points.length - 1], azimuth: points[points.length - 1].azimuth - tau}
|
|
32
|
+
: points[index < 0 ? points.length - 1 : index - 1];
|
|
33
|
+
const t = (angle - lower.azimuth) / (upper.azimuth - lower.azimuth);
|
|
34
|
+
return lower.altitude + t * (upper.altitude - lower.altitude);
|
|
35
|
+
}
|
|
36
|
+
export function createSkyObserver(options: {
|
|
37
|
+
latitude: number;
|
|
38
|
+
longitude: number;
|
|
39
|
+
elevation?: number;
|
|
40
|
+
}): SkyObserver {
|
|
41
|
+
const {latitude, longitude, elevation = 0} = options;
|
|
42
|
+
validateRange('Latitude', latitude, -90, 90);
|
|
43
|
+
validateRange('Longitude', longitude, -Number.MAX_VALUE, Number.MAX_VALUE);
|
|
44
|
+
validateRange('Elevation', elevation, -1000, 100000);
|
|
45
|
+
return Object.freeze({latitude, longitude: (((longitude % 360) + 540) % 360) - 180, elevation});
|
|
46
|
+
}
|
|
47
|
+
/** Outward ENU sky vector. Azimuth is radians from south towards west. */
|
|
48
|
+
export function getSkyDirection(altitude: number, azimuth: number): [number, number, number] {
|
|
49
|
+
validateRange('Altitude', altitude, -Math.PI / 2, Math.PI / 2);
|
|
50
|
+
validateRange('Azimuth', azimuth, -Number.MAX_VALUE, Number.MAX_VALUE);
|
|
51
|
+
return [
|
|
52
|
+
-Math.cos(altitude) * Math.sin(azimuth),
|
|
53
|
+
-Math.cos(altitude) * Math.cos(azimuth),
|
|
54
|
+
Math.sin(altitude)
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
/** Convert outward sky direction to incoming illumination, or vice versa. */
|
|
58
|
+
export function reverseSkyDirection(direction: readonly number[]): [number, number, number] {
|
|
59
|
+
if (
|
|
60
|
+
direction.length !== 3 ||
|
|
61
|
+
direction.some(value => !Number.isFinite(value)) ||
|
|
62
|
+
Math.hypot(...direction) === 0
|
|
63
|
+
)
|
|
64
|
+
throw new RangeError('Direction must be a finite nonzero three-vector');
|
|
65
|
+
return [-direction[0], -direction[1], -direction[2]];
|
|
66
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileComment: Original adapter to Astronomy Engine's UT1/TT AstroTime fields (MIT).
|
|
5
|
+
// https://github.com/cosinekitty/astronomy/tree/v2.1.19/source/js
|
|
6
|
+
import {AstroTime, SiderealTime} from 'astronomy-engine';
|
|
7
|
+
import {validateRange} from './celestial';
|
|
8
|
+
export type SkyTimeScales = {
|
|
9
|
+
/** UT1 minus UTC, seconds. Default 0. */
|
|
10
|
+
ut1MinusUtc?: number;
|
|
11
|
+
/** TT minus UTC, seconds. Omit to use Astronomy Engine's delta-T model. */
|
|
12
|
+
ttMinusUtc?: number;
|
|
13
|
+
};
|
|
14
|
+
class SkyTime extends AstroTime {
|
|
15
|
+
/** Preserve explicit TT/UT1 offsets during light-travel iteration. */
|
|
16
|
+
override AddDays(days: number): AstroTime {
|
|
17
|
+
const shifted = new SkyTime(new Date(this.date.getTime() + days * 86400000));
|
|
18
|
+
shifted.ut = this.ut + days;
|
|
19
|
+
shifted.tt = this.tt + days;
|
|
20
|
+
return shifted;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function createSkyTime(timestamp: number | Date, scales: SkyTimeScales = {}): AstroTime {
|
|
24
|
+
const date = new Date(timestamp);
|
|
25
|
+
if (!Number.isFinite(date.getTime())) throw new RangeError('Timestamp must be valid');
|
|
26
|
+
const time = new SkyTime(date);
|
|
27
|
+
const utc = time.ut;
|
|
28
|
+
validateRange('UT1 minus UTC', scales.ut1MinusUtc ?? 0, -10, 10);
|
|
29
|
+
time.ut = utc + (scales.ut1MinusUtc ?? 0) / 86400;
|
|
30
|
+
if (scales.ttMinusUtc !== undefined) {
|
|
31
|
+
validateRange('TT minus UTC', scales.ttMinusUtc, -1000, 1000);
|
|
32
|
+
time.tt = utc + scales.ttMinusUtc / 86400;
|
|
33
|
+
}
|
|
34
|
+
// Astronomy Engine 2.1.19 caches sidereal time by TT alone. Different UT1
|
|
35
|
+
// values at the same TT must invalidate that cache before horizontal work.
|
|
36
|
+
// Use public API calls; no private state or global delta-T model is modified.
|
|
37
|
+
const sentinel = new AstroTime(date);
|
|
38
|
+
sentinel.tt = time.tt + 1;
|
|
39
|
+
SiderealTime(sentinel);
|
|
40
|
+
SiderealTime(time);
|
|
41
|
+
return time;
|
|
42
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileComment: Original implementation of published equations; no reference code copied.
|
|
5
|
+
// Johnston, Spergel & Hernquist (1995), equations 1–3 and parameters in the arXiv draft:
|
|
6
|
+
// https://arxiv.org/abs/astro-ph/9502005 (v_halo = 212 km/s in that draft).
|
|
7
|
+
// Solar peculiar velocity: https://doi.org/10.1111/j.1365-2966.2010.16253.x
|
|
8
|
+
|
|
9
|
+
export const KMS_TO_PC_PER_YEAR = 31557600 / 3.0856775814913673e13;
|
|
10
|
+
const KMS_TO_PC_PER_MYR = KMS_TO_PC_PER_YEAR * 1e6;
|
|
11
|
+
const G = 4.30091727003628e-3 * KMS_TO_PC_PER_MYR ** 2;
|
|
12
|
+
const HALO_V2 = (212 * KMS_TO_PC_PER_MYR) ** 2;
|
|
13
|
+
|
|
14
|
+
/** Illustrative axisymmetric disk/bulge/halo model. Input pc, output pc/Myr². */
|
|
15
|
+
export function getGalacticAcceleration(position: readonly number[]): number[] {
|
|
16
|
+
validateVector(position);
|
|
17
|
+
const [x, y, z] = position;
|
|
18
|
+
const r = Math.hypot(x, y, z);
|
|
19
|
+
const q = Math.hypot(z, 260);
|
|
20
|
+
const u = 6500 + q;
|
|
21
|
+
const disk = (-G * 1e11) / (x * x + y * y + u * u) ** 1.5;
|
|
22
|
+
const bulge = r === 0 ? 0 : (-G * 3.4e10) / (r * (r + 700) ** 2);
|
|
23
|
+
const halo = (-2 * HALO_V2) / (r * r + 12000 ** 2);
|
|
24
|
+
return [
|
|
25
|
+
(disk + bulge + halo) * x,
|
|
26
|
+
(disk + bulge + halo) * y,
|
|
27
|
+
(disk * u * z) / q + (bulge + halo) * z
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Specific potential in pc²/Myr², with an arbitrary halo zero point. */
|
|
32
|
+
export function getGalacticPotential(position: readonly number[]): number {
|
|
33
|
+
validateVector(position);
|
|
34
|
+
const [x, y, z] = position;
|
|
35
|
+
const r = Math.hypot(x, y, z);
|
|
36
|
+
return (
|
|
37
|
+
(-G * 1e11) / Math.hypot(x, y, 6500 + Math.hypot(z, 260)) -
|
|
38
|
+
(G * 3.4e10) / (r + 700) +
|
|
39
|
+
HALO_V2 * Math.log1p((r * r) / 12000 ** 2)
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Time-reversible leapfrog integration. Position pc, velocity pc/Myr, elapsed Julian years. */
|
|
44
|
+
export function integrateGalacticOrbit(
|
|
45
|
+
position: readonly number[],
|
|
46
|
+
velocity: readonly number[],
|
|
47
|
+
years: number,
|
|
48
|
+
maximumStepYears = 10000
|
|
49
|
+
): {position: number[]; velocity: number[]} {
|
|
50
|
+
validateVector(position);
|
|
51
|
+
validateVector(velocity);
|
|
52
|
+
if (
|
|
53
|
+
!Number.isFinite(years) ||
|
|
54
|
+
Math.abs(years) > 1e7 ||
|
|
55
|
+
!Number.isFinite(maximumStepYears) ||
|
|
56
|
+
maximumStepYears <= 0 ||
|
|
57
|
+
maximumStepYears > 10000
|
|
58
|
+
) {
|
|
59
|
+
throw new RangeError(
|
|
60
|
+
'Galactic integration requires |years| <= 10 million and a step in (0, 10000]'
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
const steps = Math.ceil(Math.abs(years) / maximumStepYears);
|
|
64
|
+
if (steps > 100000) throw new RangeError('Galactic integration exceeds 100,000 steps');
|
|
65
|
+
const p = [...position];
|
|
66
|
+
const v = [...velocity];
|
|
67
|
+
if (!steps) return {position: p, velocity: v};
|
|
68
|
+
const dt = years / steps / 1e6;
|
|
69
|
+
let acceleration = getGalacticAcceleration(p);
|
|
70
|
+
for (let step = 0; step < steps; step++) {
|
|
71
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
72
|
+
v[axis] += (acceleration[axis] * dt) / 2;
|
|
73
|
+
p[axis] += v[axis] * dt;
|
|
74
|
+
}
|
|
75
|
+
acceleration = getGalacticAcceleration(p);
|
|
76
|
+
for (let axis = 0; axis < 3; axis++) v[axis] += (acceleration[axis] * dt) / 2;
|
|
77
|
+
}
|
|
78
|
+
return {position: p, velocity: v};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// IAU J2000 Galactic pole and ascending node; constructed from defining angles.
|
|
82
|
+
// https://doi.org/10.1051/0004-6361/201014961 (Liu, Zhu & Zhang 2011, eq. 2).
|
|
83
|
+
const ra = (192.85948 * Math.PI) / 180;
|
|
84
|
+
const dec = (27.12825 * Math.PI) / 180;
|
|
85
|
+
const node = (32.93192 * Math.PI) / 180;
|
|
86
|
+
const pole = [Math.cos(dec) * Math.cos(ra), Math.cos(dec) * Math.sin(ra), Math.sin(dec)];
|
|
87
|
+
const east = [-Math.sin(ra), Math.cos(ra), 0];
|
|
88
|
+
const north = [-Math.sin(dec) * Math.cos(ra), -Math.sin(dec) * Math.sin(ra), Math.cos(dec)];
|
|
89
|
+
const basis = [
|
|
90
|
+
east.map((v, i) => v * Math.cos(node) - north[i] * Math.sin(node)),
|
|
91
|
+
east.map((v, i) => v * Math.sin(node) + north[i] * Math.cos(node)),
|
|
92
|
+
pole
|
|
93
|
+
];
|
|
94
|
+
export function equatorialToGalactic(vector: readonly number[]): number[] {
|
|
95
|
+
return basis.map(row => row.reduce((sum, v, i) => sum + v * vector[i], 0));
|
|
96
|
+
}
|
|
97
|
+
export function galacticToEquatorial(vector: readonly number[]): number[] {
|
|
98
|
+
return [0, 1, 2].map(i => basis.reduce((sum, row, j) => sum + row[i] * vector[j], 0));
|
|
99
|
+
}
|
|
100
|
+
export const SOLAR_POSITION = [-8000, 0, 20];
|
|
101
|
+
const circularVelocity = Math.sqrt(-getGalacticAcceleration([-8000, 0, 0])[0] * -8000);
|
|
102
|
+
export const SOLAR_VELOCITY = [
|
|
103
|
+
11.1 * KMS_TO_PC_PER_MYR,
|
|
104
|
+
circularVelocity + 12.24 * KMS_TO_PC_PER_MYR,
|
|
105
|
+
7.25 * KMS_TO_PC_PER_MYR
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
function validateVector(vector: readonly number[]): void {
|
|
109
|
+
if (vector.length !== 3 || !vector.every(Number.isFinite))
|
|
110
|
+
throw new RangeError('Expected a finite 3-vector');
|
|
111
|
+
}
|