@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,61 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileComment: Original procedural rendering approximation, not observational sky data.
|
|
5
|
+
import {
|
|
6
|
+
equatorialToGalactic,
|
|
7
|
+
galacticToEquatorial,
|
|
8
|
+
integrateGalacticOrbit,
|
|
9
|
+
SOLAR_POSITION,
|
|
10
|
+
SOLAR_VELOCITY
|
|
11
|
+
} from './star-galactic';
|
|
12
|
+
|
|
13
|
+
export type MilkyWaySample = {intensity: number; color: readonly number[]};
|
|
14
|
+
export type MilkyWayBackground = {
|
|
15
|
+
/** Fixed equatorial J2000 directions; apply the same rendering rotation as foreground stars. */
|
|
16
|
+
centerDirection: readonly number[];
|
|
17
|
+
northDirection: readonly number[];
|
|
18
|
+
/** Qualitative relative intensity and linear RGB tint, not luminance or measured flux. */
|
|
19
|
+
sample: (equatorialDirection: readonly number[]) => MilkyWaySample;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/** Create a qualitative band, bulge and dust lane. Shares one Solar orbit integration per epoch. */
|
|
23
|
+
export function createMilkyWayBackground(
|
|
24
|
+
epochYear = 2000,
|
|
25
|
+
maximumStepYears = 10000
|
|
26
|
+
): MilkyWayBackground {
|
|
27
|
+
const solar = integrateGalacticOrbit(
|
|
28
|
+
SOLAR_POSITION,
|
|
29
|
+
SOLAR_VELOCITY,
|
|
30
|
+
epochYear - 2000,
|
|
31
|
+
maximumStepYears
|
|
32
|
+
).position;
|
|
33
|
+
const radius = Math.hypot(...solar);
|
|
34
|
+
const center = solar.map(value => -value / radius);
|
|
35
|
+
const longitude = Math.atan2(center[1], center[0]);
|
|
36
|
+
const color = Object.freeze([1, 0.91, 0.8]);
|
|
37
|
+
return {
|
|
38
|
+
centerDirection: galacticToEquatorial(center),
|
|
39
|
+
northDirection: galacticToEquatorial([0, 0, 1]),
|
|
40
|
+
sample: direction => {
|
|
41
|
+
if (
|
|
42
|
+
direction.length !== 3 ||
|
|
43
|
+
!direction.every(Number.isFinite) ||
|
|
44
|
+
Math.hypot(...direction) === 0
|
|
45
|
+
)
|
|
46
|
+
throw new RangeError('Expected a finite nonzero direction');
|
|
47
|
+
const vector = equatorialToGalactic(direction);
|
|
48
|
+
const latitude = Math.asin(Math.max(-1, Math.min(1, vector[2] / Math.hypot(...vector))));
|
|
49
|
+
const delta = Math.atan2(
|
|
50
|
+
Math.sin(Math.atan2(vector[1], vector[0]) - longitude),
|
|
51
|
+
Math.cos(Math.atan2(vector[1], vector[0]) - longitude)
|
|
52
|
+
);
|
|
53
|
+
const gaussian = (angle: number, width: number): number =>
|
|
54
|
+
Math.exp(-0.5 * (angle / ((width * Math.PI) / 180)) ** 2);
|
|
55
|
+
const band = 0.25 * gaussian(latitude, 8);
|
|
56
|
+
const bulge = 0.75 * gaussian(delta, 20) * gaussian(latitude, 10);
|
|
57
|
+
const dust = 1 - 0.65 * gaussian(latitude, 1.5);
|
|
58
|
+
return {intensity: (band + bulge) * dust, color};
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileComment: Original rendering adapter; no deck.gl code copied.
|
|
5
|
+
import {getStarfieldRotation} from './starfield';
|
|
6
|
+
import {createSkyObserver} from './sky-observer';
|
|
7
|
+
import {getSkyGlobePosition} from './sky-globe';
|
|
8
|
+
import type {SkyObserver} from './sky-observer';
|
|
9
|
+
import type {StarPosition} from './star-types';
|
|
10
|
+
|
|
11
|
+
export type StarLayerOptions = {
|
|
12
|
+
/** GlobeView LNGLAT, local ENU Cartesian, or fixed J2000 Cartesian. Default globe. */
|
|
13
|
+
coordinates?: 'globe' | 'local' | 'equatorial';
|
|
14
|
+
/** Required for globe/local; ignored for equatorial. */
|
|
15
|
+
observer?: SkyObserver;
|
|
16
|
+
/** Modern observer orientation date, separate from simulated stellar epoch. Default now. */
|
|
17
|
+
timestamp?: number | Date;
|
|
18
|
+
/** Optional accurate J2000-to-ENU rotation from a sky snapshot, replacing timestamp orientation. */
|
|
19
|
+
rotation?: readonly number[];
|
|
20
|
+
/** Rendering shell radius in meters (globe/local), arbitrary units for equatorial. Default 10 million. */
|
|
21
|
+
distance?: number;
|
|
22
|
+
/** Optional current apparent magnitude cutoff; default includes every input source. */
|
|
23
|
+
maximumMagnitude?: number;
|
|
24
|
+
/** Omit sources below the geometric local horizon. Default false; unavailable for equatorial. */
|
|
25
|
+
clipHorizon?: boolean;
|
|
26
|
+
/** Radius of a magnitude-zero source, in pixels. Default 4. */
|
|
27
|
+
radiusScale?: number;
|
|
28
|
+
/** Pixel radius clamp, default [0.5, 6]. Subpixel flux is preserved through alpha. */
|
|
29
|
+
minimumRadiusPixels?: number;
|
|
30
|
+
maximumRadiusPixels?: number;
|
|
31
|
+
};
|
|
32
|
+
export type StarLayerDatum = {
|
|
33
|
+
id: number;
|
|
34
|
+
/** ScatterplotLayer position; LNGLAT for globe, Cartesian for local/equatorial. */
|
|
35
|
+
position: [number, number, number];
|
|
36
|
+
/** Gamma-encoded RGB plus alpha, byte values for getFillColor. */
|
|
37
|
+
color: [number, number, number, number];
|
|
38
|
+
radiusPixels: number;
|
|
39
|
+
/** Local geometric elevation, radians; null for equatorial. */
|
|
40
|
+
altitude: number | null;
|
|
41
|
+
magnitude: number;
|
|
42
|
+
source: StarPosition;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** Build dependency-free ScatterplotLayer data from propagated J2000 star directions. */
|
|
46
|
+
export function getStarLayerData(
|
|
47
|
+
stars: readonly StarPosition[],
|
|
48
|
+
options: StarLayerOptions = {}
|
|
49
|
+
): StarLayerDatum[] {
|
|
50
|
+
const coordinates = options.coordinates ?? 'globe';
|
|
51
|
+
if (!['globe', 'local', 'equatorial'].includes(coordinates))
|
|
52
|
+
throw new RangeError('Unknown star layer coordinates');
|
|
53
|
+
const distance = options.distance ?? 1e7;
|
|
54
|
+
const scale = options.radiusScale ?? 4;
|
|
55
|
+
const minimum = options.minimumRadiusPixels ?? 0.5;
|
|
56
|
+
const maximum = options.maximumRadiusPixels ?? 6;
|
|
57
|
+
if (
|
|
58
|
+
![distance, scale, minimum, maximum].every(Number.isFinite) ||
|
|
59
|
+
distance <= 0 ||
|
|
60
|
+
scale <= 0 ||
|
|
61
|
+
minimum <= 0 ||
|
|
62
|
+
maximum < minimum
|
|
63
|
+
)
|
|
64
|
+
throw new RangeError('Invalid star rendering distance or radii');
|
|
65
|
+
if (options.maximumMagnitude !== undefined && !Number.isFinite(options.maximumMagnitude))
|
|
66
|
+
throw new RangeError('Magnitude cutoff must be finite');
|
|
67
|
+
if (coordinates === 'equatorial' && options.clipHorizon)
|
|
68
|
+
throw new RangeError('Horizon clipping requires a local observer');
|
|
69
|
+
const observer =
|
|
70
|
+
coordinates === 'equatorial'
|
|
71
|
+
? undefined
|
|
72
|
+
: options.observer
|
|
73
|
+
? createSkyObserver(options.observer)
|
|
74
|
+
: undefined;
|
|
75
|
+
if (coordinates !== 'equatorial' && !observer)
|
|
76
|
+
throw new RangeError('Globe/local stars require an observer');
|
|
77
|
+
const rotation = observer
|
|
78
|
+
? (options.rotation ??
|
|
79
|
+
getStarfieldRotation(options.timestamp ?? Date.now(), observer.latitude, observer.longitude))
|
|
80
|
+
: undefined;
|
|
81
|
+
if (rotation) validateRotation(rotation);
|
|
82
|
+
const result: StarLayerDatum[] = [];
|
|
83
|
+
for (const star of stars) {
|
|
84
|
+
if (
|
|
85
|
+
!Number.isFinite(star.magnitude) ||
|
|
86
|
+
star.equatorialDirection.length !== 3 ||
|
|
87
|
+
!star.equatorialDirection.every(Number.isFinite) ||
|
|
88
|
+
Math.abs(Math.hypot(...star.equatorialDirection) - 1) > 1e-6 ||
|
|
89
|
+
star.color.length !== 3 ||
|
|
90
|
+
!star.color.every(value => Number.isFinite(value) && value >= 0 && value <= 1)
|
|
91
|
+
) {
|
|
92
|
+
throw new RangeError('Invalid propagated star for rendering');
|
|
93
|
+
}
|
|
94
|
+
if (options.maximumMagnitude !== undefined && star.magnitude > options.maximumMagnitude)
|
|
95
|
+
continue;
|
|
96
|
+
const direction = rotation
|
|
97
|
+
? [0, 1, 2].map(
|
|
98
|
+
i =>
|
|
99
|
+
rotation[i] * star.equatorialDirection[0] +
|
|
100
|
+
rotation[i + 3] * star.equatorialDirection[1] +
|
|
101
|
+
rotation[i + 6] * star.equatorialDirection[2]
|
|
102
|
+
)
|
|
103
|
+
: star.equatorialDirection;
|
|
104
|
+
const altitude = observer ? Math.asin(Math.max(-1, Math.min(1, direction[2]))) : null;
|
|
105
|
+
if (options.clipHorizon && altitude !== null && altitude < 0) continue;
|
|
106
|
+
const rawRadius = scale * 10 ** (-0.2 * star.magnitude);
|
|
107
|
+
const radiusPixels = Math.max(minimum, Math.min(maximum, rawRadius));
|
|
108
|
+
const alpha = Math.min(1, (rawRadius / radiusPixels) ** 2);
|
|
109
|
+
const srgb = (linear: number): number =>
|
|
110
|
+
Math.round(
|
|
111
|
+
255 * (linear <= 0.0031308 ? 12.92 * linear : 1.055 * linear ** (1 / 2.4) - 0.055)
|
|
112
|
+
);
|
|
113
|
+
result.push({
|
|
114
|
+
id: star.star.id,
|
|
115
|
+
position:
|
|
116
|
+
coordinates === 'globe'
|
|
117
|
+
? getSkyGlobePosition(direction, observer!, distance)
|
|
118
|
+
: (direction.map(value => value * distance) as [number, number, number]),
|
|
119
|
+
color: [
|
|
120
|
+
srgb(star.color[0]),
|
|
121
|
+
srgb(star.color[1]),
|
|
122
|
+
srgb(star.color[2]),
|
|
123
|
+
Math.round(255 * alpha)
|
|
124
|
+
],
|
|
125
|
+
radiusPixels,
|
|
126
|
+
altitude,
|
|
127
|
+
magnitude: star.magnitude,
|
|
128
|
+
source: star
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function validateRotation(m: readonly number[]): void {
|
|
135
|
+
if (m.length !== 9 || !m.every(Number.isFinite))
|
|
136
|
+
throw new RangeError('Expected a finite J2000-to-ENU rotation');
|
|
137
|
+
for (let a = 0; a < 3; a++)
|
|
138
|
+
for (let b = 0; b < 3; b++) {
|
|
139
|
+
const dot = [0, 1, 2].reduce((sum, i) => sum + m[a * 3 + i] * m[b * 3 + i], 0);
|
|
140
|
+
if (Math.abs(dot - (a === b ? 1 : 0)) > 1e-6)
|
|
141
|
+
throw new RangeError('Rendering rotation must be orthonormal');
|
|
142
|
+
}
|
|
143
|
+
const determinant =
|
|
144
|
+
m[0] * (m[4] * m[8] - m[7] * m[5]) -
|
|
145
|
+
m[3] * (m[1] * m[8] - m[7] * m[2]) +
|
|
146
|
+
m[6] * (m[1] * m[5] - m[4] * m[2]);
|
|
147
|
+
if (Math.abs(determinant - 1) > 1e-6)
|
|
148
|
+
throw new RangeError('Rendering rotation must preserve handedness');
|
|
149
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
/** Numeric rows generated from BSC5; angular motions are projected mas/Julian year. */
|
|
6
|
+
export type StarCatalogRow = readonly [
|
|
7
|
+
hr: number,
|
|
8
|
+
rightAscension: number,
|
|
9
|
+
declination: number,
|
|
10
|
+
magnitude: number,
|
|
11
|
+
colorIndex: number | null,
|
|
12
|
+
properMotionRA: number,
|
|
13
|
+
properMotionDec: number,
|
|
14
|
+
parallax: number | null,
|
|
15
|
+
radialVelocity: number | null,
|
|
16
|
+
flags: string,
|
|
17
|
+
designation: string
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
export type StarRecord = {
|
|
21
|
+
/** Harvard Revised Bright Star number; identifies a catalog source, sometimes a multiple system. */
|
|
22
|
+
readonly id: number;
|
|
23
|
+
readonly designation: string;
|
|
24
|
+
/** Julian epoch; the bundled catalog uses 2000.0. Axes remain equatorial J2000. */
|
|
25
|
+
readonly epochYear: number;
|
|
26
|
+
readonly rightAscension: number;
|
|
27
|
+
readonly declination: number;
|
|
28
|
+
readonly magnitude: number;
|
|
29
|
+
/** Observed B minus V, including reddening; null when missing. */
|
|
30
|
+
readonly colorIndex: number | null;
|
|
31
|
+
/** cos(declination) * d(RA)/dt, milliarcseconds per Julian year. */
|
|
32
|
+
readonly properMotionRA: number;
|
|
33
|
+
readonly properMotionDec: number;
|
|
34
|
+
/** Milliarcseconds; zero and negative catalog measurements are retained. */
|
|
35
|
+
readonly parallax: number | null;
|
|
36
|
+
/** km/s, positive receding. */
|
|
37
|
+
readonly radialVelocity: number | null;
|
|
38
|
+
readonly dynamicalParallax: boolean;
|
|
39
|
+
readonly radialVelocityFlags: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type StarPosition = {
|
|
43
|
+
readonly star: StarRecord;
|
|
44
|
+
/** Unit vector in fixed equatorial J2000 axes. */
|
|
45
|
+
readonly equatorialDirection: readonly number[];
|
|
46
|
+
/** Unit vector after the optional rendering rotation. */
|
|
47
|
+
readonly direction: readonly number[];
|
|
48
|
+
readonly rightAscension: number;
|
|
49
|
+
readonly declination: number;
|
|
50
|
+
readonly distanceParsecs: number | null;
|
|
51
|
+
readonly magnitude: number;
|
|
52
|
+
readonly relativeFlux: number;
|
|
53
|
+
/** Approximate linear RGB, normalized to a peak of one. */
|
|
54
|
+
readonly color: readonly number[];
|
|
55
|
+
readonly motionModel: 'rectilinear' | 'galactic' | 'angular';
|
|
56
|
+
readonly radialVelocityAssumed: boolean;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type StarPositionOptions = {
|
|
60
|
+
/** Default rectilinear. Galactic integrates an illustrative static Galactic potential. */
|
|
61
|
+
model?: 'rectilinear' | 'galactic';
|
|
62
|
+
/** Column-major 3x3 proper rotation, e.g. getStarfieldRotation for a modern observer date. */
|
|
63
|
+
rotation?: readonly number[];
|
|
64
|
+
/** Galactic integration maximum step in Julian years; default 10,000. */
|
|
65
|
+
maximumStepYears?: number;
|
|
66
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileComment: Independently implemented mathematical equations (no reference code copied):
|
|
5
|
+
// USNO sidereal time: https://aa.usno.navy.mil/faq/GAST
|
|
6
|
+
// IAU 1976 precession: https://www.space.t.u-tokyo.ac.jp/s2e-documents/Specifications/Environment/Spec_CelestialRotation.html
|
|
7
|
+
// ENU basis: https://gssc.esa.int/navipedia/index.php/Transformations_between_ECEF_and_ENU_coordinates
|
|
8
|
+
import {validateObserver} from './celestial';
|
|
9
|
+
import {toDays} from './suncalc';
|
|
10
|
+
|
|
11
|
+
export type StarfieldOptions = {
|
|
12
|
+
/** Cubemap equatorial frame. Default J2000; 'date' skips precession. */
|
|
13
|
+
epoch?: 'J2000' | 'date';
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** Local mean sidereal angle, in radians, using UTC as an approximation to UT1 and TT. */
|
|
17
|
+
export function getLocalSiderealTime(timestamp: number | Date, longitude: number): number {
|
|
18
|
+
validateObserver(timestamp, 0, longitude);
|
|
19
|
+
const days = toDays(timestamp);
|
|
20
|
+
const midnight = Math.floor(days + 0.5) - 0.5;
|
|
21
|
+
const hours = (days - midnight) * 24;
|
|
22
|
+
const centuries = days / 36525;
|
|
23
|
+
const siderealHours =
|
|
24
|
+
6.697375 + 0.065709824279 * midnight + 1.0027379 * hours + 0.0000258 * centuries * centuries;
|
|
25
|
+
const angle = ((siderealHours % 24) * Math.PI) / 12 + ((longitude % 360) * Math.PI) / 180;
|
|
26
|
+
return ((angle % (2 * Math.PI)) + 2 * Math.PI) % (2 * Math.PI);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Column-major 3x3 rotation from equatorial sky directions to local east/north/up.
|
|
31
|
+
* Equatorial +X = RA 0, Dec 0; +Y = RA 6h, Dec 0; +Z = north celestial pole.
|
|
32
|
+
* For cubemap lookup from a local view direction, use the transpose (inverse).
|
|
33
|
+
*/
|
|
34
|
+
export function getStarfieldRotation(
|
|
35
|
+
timestamp: number | Date,
|
|
36
|
+
latitude: number,
|
|
37
|
+
longitude: number,
|
|
38
|
+
options: StarfieldOptions = {}
|
|
39
|
+
): number[] {
|
|
40
|
+
validateObserver(timestamp, latitude, longitude);
|
|
41
|
+
const {epoch = 'J2000'} = options;
|
|
42
|
+
if (epoch !== 'J2000' && epoch !== 'date') {
|
|
43
|
+
throw new RangeError('Starfield epoch must be J2000 or date');
|
|
44
|
+
}
|
|
45
|
+
const sidereal = getLocalSiderealTime(timestamp, longitude);
|
|
46
|
+
const phi = (latitude * Math.PI) / 180;
|
|
47
|
+
const sinTime = Math.sin(sidereal);
|
|
48
|
+
const cosTime = Math.cos(sidereal);
|
|
49
|
+
const sinLatitude = Math.sin(phi);
|
|
50
|
+
const cosLatitude = Math.cos(phi);
|
|
51
|
+
const local = [
|
|
52
|
+
-sinTime,
|
|
53
|
+
-sinLatitude * cosTime,
|
|
54
|
+
cosLatitude * cosTime,
|
|
55
|
+
cosTime,
|
|
56
|
+
-sinLatitude * sinTime,
|
|
57
|
+
cosLatitude * sinTime,
|
|
58
|
+
0,
|
|
59
|
+
cosLatitude,
|
|
60
|
+
sinLatitude
|
|
61
|
+
];
|
|
62
|
+
if (epoch === 'date') return local;
|
|
63
|
+
|
|
64
|
+
// IAU 1976, J2000 to mean equator/equinox of date. UTC approximates TT here.
|
|
65
|
+
const t = toDays(timestamp) / 36525;
|
|
66
|
+
const arcsecondsToRadians = Math.PI / (180 * 3600);
|
|
67
|
+
const zeta = t * (2306.2181 + t * (0.30188 + t * 0.017998)) * arcsecondsToRadians;
|
|
68
|
+
const theta = t * (2004.3109 + t * (-0.42665 - t * 0.041833)) * arcsecondsToRadians;
|
|
69
|
+
const z = t * (2306.2181 + t * (1.09468 + t * 0.018203)) * arcsecondsToRadians;
|
|
70
|
+
const middle = [
|
|
71
|
+
Math.cos(theta),
|
|
72
|
+
0,
|
|
73
|
+
Math.sin(theta),
|
|
74
|
+
0,
|
|
75
|
+
1,
|
|
76
|
+
0,
|
|
77
|
+
-Math.sin(theta),
|
|
78
|
+
0,
|
|
79
|
+
Math.cos(theta)
|
|
80
|
+
];
|
|
81
|
+
const precession = multiply(multiply(rotationZ(z), middle), rotationZ(zeta));
|
|
82
|
+
return multiply(local, precession);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function rotationZ(angle: number): number[] {
|
|
86
|
+
const c = Math.cos(angle);
|
|
87
|
+
const s = Math.sin(angle);
|
|
88
|
+
return [c, s, 0, -s, c, 0, 0, 0, 1];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function multiply(a: number[], b: number[]): number[] {
|
|
92
|
+
const result = new Array<number>(9);
|
|
93
|
+
for (let column = 0; column < 3; column++) {
|
|
94
|
+
for (let row = 0; row < 3; row++) {
|
|
95
|
+
result[column * 3 + row] =
|
|
96
|
+
a[row] * b[column * 3] + a[row + 3] * b[column * 3 + 1] + a[row + 6] * b[column * 3 + 2];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return result;
|
|
100
|
+
}
|
package/src/sun/stars.ts
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
// SPDX-FileComment: Original implementation of tangent-basis space motion and Planck radiation.
|
|
5
|
+
// Catalog data and license: https://github.com/brettonw/YaleBrightStarCatalog
|
|
6
|
+
// B-V temperature approximation: https://arxiv.org/abs/1201.1809 (Ballesteros 2012).
|
|
7
|
+
import {STAR_CATALOG_DATA} from './data/bright-stars';
|
|
8
|
+
import {
|
|
9
|
+
equatorialToGalactic,
|
|
10
|
+
galacticToEquatorial,
|
|
11
|
+
integrateGalacticOrbit,
|
|
12
|
+
KMS_TO_PC_PER_YEAR,
|
|
13
|
+
SOLAR_POSITION,
|
|
14
|
+
SOLAR_VELOCITY
|
|
15
|
+
} from './star-galactic';
|
|
16
|
+
import type {StarRecord, StarPosition, StarPositionOptions} from './star-types';
|
|
17
|
+
|
|
18
|
+
export type {StarRecord, StarPosition, StarPositionOptions} from './star-types';
|
|
19
|
+
export {
|
|
20
|
+
getGalacticAcceleration,
|
|
21
|
+
getGalacticPotential,
|
|
22
|
+
integrateGalacticOrbit
|
|
23
|
+
} from './star-galactic';
|
|
24
|
+
export {createMilkyWayBackground} from './star-milky-way';
|
|
25
|
+
export type {MilkyWayBackground, MilkyWaySample} from './star-milky-way';
|
|
26
|
+
|
|
27
|
+
/** Brightest 7,000 BSC5 sources, sorted by visual magnitude then HR number. */
|
|
28
|
+
export const STAR_CATALOG: readonly StarRecord[] = Object.freeze(
|
|
29
|
+
STAR_CATALOG_DATA.map(row =>
|
|
30
|
+
Object.freeze({
|
|
31
|
+
id: row[0],
|
|
32
|
+
designation: row[10],
|
|
33
|
+
epochYear: 2000,
|
|
34
|
+
rightAscension: row[1],
|
|
35
|
+
declination: row[2],
|
|
36
|
+
magnitude: row[3],
|
|
37
|
+
colorIndex: row[4],
|
|
38
|
+
properMotionRA: row[5],
|
|
39
|
+
properMotionDec: row[6],
|
|
40
|
+
parallax: row[7],
|
|
41
|
+
radialVelocity: row[8],
|
|
42
|
+
dynamicalParallax: row[9].startsWith('D'),
|
|
43
|
+
radialVelocityFlags: row[9].split('|')[1]
|
|
44
|
+
})
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
/** Metadata describes the fixed input selection, not a completeness guarantee at future epochs. */
|
|
49
|
+
export const STAR_CATALOG_INFO = Object.freeze({
|
|
50
|
+
count: 7000,
|
|
51
|
+
epochYear: 2000,
|
|
52
|
+
faintestMagnitude: 6.3,
|
|
53
|
+
positiveParallaxes: 2797,
|
|
54
|
+
fullSpaceMotions: 2796,
|
|
55
|
+
sourceRevision: 'abffb3b7223ae37e879b0a3ff5b49ad06aed5576',
|
|
56
|
+
source: 'Yale Bright Star Catalog, fifth revised edition (1991), MIT-licensed Bretton Wade export'
|
|
57
|
+
});
|
|
58
|
+
const MAS_TO_RADIANS = Math.PI / (180 * 3600 * 1000);
|
|
59
|
+
const colorCache = new Map<number | null, readonly number[]>();
|
|
60
|
+
|
|
61
|
+
/** Propagate a source to a numeric Julian epoch, without extrapolating Earth precession. */
|
|
62
|
+
export function getStarPosition(
|
|
63
|
+
star: StarRecord,
|
|
64
|
+
epochYear: number,
|
|
65
|
+
options: StarPositionOptions = {}
|
|
66
|
+
): StarPosition {
|
|
67
|
+
validateOptions(epochYear, options);
|
|
68
|
+
const solar =
|
|
69
|
+
options.model === 'galactic'
|
|
70
|
+
? integrateGalacticOrbit(
|
|
71
|
+
SOLAR_POSITION,
|
|
72
|
+
SOLAR_VELOCITY,
|
|
73
|
+
epochYear - 2000,
|
|
74
|
+
options.maximumStepYears
|
|
75
|
+
).position
|
|
76
|
+
: undefined;
|
|
77
|
+
return propagate(star, epochYear, options, solar);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Batch propagation shares the observer's Galactic integration between all sources. */
|
|
81
|
+
export function getStarPositions(
|
|
82
|
+
epochYear: number,
|
|
83
|
+
options: StarPositionOptions = {},
|
|
84
|
+
catalog: readonly StarRecord[] = STAR_CATALOG
|
|
85
|
+
): StarPosition[] {
|
|
86
|
+
validateOptions(epochYear, options);
|
|
87
|
+
const solar =
|
|
88
|
+
options.model === 'galactic'
|
|
89
|
+
? integrateGalacticOrbit(
|
|
90
|
+
SOLAR_POSITION,
|
|
91
|
+
SOLAR_VELOCITY,
|
|
92
|
+
epochYear - 2000,
|
|
93
|
+
options.maximumStepYears
|
|
94
|
+
).position
|
|
95
|
+
: undefined;
|
|
96
|
+
return catalog.map(star => propagate(star, epochYear, options, solar));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Observed B-V to qualitative linear RGB. Missing B-V uses white. */
|
|
100
|
+
export function getStarColor(colorIndex: number | null): readonly number[] {
|
|
101
|
+
if (colorIndex !== null && !Number.isFinite(colorIndex))
|
|
102
|
+
throw new RangeError('B-V must be finite or null');
|
|
103
|
+
const cached = colorCache.get(colorIndex);
|
|
104
|
+
if (cached) return cached;
|
|
105
|
+
if (colorCache.size >= 1024) colorCache.clear();
|
|
106
|
+
let color: number[] = [1, 1, 1];
|
|
107
|
+
if (colorIndex !== null) {
|
|
108
|
+
const bv = Math.max(-0.4, Math.min(2, colorIndex));
|
|
109
|
+
const temperature = 4600 * (1 / (0.92 * bv + 1.7) + 1 / (0.92 * bv + 0.62));
|
|
110
|
+
// Three broad spectral samples; this is a rendering tint, not calibrated sRGB photometry.
|
|
111
|
+
const planck = (wavelength: number): number =>
|
|
112
|
+
1 / (wavelength ** 5 * Math.expm1(0.01438776877 / (wavelength * temperature)));
|
|
113
|
+
color = [680e-9, 550e-9, 440e-9].map(planck);
|
|
114
|
+
const peak = Math.max(...color);
|
|
115
|
+
color = color.map(value => value / peak);
|
|
116
|
+
}
|
|
117
|
+
const result = Object.freeze(color);
|
|
118
|
+
colorCache.set(colorIndex, result);
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function propagate(
|
|
123
|
+
star: StarRecord,
|
|
124
|
+
epochYear: number,
|
|
125
|
+
options: StarPositionOptions,
|
|
126
|
+
solar?: number[]
|
|
127
|
+
): StarPosition {
|
|
128
|
+
validateStar(star);
|
|
129
|
+
if (solar && star.epochYear !== 2000)
|
|
130
|
+
throw new RangeError('Galactic motion requires J2000 input records');
|
|
131
|
+
const years = epochYear - star.epochYear;
|
|
132
|
+
if (Math.abs(years) > 1e7)
|
|
133
|
+
throw new RangeError('Star propagation is limited to 10 million Julian years');
|
|
134
|
+
const {rightAscension: ra, declination: dec} = star;
|
|
135
|
+
const cosDec = Math.cos(dec),
|
|
136
|
+
sinDec = Math.sin(dec),
|
|
137
|
+
cosRA = Math.cos(ra),
|
|
138
|
+
sinRA = Math.sin(ra);
|
|
139
|
+
const direction = [cosDec * cosRA, cosDec * sinRA, sinDec];
|
|
140
|
+
const raRate = star.properMotionRA * MAS_TO_RADIANS;
|
|
141
|
+
const decRate = star.properMotionDec * MAS_TO_RADIANS;
|
|
142
|
+
const tangent = [
|
|
143
|
+
-sinRA * raRate - sinDec * cosRA * decRate,
|
|
144
|
+
cosRA * raRate - sinDec * sinRA * decRate,
|
|
145
|
+
cosDec * decRate
|
|
146
|
+
];
|
|
147
|
+
const distance = star.parallax !== null && star.parallax > 0 ? 1000 / star.parallax : null;
|
|
148
|
+
let relative: number[],
|
|
149
|
+
distanceParsecs: number | null = null;
|
|
150
|
+
let motionModel: StarPosition['motionModel'] = 'angular';
|
|
151
|
+
if (distance !== null) {
|
|
152
|
+
const position = direction.map(value => value * distance);
|
|
153
|
+
const velocity = tangent.map(
|
|
154
|
+
(value, i) =>
|
|
155
|
+
value * distance + direction[i] * (star.radialVelocity ?? 0) * KMS_TO_PC_PER_YEAR
|
|
156
|
+
);
|
|
157
|
+
if (solar) {
|
|
158
|
+
const galPosition = equatorialToGalactic(position).map(
|
|
159
|
+
(value, i) => value + SOLAR_POSITION[i]
|
|
160
|
+
);
|
|
161
|
+
const galVelocity = equatorialToGalactic(velocity).map(
|
|
162
|
+
(value, i) => value * 1e6 + SOLAR_VELOCITY[i]
|
|
163
|
+
);
|
|
164
|
+
const moved = integrateGalacticOrbit(
|
|
165
|
+
galPosition,
|
|
166
|
+
galVelocity,
|
|
167
|
+
years,
|
|
168
|
+
options.maximumStepYears
|
|
169
|
+
).position;
|
|
170
|
+
relative = galacticToEquatorial(moved.map((value, i) => value - solar[i]));
|
|
171
|
+
motionModel = 'galactic';
|
|
172
|
+
} else {
|
|
173
|
+
relative = position.map((value, i) => value + velocity[i] * years);
|
|
174
|
+
motionModel = 'rectilinear';
|
|
175
|
+
}
|
|
176
|
+
distanceParsecs = Math.hypot(...relative);
|
|
177
|
+
} else relative = direction.map((value, i) => value + tangent[i] * years);
|
|
178
|
+
const length = Math.hypot(...relative);
|
|
179
|
+
if (!(length > 0) || !Number.isFinite(length))
|
|
180
|
+
throw new RangeError('Star coincides with observer or motion overflowed');
|
|
181
|
+
const equatorialDirection = relative.map(value => value / length);
|
|
182
|
+
const rotated = options.rotation
|
|
183
|
+
? rotate(options.rotation, equatorialDirection)
|
|
184
|
+
: [...equatorialDirection];
|
|
185
|
+
const magnitude =
|
|
186
|
+
distanceParsecs !== null && distance !== null
|
|
187
|
+
? star.magnitude + 5 * Math.log10(distanceParsecs / distance)
|
|
188
|
+
: star.magnitude;
|
|
189
|
+
return {
|
|
190
|
+
star,
|
|
191
|
+
equatorialDirection,
|
|
192
|
+
direction: rotated,
|
|
193
|
+
rightAscension:
|
|
194
|
+
(Math.atan2(equatorialDirection[1], equatorialDirection[0]) + 2 * Math.PI) % (2 * Math.PI),
|
|
195
|
+
declination: Math.asin(Math.max(-1, Math.min(1, equatorialDirection[2]))),
|
|
196
|
+
distanceParsecs,
|
|
197
|
+
magnitude,
|
|
198
|
+
relativeFlux: 10 ** (-0.4 * magnitude),
|
|
199
|
+
color: getStarColor(star.colorIndex),
|
|
200
|
+
motionModel,
|
|
201
|
+
radialVelocityAssumed: star.radialVelocity === null
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function validateStar(star: StarRecord): void {
|
|
206
|
+
if (
|
|
207
|
+
![
|
|
208
|
+
star.epochYear,
|
|
209
|
+
star.rightAscension,
|
|
210
|
+
star.declination,
|
|
211
|
+
star.magnitude,
|
|
212
|
+
star.properMotionRA,
|
|
213
|
+
star.properMotionDec
|
|
214
|
+
].every(Number.isFinite) ||
|
|
215
|
+
Math.abs(star.declination) > Math.PI / 2 ||
|
|
216
|
+
(star.parallax !== null && !Number.isFinite(star.parallax)) ||
|
|
217
|
+
(star.radialVelocity !== null && !Number.isFinite(star.radialVelocity))
|
|
218
|
+
) {
|
|
219
|
+
throw new RangeError('Invalid star coordinates or motion');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function validateOptions(epochYear: number, options: StarPositionOptions): void {
|
|
223
|
+
if (!Number.isFinite(epochYear) || Math.abs(epochYear - 2000) > 1e7)
|
|
224
|
+
throw new RangeError('Epoch must be within 10 million years of J2000');
|
|
225
|
+
if (
|
|
226
|
+
options.model !== undefined &&
|
|
227
|
+
options.model !== 'rectilinear' &&
|
|
228
|
+
options.model !== 'galactic'
|
|
229
|
+
)
|
|
230
|
+
throw new RangeError('Unknown stellar motion model');
|
|
231
|
+
if (
|
|
232
|
+
options.maximumStepYears !== undefined &&
|
|
233
|
+
(!Number.isFinite(options.maximumStepYears) ||
|
|
234
|
+
options.maximumStepYears <= 0 ||
|
|
235
|
+
options.maximumStepYears > 10000)
|
|
236
|
+
)
|
|
237
|
+
throw new RangeError('Invalid Galactic step');
|
|
238
|
+
const m = options.rotation;
|
|
239
|
+
if (m) {
|
|
240
|
+
if (m.length !== 9 || !m.every(Number.isFinite))
|
|
241
|
+
throw new RangeError('Rotation must be a finite 3x3 matrix');
|
|
242
|
+
for (let a = 0; a < 3; a++)
|
|
243
|
+
for (let b = 0; b < 3; b++) {
|
|
244
|
+
const dot = [0, 1, 2].reduce((sum, i) => sum + m[a * 3 + i] * m[b * 3 + i], 0);
|
|
245
|
+
if (Math.abs(dot - (a === b ? 1 : 0)) > 1e-6)
|
|
246
|
+
throw new RangeError('Rotation must be orthonormal');
|
|
247
|
+
}
|
|
248
|
+
const determinant =
|
|
249
|
+
m[0] * (m[4] * m[8] - m[7] * m[5]) -
|
|
250
|
+
m[3] * (m[1] * m[8] - m[7] * m[2]) +
|
|
251
|
+
m[6] * (m[1] * m[5] - m[4] * m[2]);
|
|
252
|
+
if (Math.abs(determinant - 1) > 1e-6) throw new RangeError('Rotation must preserve handedness');
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function rotate(m: readonly number[], v: readonly number[]): number[] {
|
|
256
|
+
return [0, 1, 2].map(i => m[i] * v[0] + m[i + 3] * v[1] + m[i + 6] * v[2]);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export {getStarLayerData} from './star-render';
|
|
260
|
+
export type {StarLayerOptions, StarLayerDatum} from './star-render';
|