@johnmorrisdotca/wakusei-planets 0.33.0 → 0.35.0
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/CHANGELOG.md +22 -0
- package/NOTICE.md +52 -0
- package/README.md +26 -3
- package/dist/approaches.d.ts +276 -0
- package/dist/approaches.js +255 -0
- package/dist/asteroids.d.ts +397 -0
- package/dist/asteroids.js +338 -0
- package/dist/comets.d.ts +316 -0
- package/dist/comets.js +404 -0
- package/dist/craft/bepicolombo.d.ts +1 -0
- package/dist/craft/bepicolombo.js +923 -0
- package/dist/craft/europaclipper.d.ts +1 -0
- package/dist/craft/europaclipper.js +342 -0
- package/dist/craft/hayabusa2.d.ts +1 -0
- package/dist/craft/hayabusa2.js +73 -0
- package/dist/craft/juice.d.ts +1 -0
- package/dist/craft/juice.js +40 -0
- package/dist/craft/lucy.d.ts +1 -0
- package/dist/craft/lucy.js +42 -0
- package/dist/craft/osirisapex.d.ts +1 -0
- package/dist/craft/osirisapex.js +69 -0
- package/dist/craft/psyche.d.ts +1 -0
- package/dist/craft/psyche.js +30 -0
- package/dist/craft/solarorbiter.d.ts +1 -0
- package/dist/craft/solarorbiter.js +94 -0
- package/dist/data/approaches.d.ts +17 -0
- package/dist/data/approaches.js +4192 -0
- package/dist/data/asteroids.d.ts +3 -0
- package/dist/data/asteroids.js +107 -0
- package/dist/data/comets.d.ts +2 -0
- package/dist/data/comets.js +36 -0
- package/dist/data/places-67p.d.ts +27 -0
- package/dist/data/places-67p.js +2 -0
- package/dist/data/places-ariel.d.ts +602 -0
- package/dist/data/places-ariel.js +27 -0
- package/dist/data/places-bennu.d.ts +25 -0
- package/dist/data/places-bennu.js +2 -0
- package/dist/data/places-callisto.d.ts +3547 -0
- package/dist/data/places-callisto.js +155 -0
- package/dist/data/places-ceres.d.ts +3436 -0
- package/dist/data/places-ceres.js +150 -0
- package/dist/data/places-charon.d.ts +349 -0
- package/dist/data/places-charon.js +16 -0
- package/dist/data/places-dimorphos.d.ts +23 -0
- package/dist/data/places-dimorphos.js +2 -0
- package/dist/data/places-dione.d.ts +2258 -0
- package/dist/data/places-dione.js +99 -0
- package/dist/data/places-enceladus.d.ts +2009 -0
- package/dist/data/places-enceladus.js +88 -0
- package/dist/data/places-eros.d.ts +26 -0
- package/dist/data/places-eros.js +2 -0
- package/dist/data/places-europa.d.ts +2977 -0
- package/dist/data/places-europa.js +130 -0
- package/dist/data/places-ganymede.d.ts +4518 -0
- package/dist/data/places-ganymede.js +197 -0
- package/dist/data/places-iapetus.d.ts +1616 -0
- package/dist/data/places-iapetus.js +71 -0
- package/dist/data/places-io.d.ts +6012 -0
- package/dist/data/places-io.js +262 -0
- package/dist/data/places-jupiter.d.ts +46 -0
- package/dist/data/places-jupiter.js +3 -0
- package/dist/data/places-mars.d.ts +20701 -0
- package/dist/data/places-mars.js +942 -0
- package/dist/data/places-mercury.d.ts +9256 -0
- package/dist/data/places-mercury.js +403 -0
- package/dist/data/places-mimas.d.ts +968 -0
- package/dist/data/places-mimas.js +43 -0
- package/dist/data/places-miranda.d.ts +419 -0
- package/dist/data/places-miranda.js +19 -0
- package/dist/data/places-moon.d.ts +18849 -0
- package/dist/data/places-moon.js +861 -0
- package/dist/data/places-oberon.d.ts +235 -0
- package/dist/data/places-oberon.js +11 -0
- package/dist/data/places-pluto.d.ts +1687 -0
- package/dist/data/places-pluto.js +74 -0
- package/dist/data/places-rhea.d.ts +3317 -0
- package/dist/data/places-rhea.js +145 -0
- package/dist/data/places-ryugu.d.ts +87 -0
- package/dist/data/places-ryugu.js +5 -0
- package/dist/data/places-saturn.d.ts +25 -0
- package/dist/data/places-saturn.js +2 -0
- package/dist/data/places-tempel-1.d.ts +25 -0
- package/dist/data/places-tempel-1.js +2 -0
- package/dist/data/places-tethys.d.ts +1222 -0
- package/dist/data/places-tethys.js +54 -0
- package/dist/data/places-titan.d.ts +7031 -0
- package/dist/data/places-titan.js +306 -0
- package/dist/data/places-titania.d.ts +418 -0
- package/dist/data/places-titania.js +19 -0
- package/dist/data/places-triton.d.ts +1457 -0
- package/dist/data/places-triton.js +64 -0
- package/dist/data/places-umbriel.d.ts +303 -0
- package/dist/data/places-umbriel.js +14 -0
- package/dist/data/places-venus.d.ts +9290 -0
- package/dist/data/places-venus.js +405 -0
- package/dist/data/places-vesta.d.ts +2444 -0
- package/dist/data/places-vesta.js +107 -0
- package/dist/data/roadster.d.ts +8 -0
- package/dist/data/roadster.js +686 -0
- package/dist/element.d.ts +10 -1
- package/dist/element.js +39 -4
- package/dist/places/67p.d.ts +13 -0
- package/dist/places/67p.js +14 -0
- package/dist/places/ariel.d.ts +13 -0
- package/dist/places/ariel.js +14 -0
- package/dist/places/bennu.d.ts +13 -0
- package/dist/places/bennu.js +14 -0
- package/dist/places/callisto.d.ts +13 -0
- package/dist/places/callisto.js +14 -0
- package/dist/places/ceres.d.ts +13 -0
- package/dist/places/ceres.js +14 -0
- package/dist/places/charon.d.ts +13 -0
- package/dist/places/charon.js +14 -0
- package/dist/places/dimorphos.d.ts +13 -0
- package/dist/places/dimorphos.js +14 -0
- package/dist/places/dione.d.ts +13 -0
- package/dist/places/dione.js +14 -0
- package/dist/places/enceladus.d.ts +13 -0
- package/dist/places/enceladus.js +14 -0
- package/dist/places/eros.d.ts +13 -0
- package/dist/places/eros.js +14 -0
- package/dist/places/europa.d.ts +13 -0
- package/dist/places/europa.js +14 -0
- package/dist/places/ganymede.d.ts +13 -0
- package/dist/places/ganymede.js +14 -0
- package/dist/places/iapetus.d.ts +13 -0
- package/dist/places/iapetus.js +14 -0
- package/dist/places/io.d.ts +13 -0
- package/dist/places/io.js +14 -0
- package/dist/places/jupiter.d.ts +13 -0
- package/dist/places/jupiter.js +14 -0
- package/dist/places/mars.d.ts +12 -0
- package/dist/places/mars.js +13 -0
- package/dist/places/mercury.d.ts +13 -0
- package/dist/places/mercury.js +14 -0
- package/dist/places/mimas.d.ts +13 -0
- package/dist/places/mimas.js +14 -0
- package/dist/places/miranda.d.ts +13 -0
- package/dist/places/miranda.js +14 -0
- package/dist/places/moon.d.ts +12 -0
- package/dist/places/moon.js +13 -0
- package/dist/places/oberon.d.ts +13 -0
- package/dist/places/oberon.js +14 -0
- package/dist/places/pluto.d.ts +13 -0
- package/dist/places/pluto.js +14 -0
- package/dist/places/rhea.d.ts +13 -0
- package/dist/places/rhea.js +14 -0
- package/dist/places/ryugu.d.ts +13 -0
- package/dist/places/ryugu.js +14 -0
- package/dist/places/saturn.d.ts +13 -0
- package/dist/places/saturn.js +14 -0
- package/dist/places/tempel-1.d.ts +13 -0
- package/dist/places/tempel-1.js +14 -0
- package/dist/places/tethys.d.ts +13 -0
- package/dist/places/tethys.js +14 -0
- package/dist/places/titan.d.ts +13 -0
- package/dist/places/titan.js +14 -0
- package/dist/places/titania.d.ts +13 -0
- package/dist/places/titania.js +14 -0
- package/dist/places/triton.d.ts +13 -0
- package/dist/places/triton.js +14 -0
- package/dist/places/umbriel.d.ts +13 -0
- package/dist/places/umbriel.js +14 -0
- package/dist/places/venus.d.ts +13 -0
- package/dist/places/venus.js +14 -0
- package/dist/places/vesta.d.ts +13 -0
- package/dist/places/vesta.js +14 -0
- package/dist/places.d.ts +354 -0
- package/dist/places.js +357 -0
- package/dist/plan/element.d.ts +52 -0
- package/dist/plan/element.js +258 -0
- package/dist/plan/index.d.ts +2 -0
- package/dist/plan/index.js +2 -0
- package/dist/plan/layout.d.ts +230 -0
- package/dist/plan/layout.js +229 -0
- package/dist/plan/svg.d.ts +125 -0
- package/dist/plan/svg.js +185 -0
- package/dist/roadster.d.ts +415 -0
- package/dist/roadster.js +496 -0
- package/dist/scene/body.d.ts +13 -2
- package/dist/scene/body.js +36 -0
- package/dist/scene/name-label.d.ts +116 -0
- package/dist/scene/name-label.js +232 -0
- package/dist/scene/painter.d.ts +30 -1
- package/dist/scene/painter.js +56 -4
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/beside.d.ts +4 -1
- package/dist/space/beside.js +47 -6
- package/dist/space/covered.d.ts +102 -0
- package/dist/space/covered.js +98 -0
- package/dist/space/element.d.ts +37 -1
- package/dist/space/element.js +151 -11
- package/dist/space/index.d.ts +1 -0
- package/dist/space/index.js +1 -0
- package/dist/space/scale.d.ts +2 -1
- package/dist/space/scale.js +13 -2
- package/dist/space/scene.d.ts +23 -1
- package/dist/space/scene.js +62 -21
- package/dist/spacecraft-facts.d.ts +4 -4
- package/dist/spacecraft-facts.js +158 -3
- package/dist/spacecraft.d.ts +69 -2
- package/dist/spacecraft.js +45 -2
- package/dist/textures/mimas-1024.webp +0 -0
- package/dist/textures/mimas-512.webp +0 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +204 -2
package/dist/roadster.js
ADDED
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
// Starman and the Tesla Roadster: where the car launched on the first Falcon Heavy is at a date, its distances, speeds, orbit and the moments worth looking at. The path is a table of state vectors from JPL Horizons
|
|
2
|
+
// (target -143205, solution s11; scripts/make-roadster-data.py, src/data/roadster.ts) joined by cubic Hermite interpolation on position and velocity, and only this entry point imports it. Positions are heliocentric, in
|
|
3
|
+
// kilometres, in the J2000 ecliptic frame, like `spacecraftPosition` (`heliocentric` gives the planets in astronomical units in the same axes). Pure: no DOM, no clock reads, no three.js.
|
|
4
|
+
import { ROADSTER_ROWS, ROADSTER_START, ROADSTER_STEP_DAYS, ROADSTER_WORST_KM } from "./data/roadster.js";
|
|
5
|
+
import { toTerrestrialTime, ttMinusUtc } from "./clock.js";
|
|
6
|
+
import { heliocentric } from "./ephemeris.js";
|
|
7
|
+
import { add, cross, dot, length, scale, sub, unit } from "./vec.js";
|
|
8
|
+
import { moment } from "./when.js";
|
|
9
|
+
const AU_KM = 149_597_870.7;
|
|
10
|
+
const MILE_KM = 1.609344;
|
|
11
|
+
const LIGHT_KM_PER_SECOND = 299_792.458;
|
|
12
|
+
/** The Sun's gravitational parameter in cubic kilometres a second squared (the value of the DE440 ephemeris that Horizons uses). */
|
|
13
|
+
const GM_SUN = 132_712_440_041.279_42;
|
|
14
|
+
const DAY_MS = 86_400_000;
|
|
15
|
+
const STRIDE = 7;
|
|
16
|
+
/** The launch: 2018-02-06 20:45 UTC, from Horizons' own notes on the object. */
|
|
17
|
+
const LAUNCH = Date.UTC(2018, 1, 6, 20, 45);
|
|
18
|
+
const ROWS = ROADSTER_ROWS;
|
|
19
|
+
const COUNT = ROWS.length / STRIDE;
|
|
20
|
+
const SPAN_SECONDS = ROWS[(COUNT - 1) * STRIDE] * 3600;
|
|
21
|
+
const utcOfTerrestrial = (tt) => tt - ttMinusUtc(tt) * 1000;
|
|
22
|
+
const RECORD_START = utcOfTerrestrial(ROADSTER_START);
|
|
23
|
+
const RECORD_END = utcOfTerrestrial(ROADSTER_START + SPAN_SECONDS * 1000);
|
|
24
|
+
/**
|
|
25
|
+
* What is known about the car: its names, launch, Horizons' number and the span of the path.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { ROADSTER } from "@johnmorrisdotca/wakusei-planets/roadster";
|
|
30
|
+
*
|
|
31
|
+
* console.log(ROADSTER.name.en, "and the", ROADSTER.car.en, "were launched", new Date(ROADSTER.launch).toISOString());
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export const ROADSTER = {
|
|
35
|
+
/** The mannequin at the wheel, in English and Japanese. */
|
|
36
|
+
name: { en: "Starman", ja: "スターマン" },
|
|
37
|
+
/** The car, in English and Japanese. */
|
|
38
|
+
car: { en: "Tesla Roadster", ja: "テスラ・ロードスター" },
|
|
39
|
+
/** The launch, in milliseconds since 1970 (UTC): the first flight of the Falcon Heavy, 2018-02-06 20:45, from launch complex 39A of the Kennedy Space Center. */
|
|
40
|
+
launch: LAUNCH,
|
|
41
|
+
/** The number JPL Horizons gives the car. */
|
|
42
|
+
horizonsId: "-143205",
|
|
43
|
+
/** The span the path covers, in milliseconds since 1970 (UTC): from about six hours after the launch (where Horizons' record starts) to 2036-01-01. A date outside it throws a `RangeError`. */
|
|
44
|
+
record: { start: RECORD_START, end: RECORD_END },
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* How far to trust the path, stated: the span it covers, the worst error of the interpolation against Horizons' own record as measured when the table was made, and what the table cannot know.
|
|
48
|
+
* The car's path is a prediction from a fit to 374 telescope observations made in February and March 2018 (Horizons' solution s11), with sunlight's push on the car estimated from them: a date years after the fit drifts from where the car really is, by more the further away it is.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { ROADSTER_ACCURACY } from "@johnmorrisdotca/wakusei-planets/roadster";
|
|
53
|
+
*
|
|
54
|
+
* console.log(`rows ${ROADSTER_ACCURACY.stepDays} days apart, within ${ROADSTER_ACCURACY.interpolationKm} km of Horizons' own path`);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export const ROADSTER_ACCURACY = {
|
|
58
|
+
/** The first moment the path covers, in milliseconds since 1970 (UTC). */
|
|
59
|
+
from: RECORD_START,
|
|
60
|
+
/** The last moment the path covers, in milliseconds since 1970 (UTC). */
|
|
61
|
+
to: RECORD_END,
|
|
62
|
+
/** The days between rows of the table once the car is ten days out. */
|
|
63
|
+
stepDays: ROADSTER_STEP_DAYS,
|
|
64
|
+
/** The worst distance, in kilometres, between the table's interpolation and Horizons' own record of the same path, measured every day of the span, every hour of the first 13 days and every hour round the Mars passes of October 2020 and April 2035. */
|
|
65
|
+
interpolationKm: ROADSTER_WORST_KM,
|
|
66
|
+
/** In words, what the numbers leave out. */
|
|
67
|
+
note: "Horizons' path was fitted to observations from February and March 2018 and is a prediction after that; sunlight's push is modelled only as one number fitted to those observations, so the real car drifts from the predicted path, and the further from 2018 the more. The interpolation error above is separate and small beside it.",
|
|
68
|
+
};
|
|
69
|
+
/** The state from the table at a UTC moment: terrestrial seconds after the start of the table, position and velocity. */
|
|
70
|
+
function state(ms) {
|
|
71
|
+
const seconds = (toTerrestrialTime(ms) - ROADSTER_START) / 1000;
|
|
72
|
+
if (!(seconds >= -1e-3 && seconds <= SPAN_SECONDS + 1e-3)) {
|
|
73
|
+
throw new RangeError(`when ${new Date(ms).toISOString()} is outside the path of the Tesla Roadster, which runs from ${new Date(RECORD_START).toISOString()} to ${new Date(RECORD_END).toISOString()}`);
|
|
74
|
+
}
|
|
75
|
+
let lo = 0;
|
|
76
|
+
let hi = COUNT - 2;
|
|
77
|
+
while (lo < hi) {
|
|
78
|
+
const mid = (lo + hi + 1) >> 1;
|
|
79
|
+
if (ROWS[mid * STRIDE] * 3600 <= seconds)
|
|
80
|
+
lo = mid;
|
|
81
|
+
else
|
|
82
|
+
hi = mid - 1;
|
|
83
|
+
}
|
|
84
|
+
const a = lo * STRIDE;
|
|
85
|
+
const b = a + STRIDE;
|
|
86
|
+
const t0 = ROWS[a] * 3600;
|
|
87
|
+
const h = ROWS[b] * 3600 - t0;
|
|
88
|
+
const s = (seconds - t0) / h;
|
|
89
|
+
const s2 = s * s;
|
|
90
|
+
const s3 = s2 * s;
|
|
91
|
+
const h00 = 2 * s3 - 3 * s2 + 1;
|
|
92
|
+
const h10 = s3 - 2 * s2 + s;
|
|
93
|
+
const h01 = -2 * s3 + 3 * s2;
|
|
94
|
+
const h11 = s3 - s2;
|
|
95
|
+
const d00 = (6 * s2 - 6 * s) / h;
|
|
96
|
+
const d10 = 3 * s2 - 4 * s + 1;
|
|
97
|
+
const d01 = (-6 * s2 + 6 * s) / h;
|
|
98
|
+
const d11 = 3 * s2 - 2 * s;
|
|
99
|
+
const position = [0, 0, 0];
|
|
100
|
+
const velocity = [0, 0, 0];
|
|
101
|
+
for (let k = 0; k < 3; k += 1) {
|
|
102
|
+
const p0 = ROWS[a + 1 + k];
|
|
103
|
+
const p1 = ROWS[b + 1 + k];
|
|
104
|
+
const v0 = ROWS[a + 4 + k];
|
|
105
|
+
const v1 = ROWS[b + 4 + k];
|
|
106
|
+
position[k] = h00 * p0 + h10 * h * v0 + h01 * p1 + h11 * h * v1;
|
|
107
|
+
velocity[k] = d00 * p0 + d10 * v0 + d01 * p1 + d11 * v1;
|
|
108
|
+
}
|
|
109
|
+
return { position, velocity, seconds };
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Where the car is at a moment: x, y, z in kilometres from the Sun, in the J2000 ecliptic frame (the axes of `heliocentric`, which is in astronomical units, and of `spacecraftPosition`).
|
|
113
|
+
* The path is Horizons' prediction from 2018's observations (see `ROADSTER_ACCURACY`). A moment outside `ROADSTER.record` throws a `RangeError`.
|
|
114
|
+
*
|
|
115
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
116
|
+
* @returns The position in kilometres.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { roadsterPosition } from "@johnmorrisdotca/wakusei-planets/roadster";
|
|
121
|
+
*
|
|
122
|
+
* const [x, y, z] = roadsterPosition(new Date("2020-10-07T06:00:00Z"));
|
|
123
|
+
* console.log((Math.hypot(x, y, z) / 149597870.7).toFixed(3), "au from the Sun");
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export function roadsterPosition(when) {
|
|
127
|
+
return state(moment(when)).position;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* The same position in astronomical units, the unit `heliocentric` gives the planets in, so the car and a planet subtract directly.
|
|
131
|
+
*
|
|
132
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
133
|
+
* @returns The position in au.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* import { heliocentric } from "@johnmorrisdotca/wakusei-planets";
|
|
138
|
+
* import { roadsterPositionAu } from "@johnmorrisdotca/wakusei-planets/roadster";
|
|
139
|
+
*
|
|
140
|
+
* const day = Date.UTC(2020, 9, 7);
|
|
141
|
+
* const [c, m] = [roadsterPositionAu(day), heliocentric("mars", day)];
|
|
142
|
+
* console.log(Math.hypot(c[0] - m[0], c[1] - m[1], c[2] - m[2]).toFixed(3), "au from Mars");
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export function roadsterPositionAu(when) {
|
|
146
|
+
return scale(roadsterPosition(when), 1 / AU_KM);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The car's velocity relative to the Sun at a moment, in kilometres a second, in the same frame as `roadsterPosition`. It is the slope of the interpolation, within 2.3 metres a second of Horizons' own after the first day (up to 115 metres a second in the first day, while the Earth still bends the path).
|
|
150
|
+
*
|
|
151
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
152
|
+
* @returns The velocity.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* import { roadsterVelocity } from "@johnmorrisdotca/wakusei-planets/roadster";
|
|
157
|
+
*
|
|
158
|
+
* console.log(roadsterVelocity(Date.UTC(2024, 0, 1)).map((v) => v.toFixed(2)));
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export function roadsterVelocity(when) {
|
|
162
|
+
return state(moment(when)).velocity;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* The car's speed relative to the Sun at a moment, in kilometres a second.
|
|
166
|
+
*
|
|
167
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
168
|
+
* @returns The speed.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* import { roadsterSpeed } from "@johnmorrisdotca/wakusei-planets/roadster";
|
|
173
|
+
*
|
|
174
|
+
* console.log(roadsterSpeed(Date.UTC(2026, 10, 11)).toFixed(1), "km/s");
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
export function roadsterSpeed(when) {
|
|
178
|
+
return length(roadsterVelocity(when));
|
|
179
|
+
}
|
|
180
|
+
/** A planet's position (km) and velocity (km/s) from the Sun at a UTC moment: `heliocentric`, and its slope over two hours either side (the curve is smooth, so the error is far below a millimetre a second). */
|
|
181
|
+
function planetState(id, ms) {
|
|
182
|
+
const h = 3_600_000;
|
|
183
|
+
const at = (t) => scale(heliocentric(id, t), AU_KM);
|
|
184
|
+
return { position: at(ms), velocity: scale(sub(at(ms + h), at(ms - h)), 1 / 7200) };
|
|
185
|
+
}
|
|
186
|
+
/** The osculating orbit of a state about the Sun. */
|
|
187
|
+
function elementsOf(position, velocity) {
|
|
188
|
+
const r = length(position);
|
|
189
|
+
const v2 = dot(velocity, velocity);
|
|
190
|
+
const h = cross(position, velocity);
|
|
191
|
+
const hLength = length(h);
|
|
192
|
+
const eccentricityVector = sub(scale(cross(velocity, h), 1 / GM_SUN), scale(position, 1 / r));
|
|
193
|
+
const e = length(eccentricityVector);
|
|
194
|
+
const a = 1 / (2 / r - v2 / GM_SUN);
|
|
195
|
+
const node = unit([-h[1], h[0], 0]);
|
|
196
|
+
const nodeAngle = Math.atan2(h[0], -h[1]);
|
|
197
|
+
const perihelionAngle = Math.atan2(dot(cross(node, eccentricityVector), unit(h)), dot(node, eccentricityVector));
|
|
198
|
+
const trueAnomaly = Math.atan2(dot(cross(eccentricityVector, position), unit(h)), dot(eccentricityVector, position));
|
|
199
|
+
const eccentricAnomaly = 2 * Math.atan2(Math.sqrt(1 - e) * Math.sin(trueAnomaly / 2), Math.sqrt(1 + e) * Math.cos(trueAnomaly / 2));
|
|
200
|
+
const meanAnomaly = eccentricAnomaly - e * Math.sin(eccentricAnomaly);
|
|
201
|
+
const turn = (radians) => (((radians * 180) / Math.PI) % 360 + 360) % 360;
|
|
202
|
+
return {
|
|
203
|
+
semiMajorAxisKm: a,
|
|
204
|
+
semiMajorAxisAu: a / AU_KM,
|
|
205
|
+
eccentricity: e,
|
|
206
|
+
inclination: (Math.acos(h[2] / hLength) * 180) / Math.PI,
|
|
207
|
+
ascendingNode: turn(nodeAngle),
|
|
208
|
+
argumentOfPerihelion: turn(perihelionAngle),
|
|
209
|
+
meanAnomaly: turn(meanAnomaly),
|
|
210
|
+
trueAnomaly: turn(trueAnomaly),
|
|
211
|
+
periodDays: (2 * Math.PI * Math.sqrt((a * a * a) / GM_SUN)) / 86_400,
|
|
212
|
+
perihelionKm: a * (1 - e),
|
|
213
|
+
perihelionAu: (a * (1 - e)) / AU_KM,
|
|
214
|
+
aphelionKm: a * (1 + e),
|
|
215
|
+
aphelionAu: (a * (1 + e)) / AU_KM,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* The osculating orbital elements about the Sun at a moment, from the state vector (the same numbers Horizons lists as EC, QR, IN, OM, W, A, AD and PR).
|
|
220
|
+
*
|
|
221
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
222
|
+
* @returns The elements.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* import { roadsterElements } from "@johnmorrisdotca/wakusei-planets/roadster";
|
|
227
|
+
*
|
|
228
|
+
* const orbit = roadsterElements(new Date("2026-11-11T00:00:00Z"));
|
|
229
|
+
* console.log(`perihelion ${orbit.perihelionAu.toFixed(3)} au, aphelion ${orbit.aphelionAu.toFixed(3)} au, period ${orbit.periodDays.toFixed(0)} days`);
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
export function roadsterElements(when) {
|
|
233
|
+
const { position, velocity } = state(moment(when));
|
|
234
|
+
return elementsOf(position, velocity);
|
|
235
|
+
}
|
|
236
|
+
/** The angle, in radians, that the car sweeps round the Sun between two states, about the direction of their angular momentum. */
|
|
237
|
+
function sweep(p0, v0, p1, v1) {
|
|
238
|
+
const axis = unit(add(cross(p0, v0), cross(p1, v1)));
|
|
239
|
+
return Math.atan2(dot(cross(p0, p1), axis), dot(p0, p1));
|
|
240
|
+
}
|
|
241
|
+
/** The angle swept round the Sun, in radians, from the first row to each row. A deterministic function of the table, worked out once. */
|
|
242
|
+
let swept;
|
|
243
|
+
function sweptAtRows() {
|
|
244
|
+
if (swept !== undefined)
|
|
245
|
+
return swept;
|
|
246
|
+
const out = new Float64Array(COUNT);
|
|
247
|
+
for (let i = 1; i < COUNT; i += 1) {
|
|
248
|
+
const a = (i - 1) * STRIDE;
|
|
249
|
+
const b = i * STRIDE;
|
|
250
|
+
out[i] = out[i - 1] + sweep([ROWS[a + 1], ROWS[a + 2], ROWS[a + 3]], [ROWS[a + 4], ROWS[a + 5], ROWS[a + 6]], [ROWS[b + 1], ROWS[b + 2], ROWS[b + 3]], [ROWS[b + 4], ROWS[b + 5], ROWS[b + 6]]);
|
|
251
|
+
}
|
|
252
|
+
swept = out;
|
|
253
|
+
return out;
|
|
254
|
+
}
|
|
255
|
+
/** The orbits of the Sun the car has made at a moment: the angle swept round the Sun since the launch over a full turn. The six hours from the launch to the first row are counted at the rate of that row (under a thousandth of an orbit). */
|
|
256
|
+
function orbitsAt(ms) {
|
|
257
|
+
const { position, velocity, seconds } = state(ms);
|
|
258
|
+
let lo = 0;
|
|
259
|
+
let hi = COUNT - 2;
|
|
260
|
+
while (lo < hi) {
|
|
261
|
+
const mid = (lo + hi + 1) >> 1;
|
|
262
|
+
if (ROWS[mid * STRIDE] * 3600 <= seconds)
|
|
263
|
+
lo = mid;
|
|
264
|
+
else
|
|
265
|
+
hi = mid - 1;
|
|
266
|
+
}
|
|
267
|
+
const a = lo * STRIDE;
|
|
268
|
+
const angle = sweptAtRows()[lo] + sweep([ROWS[a + 1], ROWS[a + 2], ROWS[a + 3]], [ROWS[a + 4], ROWS[a + 5], ROWS[a + 6]], position, velocity);
|
|
269
|
+
const first = { position: [ROWS[1], ROWS[2], ROWS[3]], velocity: [ROWS[4], ROWS[5], ROWS[6]] };
|
|
270
|
+
const rate = length(cross(first.position, first.velocity)) / dot(first.position, first.position);
|
|
271
|
+
const before = Math.max(0, (ROADSTER_START - toTerrestrialTime(LAUNCH)) / 1000);
|
|
272
|
+
return (angle + rate * before) / (2 * Math.PI);
|
|
273
|
+
}
|
|
274
|
+
/** The scan step for close approaches, in milliseconds. */
|
|
275
|
+
const UTC_STEP_MS = 2 * DAY_MS;
|
|
276
|
+
/** A closest approach counts when the distance falls under this many astronomical units: the Earth and Mars come to a least distance every few years, and most of those are far off. */
|
|
277
|
+
const APPROACH_AU = 1;
|
|
278
|
+
const approachMemo = new Map();
|
|
279
|
+
/** The distance between the car and a planet at a UTC moment, in kilometres. */
|
|
280
|
+
function distanceTo(id, ms) {
|
|
281
|
+
return length(sub(state(ms).position, scale(heliocentric(id, ms), AU_KM)));
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Every closest approach of the car to the Earth or to Mars inside the span of the path, in date order: a least value of the distance between the centres that is under one astronomical unit (found by scanning every two days and then narrowing each minimum to about a second).
|
|
285
|
+
* The car's launch, before the span, and the end of the span are not counted. The answer is the same every time, so it is worked out once and kept.
|
|
286
|
+
*
|
|
287
|
+
* @param body - `"earth"` or `"mars"`.
|
|
288
|
+
* @returns The approaches.
|
|
289
|
+
*
|
|
290
|
+
* @example
|
|
291
|
+
* ```ts
|
|
292
|
+
* import { roadsterApproaches } from "@johnmorrisdotca/wakusei-planets/roadster";
|
|
293
|
+
*
|
|
294
|
+
* for (const a of roadsterApproaches("mars")) console.log(new Date(a.date).toISOString().slice(0, 10), (a.distanceKm / 149597870.7).toFixed(3), "au");
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
export function roadsterApproaches(body) {
|
|
298
|
+
if (body !== "earth" && body !== "mars")
|
|
299
|
+
throw new RangeError(`body must be "earth" or "mars", got ${JSON.stringify(body)}`);
|
|
300
|
+
const kept = approachMemo.get(body);
|
|
301
|
+
if (kept !== undefined)
|
|
302
|
+
return kept;
|
|
303
|
+
const times = [];
|
|
304
|
+
const distances = [];
|
|
305
|
+
for (let t = RECORD_START; t < RECORD_END; t += UTC_STEP_MS) {
|
|
306
|
+
times.push(t);
|
|
307
|
+
distances.push(distanceTo(body, t));
|
|
308
|
+
}
|
|
309
|
+
times.push(RECORD_END);
|
|
310
|
+
distances.push(distanceTo(body, RECORD_END));
|
|
311
|
+
const found = [];
|
|
312
|
+
const phi = (Math.sqrt(5) - 1) / 2;
|
|
313
|
+
for (let i = 1; i < times.length - 1; i += 1) {
|
|
314
|
+
if (!(distances[i] < distances[i - 1] && distances[i] <= distances[i + 1] && distances[i] < APPROACH_AU * AU_KM * 1.05))
|
|
315
|
+
continue;
|
|
316
|
+
let lo = times[i - 1];
|
|
317
|
+
let hi = Math.min(times[i + 1], RECORD_END);
|
|
318
|
+
let c = hi - phi * (hi - lo);
|
|
319
|
+
let d = lo + phi * (hi - lo);
|
|
320
|
+
let fc = distanceTo(body, c);
|
|
321
|
+
let fd = distanceTo(body, d);
|
|
322
|
+
while (hi - lo > 1000) {
|
|
323
|
+
if (fc < fd) {
|
|
324
|
+
hi = d;
|
|
325
|
+
d = c;
|
|
326
|
+
fd = fc;
|
|
327
|
+
c = hi - phi * (hi - lo);
|
|
328
|
+
fc = distanceTo(body, c);
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
lo = c;
|
|
332
|
+
c = d;
|
|
333
|
+
fc = fd;
|
|
334
|
+
d = lo + phi * (hi - lo);
|
|
335
|
+
fd = distanceTo(body, d);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const date = (lo + hi) / 2;
|
|
339
|
+
const distanceKm = distanceTo(body, date);
|
|
340
|
+
if (distanceKm < APPROACH_AU * AU_KM)
|
|
341
|
+
found.push({ date, distanceKm });
|
|
342
|
+
}
|
|
343
|
+
approachMemo.set(body, found);
|
|
344
|
+
return found;
|
|
345
|
+
}
|
|
346
|
+
const distanceOf = (km) => ({ km, miles: km / MILE_KM, au: km / AU_KM, lightSeconds: km / LIGHT_KM_PER_SECOND });
|
|
347
|
+
function neighbours(list, ms) {
|
|
348
|
+
let previous = null;
|
|
349
|
+
let next = null;
|
|
350
|
+
for (const a of list) {
|
|
351
|
+
if (a.date <= ms)
|
|
352
|
+
previous = a;
|
|
353
|
+
else {
|
|
354
|
+
next = a;
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return { previous, next };
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* The car's numbers at a moment: its distance from the Sun, the Earth and Mars in kilometres, miles and astronomical units with the light time, its speed relative to each, the days since launch, the orbits of the Sun made, the period of its orbit now,
|
|
362
|
+
* and the closest approaches to the Earth and Mars before and after the moment inside the span. The Earth and Mars come from the package's own positions (`heliocentric`), with no allowance for the light's travel.
|
|
363
|
+
* A moment outside `ROADSTER.record` throws a `RangeError`.
|
|
364
|
+
*
|
|
365
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
366
|
+
* @returns The numbers.
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```ts
|
|
370
|
+
* import { roadsterStats } from "@johnmorrisdotca/wakusei-planets/roadster";
|
|
371
|
+
*
|
|
372
|
+
* const stats = roadsterStats(new Date("2026-11-11T12:00:00Z"));
|
|
373
|
+
* console.log(Math.round(stats.earth.km / 1e6), "million km from the Earth,", stats.orbitsCompleted, "orbits of the Sun,", stats.speed.sun.toFixed(1), "km/s");
|
|
374
|
+
* ```
|
|
375
|
+
*/
|
|
376
|
+
export function roadsterStats(when) {
|
|
377
|
+
const ms = moment(when);
|
|
378
|
+
const { position, velocity } = state(ms);
|
|
379
|
+
const earth = planetState("earth", ms);
|
|
380
|
+
const mars = planetState("mars", ms);
|
|
381
|
+
const orbits = orbitsAt(ms);
|
|
382
|
+
return {
|
|
383
|
+
when: ms,
|
|
384
|
+
sun: distanceOf(length(position)),
|
|
385
|
+
earth: distanceOf(length(sub(position, earth.position))),
|
|
386
|
+
mars: distanceOf(length(sub(position, mars.position))),
|
|
387
|
+
speed: { sun: length(velocity), earth: length(sub(velocity, earth.velocity)), mars: length(sub(velocity, mars.velocity)) },
|
|
388
|
+
daysSinceLaunch: (ms - LAUNCH) / DAY_MS,
|
|
389
|
+
orbits,
|
|
390
|
+
orbitsCompleted: Math.floor(orbits),
|
|
391
|
+
periodDays: elementsOf(position, velocity).periodDays,
|
|
392
|
+
approaches: { earth: neighbours(roadsterApproaches("earth"), ms), mars: neighbours(roadsterApproaches("mars"), ms) },
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
const NAMES = {
|
|
396
|
+
launch: { en: "Launch", ja: "打ち上げ" },
|
|
397
|
+
"earth-approach": { en: "Closest approach to the Earth", ja: "地球に最接近" },
|
|
398
|
+
"mars-approach": { en: "Closest approach to Mars", ja: "火星に最接近" },
|
|
399
|
+
perihelion: { en: "Perihelion (closest to the Sun)", ja: "近日点通過" },
|
|
400
|
+
aphelion: { en: "Aphelion (furthest from the Sun)", ja: "遠日点通過" },
|
|
401
|
+
};
|
|
402
|
+
let eventMemo;
|
|
403
|
+
/** The moments of perihelion and aphelion: where the radial speed (the dot product of the position and the velocity) changes sign, found between rows and narrowed by bisection. */
|
|
404
|
+
function sunExtremes() {
|
|
405
|
+
const out = [];
|
|
406
|
+
const radial = (i) => ROWS[i * STRIDE + 1] * ROWS[i * STRIDE + 4] + ROWS[i * STRIDE + 2] * ROWS[i * STRIDE + 5] + ROWS[i * STRIDE + 3] * ROWS[i * STRIDE + 6];
|
|
407
|
+
for (let i = 0; i < COUNT - 1; i += 1) {
|
|
408
|
+
const before = radial(i);
|
|
409
|
+
const after = radial(i + 1);
|
|
410
|
+
if (before === 0 || Math.sign(before) === Math.sign(after))
|
|
411
|
+
continue;
|
|
412
|
+
let lo = ROADSTER_START + ROWS[i * STRIDE] * 3_600_000;
|
|
413
|
+
let hi = ROADSTER_START + ROWS[(i + 1) * STRIDE] * 3_600_000;
|
|
414
|
+
const at = (tt) => {
|
|
415
|
+
const s = state(utcOfTerrestrial(tt));
|
|
416
|
+
return dot(s.position, s.velocity);
|
|
417
|
+
};
|
|
418
|
+
const sign = Math.sign(before);
|
|
419
|
+
while (hi - lo > 100) {
|
|
420
|
+
const mid = (lo + hi) / 2;
|
|
421
|
+
if (Math.sign(at(mid)) === sign)
|
|
422
|
+
lo = mid;
|
|
423
|
+
else
|
|
424
|
+
hi = mid;
|
|
425
|
+
}
|
|
426
|
+
const date = utcOfTerrestrial((lo + hi) / 2);
|
|
427
|
+
const kind = sign < 0 ? "perihelion" : "aphelion";
|
|
428
|
+
out.push({ kind, date, name: NAMES[kind], distanceKm: length(state(date).position) });
|
|
429
|
+
}
|
|
430
|
+
return out;
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Every moment of the car's story the table can find, in date order, each with a name in English and Japanese: the launch, each closest approach to the Earth and to Mars, and each perihelion and aphelion passage inside the span.
|
|
434
|
+
* A page can list them and jump to any one. The answer is the same every time, so it is worked out once and kept.
|
|
435
|
+
*
|
|
436
|
+
* @returns The events.
|
|
437
|
+
*
|
|
438
|
+
* @example
|
|
439
|
+
* ```ts
|
|
440
|
+
* import { roadsterEvents } from "@johnmorrisdotca/wakusei-planets/roadster";
|
|
441
|
+
*
|
|
442
|
+
* for (const e of roadsterEvents().slice(0, 5)) console.log(new Date(e.date).toISOString().slice(0, 10), e.name.en);
|
|
443
|
+
* ```
|
|
444
|
+
*/
|
|
445
|
+
export function roadsterEvents() {
|
|
446
|
+
if (eventMemo !== undefined)
|
|
447
|
+
return eventMemo;
|
|
448
|
+
const list = [{ kind: "launch", date: LAUNCH, name: NAMES.launch }];
|
|
449
|
+
for (const a of roadsterApproaches("earth"))
|
|
450
|
+
list.push({ kind: "earth-approach", date: a.date, name: NAMES["earth-approach"], distanceKm: a.distanceKm });
|
|
451
|
+
for (const a of roadsterApproaches("mars"))
|
|
452
|
+
list.push({ kind: "mars-approach", date: a.date, name: NAMES["mars-approach"], distanceKm: a.distanceKm });
|
|
453
|
+
list.push(...sunExtremes());
|
|
454
|
+
eventMemo = list.sort((a, b) => a.date - b.date);
|
|
455
|
+
return eventMemo;
|
|
456
|
+
}
|
|
457
|
+
/** The most moments one series holds, so that one call cannot take the page's time. */
|
|
458
|
+
const MAX_SERIES = 100_000;
|
|
459
|
+
/**
|
|
460
|
+
* The car's distance from the Sun, the Earth and Mars, and its speed relative to the Sun, at equal steps from one moment to another, ready to graph. Both ends must be inside `ROADSTER.record`; a step that is not positive, or a series of more than 100,000 moments, throws a `RangeError`.
|
|
461
|
+
*
|
|
462
|
+
* @param from - The first moment: a `Date` or milliseconds since 1970 (UTC).
|
|
463
|
+
* @param to - The last moment, not before the first.
|
|
464
|
+
* @param stepMs - The step in milliseconds.
|
|
465
|
+
* @returns The series.
|
|
466
|
+
*
|
|
467
|
+
* @example
|
|
468
|
+
* ```ts
|
|
469
|
+
* import { roadsterSeries } from "@johnmorrisdotca/wakusei-planets/roadster";
|
|
470
|
+
*
|
|
471
|
+
* const { times, earthKm } = roadsterSeries(new Date("2019-01-01T00:00:00Z"), new Date("2020-01-01T00:00:00Z"), 7 * 86_400_000);
|
|
472
|
+
* console.log(times.length, "weeks; nearest", Math.round(Math.min(...earthKm) / 1e6), "million km from the Earth");
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
export function roadsterSeries(from, to, stepMs) {
|
|
476
|
+
const start = moment(from, "from");
|
|
477
|
+
const end = moment(to, "to");
|
|
478
|
+
if (!Number.isFinite(stepMs) || !(stepMs > 0))
|
|
479
|
+
throw new RangeError(`stepMs must be a positive number of milliseconds, got ${String(stepMs)}`);
|
|
480
|
+
if (end < start)
|
|
481
|
+
throw new RangeError("to must not be before from");
|
|
482
|
+
const count = Math.floor((end - start) / stepMs) + 1;
|
|
483
|
+
if (count > MAX_SERIES)
|
|
484
|
+
throw new RangeError(`${count} moments is more than the ${MAX_SERIES} a series holds: use a larger step`);
|
|
485
|
+
const series = { times: [], sunKm: [], earthKm: [], marsKm: [], speed: [] };
|
|
486
|
+
for (let i = 0; i < count; i += 1) {
|
|
487
|
+
const ms = start + i * stepMs;
|
|
488
|
+
const { position, velocity } = state(ms);
|
|
489
|
+
series.times.push(ms);
|
|
490
|
+
series.sunKm.push(length(position));
|
|
491
|
+
series.earthKm.push(length(sub(position, scale(heliocentric("earth", ms), AU_KM))));
|
|
492
|
+
series.marsKm.push(length(sub(position, scale(heliocentric("mars", ms), AU_KM))));
|
|
493
|
+
series.speed.push(length(velocity));
|
|
494
|
+
}
|
|
495
|
+
return series;
|
|
496
|
+
}
|
package/dist/scene/body.d.ts
CHANGED
|
@@ -7,9 +7,10 @@ import type { SourceBook } from "../door/book.ts";
|
|
|
7
7
|
import type { BodyMapSource } from "../door/map.ts";
|
|
8
8
|
import { type DetailStats } from "./detail.ts";
|
|
9
9
|
import type { TileLevel } from "./tiles.ts";
|
|
10
|
+
import { type NameLabelOptions } from "./name-label.ts";
|
|
10
11
|
export { fallbackLook } from "./fallback.ts";
|
|
11
|
-
/** The parts of three.js the bodies use: a page may hand over a module with only these (see `setThreeLoader`). */
|
|
12
|
-
export type ThreeParts = Pick<typeof THREE, "AdditiveBlending" | "BufferAttribute" | "BufferGeometry" | "ClampToEdgeWrapping" | "DataTexture" | "DoubleSide" | "Group" | "Line" | "LineBasicMaterial" | "LineSegments" | "LinearFilter" | "Mesh" | "NoColorSpace" | "OrthographicCamera" | "PlaneGeometry" | "RepeatWrapping" | "RGBAFormat" | "RingGeometry" | "Scene" | "ShaderMaterial" | "SphereGeometry" | "TextureLoader" | "Vector2" | "Vector3" | "WebGLRenderer"
|
|
12
|
+
/** The parts of three.js the bodies use: a page may hand over a module with only these (see `setThreeLoader`). `CanvasTexture`, `SRGBColorSpace` and `NormalBlending` are needed only for a name written on a body (`body-label`). */
|
|
13
|
+
export type ThreeParts = Pick<typeof THREE, "AdditiveBlending" | "BufferAttribute" | "BufferGeometry" | "ClampToEdgeWrapping" | "DataTexture" | "DoubleSide" | "Group" | "Line" | "LineBasicMaterial" | "LineSegments" | "LinearFilter" | "Mesh" | "NoColorSpace" | "OrthographicCamera" | "PlaneGeometry" | "RepeatWrapping" | "RGBAFormat" | "RingGeometry" | "Scene" | "ShaderMaterial" | "SphereGeometry" | "TextureLoader" | "Vector2" | "Vector3" | "WebGLRenderer"> & Partial<Pick<typeof THREE, "CanvasTexture" | "SRGBColorSpace" | "NormalBlending">>;
|
|
13
14
|
/** One moon in a system view: its place in planet radii (viewer's frame) and the points of its orbit, if they changed. */
|
|
14
15
|
export interface MoonDraw {
|
|
15
16
|
id: BodyId;
|
|
@@ -34,6 +35,10 @@ export interface SceneState {
|
|
|
34
35
|
minMoonPx?: number;
|
|
35
36
|
/** The colour of the orbit lines, `#rrggbb`. */
|
|
36
37
|
orbitColour?: string;
|
|
38
|
+
/** The body's name written on its globe: the text and the look, or none. */
|
|
39
|
+
label?: ({
|
|
40
|
+
text: string;
|
|
41
|
+
} & NameLabelOptions) | null;
|
|
37
42
|
}
|
|
38
43
|
/** The scene the shared renderer draws, with the one call that moves it. */
|
|
39
44
|
export interface BodyScene extends Scene3D {
|
|
@@ -43,6 +48,12 @@ export interface BodyScene extends Scene3D {
|
|
|
43
48
|
readonly painted: boolean;
|
|
44
49
|
/** The window of finer map on the body, or `undefined` for a body with none (a glowing one, or one with no painted map). */
|
|
45
50
|
readonly detail: DetailStats | undefined;
|
|
51
|
+
/** The name on the globe now: whether it is drawn (made, its font in, and the body big enough), its text, and its turn about the pole in radians (for `facing`); `null` for none. */
|
|
52
|
+
readonly label: {
|
|
53
|
+
shown: boolean;
|
|
54
|
+
text: string;
|
|
55
|
+
turn: number;
|
|
56
|
+
} | null;
|
|
46
57
|
}
|
|
47
58
|
export interface BodyItemOptions {
|
|
48
59
|
id: BodyId;
|
package/dist/scene/body.js
CHANGED
|
@@ -8,6 +8,7 @@ import { fallbackLook } from "./fallback.js";
|
|
|
8
8
|
import { writeBasis } from "./basis.js";
|
|
9
9
|
import { loadImage } from "./textures.js";
|
|
10
10
|
import { ringStrip } from "./rings.js";
|
|
11
|
+
import { createNameLabel } from "./name-label.js";
|
|
11
12
|
export { fallbackLook } from "./fallback.js";
|
|
12
13
|
/** The shader material of a body: its surface code with the look's lighting and glow uniforms. A star made from numbers is drawn with it too (the size line-up). */
|
|
13
14
|
export function makeBodyMaterial(T, look, painted) {
|
|
@@ -353,6 +354,31 @@ export function createBodyItem(options) {
|
|
|
353
354
|
}
|
|
354
355
|
}
|
|
355
356
|
};
|
|
357
|
+
// the name on the globe: a child of the mesh, so it turns with the body
|
|
358
|
+
// the element hands over the same label object until a setting changes, so a draw compares by reference and does no work when nothing did
|
|
359
|
+
let label;
|
|
360
|
+
let labelApplied = undefined;
|
|
361
|
+
const syncLabel = (state) => {
|
|
362
|
+
if (state.label === labelApplied)
|
|
363
|
+
return;
|
|
364
|
+
labelApplied = state.label;
|
|
365
|
+
if (!state.label) {
|
|
366
|
+
if (label !== undefined) {
|
|
367
|
+
mesh.remove(label.object);
|
|
368
|
+
label.dispose();
|
|
369
|
+
label = undefined;
|
|
370
|
+
}
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
if (label === undefined) {
|
|
374
|
+
label = createNameLabel(T, state.label.text, state.label, look.emissive === true, () => options.redraw());
|
|
375
|
+
mesh.add(label.object);
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
label.set(state.label.text, state.label);
|
|
379
|
+
options.redraw();
|
|
380
|
+
}
|
|
381
|
+
};
|
|
356
382
|
const light = new T.Vector3();
|
|
357
383
|
const pole = new T.Vector3();
|
|
358
384
|
const apply = (state) => {
|
|
@@ -360,6 +386,7 @@ export function createBodyItem(options) {
|
|
|
360
386
|
orient(state);
|
|
361
387
|
frame(state);
|
|
362
388
|
place(state);
|
|
389
|
+
syncLabel(state);
|
|
363
390
|
light.set(...state.pose.light);
|
|
364
391
|
if (ringHalves !== undefined) {
|
|
365
392
|
pole.set(...state.pose.pole);
|
|
@@ -400,6 +427,9 @@ export function createBodyItem(options) {
|
|
|
400
427
|
glow.scale.setScalar(1);
|
|
401
428
|
}
|
|
402
429
|
requestSharperTexture(state);
|
|
430
|
+
// the disc's radius on the screen in CSS pixels: the short side's half at zoom 1 over the extent
|
|
431
|
+
if (label !== undefined)
|
|
432
|
+
label.update(camera, ((aspect >= 1 ? viewHeight : viewWidth) / 2) * (state.zoom / state.extent), state.pose.light);
|
|
403
433
|
if (detail !== undefined && textureWidth > 0) {
|
|
404
434
|
const east = cross(state.pose.pole, state.pose.meridian);
|
|
405
435
|
const ax = facts.axesKm;
|
|
@@ -421,6 +451,10 @@ export function createBodyItem(options) {
|
|
|
421
451
|
get detail() {
|
|
422
452
|
return detail?.stats;
|
|
423
453
|
},
|
|
454
|
+
get label() {
|
|
455
|
+
const inner = label?.object.children[0];
|
|
456
|
+
return label === undefined || latest.label === undefined || latest.label === null ? null : { shown: label.ready && inner !== undefined && inner.visible, text: latest.label.text, turn: inner?.rotation.y ?? 0 };
|
|
457
|
+
},
|
|
424
458
|
resize(w, h) {
|
|
425
459
|
viewWidth = w;
|
|
426
460
|
viewHeight = h;
|
|
@@ -438,6 +472,8 @@ export function createBodyItem(options) {
|
|
|
438
472
|
windowUniforms.uDetail.value = null;
|
|
439
473
|
}
|
|
440
474
|
detail?.dispose();
|
|
475
|
+
label?.dispose();
|
|
476
|
+
label = undefined;
|
|
441
477
|
for (const o of orbitLines.values())
|
|
442
478
|
o.line.geometry.dispose();
|
|
443
479
|
orbitMaterial.dispose();
|