@johnmorrisdotca/wakusei-planets 0.48.0 → 0.50.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.
@@ -21,6 +21,12 @@ export interface LandOptions {
21
21
  pitch?: number;
22
22
  fov?: number;
23
23
  };
24
+ /** `"landing"` to watch Apollo 17's powered descent once down (the real moment: its Sun and Earth, the clock from T+4:00 or T+9:00): see `watch` of the standing view. */
25
+ watch?: "landing";
26
+ /** Which camera watches: `lander` (the commander's window, the default) or `ground` (an observer standing off the touchdown point). */
27
+ watchCamera?: "lander" | "ground";
28
+ /** Where the ground camera stands, as `"150 0"`: metres from the touchdown point and the bearing in degrees clockwise from north (150 m north by default). */
29
+ watchFrom?: string;
24
30
  /** False to cut straight to the ground with no turn, no zoom and no fade (reduced motion does the same). */
25
31
  smooth?: boolean;
26
32
  /** Milliseconds to wait for the standing view to be live before giving up (20,000 by default). */
@@ -176,6 +176,14 @@ export async function land(space, siteId, options = {}) {
176
176
  veil.style.opacity = "0";
177
177
  fail(live ? "this device cannot draw the ground" : "the ground did not come in time");
178
178
  }
179
+ // watching the descent: the standing view starts it as the veil goes up, so the first thing seen is its first frame
180
+ if (options.watch === "landing") {
181
+ if (options.watchCamera !== undefined)
182
+ surface.setAttribute("watch-camera", options.watchCamera);
183
+ if (options.watchFrom !== undefined)
184
+ surface.setAttribute("watch-from", options.watchFrom);
185
+ surface.setAttribute("watch", "landing");
186
+ }
179
187
  veil.style.opacity = "0";
180
188
  if (smooth)
181
189
  await sleep(FADE_MS, landing);
@@ -0,0 +1,134 @@
1
+ /**
2
+ * The descent's fixed facts: its length in seconds, when it began in real time, where the lunar module was at ignition, and the clock the view starts at (T+4:00, where the report has the radar locked: the first
3
+ * four minutes are 530 km up-range of the ground the package has, so they are a time lapse of the clock with no ground).
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { LANDING } from "@johnmorrisdotca/wakusei-planets/surface";
8
+ *
9
+ * console.log(`${LANDING.duration} s from ${new Date(LANDING.ignition).toISOString()}`);
10
+ * ```
11
+ */
12
+ export declare const LANDING: {
13
+ /** Seconds from ignition to touchdown (the report's 12:05). */
14
+ readonly duration: 725;
15
+ /** Ignition in real time: 110:09:53 ground elapsed time, 12:05 before the touchdown at 19:54:57 UTC on 1972-12-11. */
16
+ readonly ignition: number;
17
+ /** The clock the view starts at, in seconds from ignition. */
18
+ readonly viewStart: 240;
19
+ /** At ignition (table 3-III): latitude and east longitude in degrees, altitude in metres (8.7 nautical miles), speed in m/s (5,550.3 ft/s) and heading (276.07 degrees). */
20
+ readonly start: {
21
+ readonly lat: 19.13;
22
+ readonly lon: 48.75;
23
+ readonly altitude: number;
24
+ readonly speed: number;
25
+ readonly heading: 276.07;
26
+ };
27
+ /** The ground speed the made curve ends at, and the descent rate at touchdown the report gives ("approximately 3 ft/sec"), in m/s. */
28
+ readonly touchdownDescent: number;
29
+ };
30
+ /**
31
+ * Where the lunar module is and how it moves at one moment of the descent.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { landingAt, type LandingPose } from "@johnmorrisdotca/wakusei-planets/surface";
36
+ *
37
+ * const pose: LandingPose = landingAt(600);
38
+ * console.log(`${Math.round(pose.altitude)} m up, ${pose.descent.toFixed(1)} m/s down, throttle ${pose.throttle.toFixed(2)}`);
39
+ * ```
40
+ */
41
+ export interface LandingPose {
42
+ /** Seconds from ignition. */
43
+ t: number;
44
+ /** Metres over the ground under it, and metres a second down (positive down) and along the ground. */
45
+ altitude: number;
46
+ descent: number;
47
+ speed: number;
48
+ /** Metres still to go along the ground to the touchdown point. */
49
+ toGo: number;
50
+ /** Metres east and north of the touchdown point, on the site's plane, and the heading it flies, degrees clockwise from north. */
51
+ east: number;
52
+ north: number;
53
+ heading: number;
54
+ /** The way the crew's window looks, degrees above the horizon (negative looks down), and the share of full thrust. */
55
+ pitch: number;
56
+ throttle: number;
57
+ }
58
+ /**
59
+ * The lunar module at a moment of the descent. The altitude passes through the altitudes the report names, the speed starts at the report's and covers the real distance to the touchdown point, and the rest is a
60
+ * smooth curve of ours: `east` and `north` are on a straight line back from the touchdown point toward where the descent began, in metres on the site's plane (the curve of the Moon is the ground's to take off).
61
+ *
62
+ * @param t - Seconds from ignition (held between 0 and the length of the descent).
63
+ * @returns The pose.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * import { landingAt } from "@johnmorrisdotca/wakusei-planets/surface";
68
+ *
69
+ * const high = landingAt(562);
70
+ * console.log(`${Math.round(high.altitude)} m up at the high gate, ${high.speed.toFixed(0)} m/s along, ${Math.round(high.toGo)} m to go`);
71
+ * ```
72
+ */
73
+ export declare function landingAt(t: number): LandingPose;
74
+ /**
75
+ * One event the page shows as it passes: when (seconds from ignition), what it is in English and Japanese, and whether its TIME is the report's (the altitude events are placed by us on the curve).
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * import { CALLOUTS, type Callout } from "@johnmorrisdotca/wakusei-planets/surface";
80
+ *
81
+ * const touchdown: Callout = CALLOUTS.find((c) => c.id === "touchdown")!;
82
+ * console.log(touchdown.en, touchdown.reported);
83
+ * ```
84
+ */
85
+ export interface Callout {
86
+ id: string;
87
+ t: number;
88
+ en: string;
89
+ ja: string;
90
+ /** True where the time comes from the report's table of events; false where it is the moment the made curve reaches the altitude the report names. */
91
+ reported: boolean;
92
+ }
93
+ /**
94
+ * The events of the descent as the report gives them (the times in its table of events) and the altitudes it names (placed on the curve), in the order they pass.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * import { CALLOUTS } from "@johnmorrisdotca/wakusei-planets/surface";
99
+ *
100
+ * console.log(CALLOUTS.map((c) => `T+${c.t}s ${c.en}`).join("; "));
101
+ * ```
102
+ */
103
+ export declare const CALLOUTS: readonly Callout[];
104
+ /**
105
+ * The events that have passed by a moment, the latest last.
106
+ *
107
+ * @param t - Seconds from ignition.
108
+ * @returns The events with a time at or before `t`.
109
+ *
110
+ * @example
111
+ * ```ts
112
+ * import { calloutsBy } from "@johnmorrisdotca/wakusei-planets/surface";
113
+ *
114
+ * console.log(calloutsBy(600).map((c) => c.id).join(", "));
115
+ * ```
116
+ */
117
+ export declare function calloutsBy(t: number): Callout[];
118
+ /**
119
+ * The clock as the page shows it: `T+04:00` from ignition, and the ground elapsed time of the mission (ignition was 110:09:53).
120
+ *
121
+ * @param t - Seconds from ignition.
122
+ * @returns The two clocks as text.
123
+ *
124
+ * @example
125
+ * ```ts
126
+ * import { clockText } from "@johnmorrisdotca/wakusei-planets/surface";
127
+ *
128
+ * console.log(clockText(240));
129
+ * ```
130
+ */
131
+ export declare function clockText(t: number): {
132
+ t: string;
133
+ get: string;
134
+ };
@@ -0,0 +1,237 @@
1
+ // Apollo 17's powered descent as a function of time: where the lunar module is, how high, how fast and which way it points at each second from ignition to touchdown. What is REAL is what the Apollo 17 Mission
2
+ // Report (NASA, JSC-07904, NTRS 19730015117) prints: the times of the events (table 8-VI), the state at ignition (table 3-III: place, altitude, speed, heading), the altitudes it names in words (30,000 ft after the radar
3
+ // locked, 13,000 ft, pitchover at about 7,500 ft, manual takeover just under 300 ft, dust at 60 to 70 ft, touchdown at about 3 ft/s) and the place of touchdown. What is MADE is the smooth curve through those moments
4
+ // (the report prints no full table), the path on the ground between the start and the end, the attitude between events and the throttle. The page says so. Pure: no DOM.
5
+ const FT = 0.3048;
6
+ const NMI = 1852;
7
+ const R_MOON = 1_737_400;
8
+ /**
9
+ * The descent's fixed facts: its length in seconds, when it began in real time, where the lunar module was at ignition, and the clock the view starts at (T+4:00, where the report has the radar locked: the first
10
+ * four minutes are 530 km up-range of the ground the package has, so they are a time lapse of the clock with no ground).
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { LANDING } from "@johnmorrisdotca/wakusei-planets/surface";
15
+ *
16
+ * console.log(`${LANDING.duration} s from ${new Date(LANDING.ignition).toISOString()}`);
17
+ * ```
18
+ */
19
+ export const LANDING = {
20
+ /** Seconds from ignition to touchdown (the report's 12:05). */
21
+ duration: 725,
22
+ /** Ignition in real time: 110:09:53 ground elapsed time, 12:05 before the touchdown at 19:54:57 UTC on 1972-12-11. */
23
+ ignition: Date.UTC(1972, 11, 11, 19, 42, 52),
24
+ /** The clock the view starts at, in seconds from ignition. */
25
+ viewStart: 240,
26
+ /** At ignition (table 3-III): latitude and east longitude in degrees, altitude in metres (8.7 nautical miles), speed in m/s (5,550.3 ft/s) and heading (276.07 degrees). */
27
+ start: { lat: 19.13, lon: 48.75, altitude: 8.7 * NMI, speed: 5550.3 * FT, heading: 276.07 },
28
+ /** The ground speed the made curve ends at, and the descent rate at touchdown the report gives ("approximately 3 ft/sec"), in m/s. */
29
+ touchdownDescent: 3 * FT,
30
+ };
31
+ // The altitude through the moments the report names; the times of those it gives no clock for (30,000 ft, 13,000 ft, manual takeover, dust) are placed by us between the times it does give.
32
+ const ALTITUDE = [
33
+ [0, LANDING.start.altitude],
34
+ [255, 30_000 * FT],
35
+ [500, 13_000 * FT],
36
+ [562, 7_500 * FT],
37
+ [658, 152],
38
+ [678, 90],
39
+ [715, 20],
40
+ [722, 2.5],
41
+ [725, 0],
42
+ ];
43
+ // The speed along the ground: the start is the report's, the end is "near zero", the rest is made to fall smoothly and to cover the real distance from the start to the touchdown (the weights below are scaled to it).
44
+ const SPEED_SHAPE = [
45
+ [0, LANDING.start.speed],
46
+ [120, 1370],
47
+ [255, 1000],
48
+ [446, 430],
49
+ [562, 60],
50
+ [658, 8],
51
+ [700, 1.5],
52
+ [725, 0.5],
53
+ ];
54
+ /** A piecewise cubic through points that never overshoots (Fritsch-Carlson), as a function of t. */
55
+ function monotone(points) {
56
+ const n = points.length;
57
+ const h = [];
58
+ const d = [];
59
+ for (let i = 0; i < n - 1; i += 1) {
60
+ h.push(points[i + 1][0] - points[i][0]);
61
+ d.push((points[i + 1][1] - points[i][1]) / h[i]);
62
+ }
63
+ const m = new Array(n).fill(0);
64
+ m[0] = d[0];
65
+ m[n - 1] = d[n - 2];
66
+ for (let i = 1; i < n - 1; i += 1) {
67
+ if (d[i - 1] * d[i] <= 0)
68
+ m[i] = 0;
69
+ else {
70
+ const w1 = 2 * h[i] + h[i - 1];
71
+ const w2 = h[i] + 2 * h[i - 1];
72
+ m[i] = (w1 + w2) / (w1 / d[i - 1] + w2 / d[i]);
73
+ }
74
+ }
75
+ return (t) => {
76
+ if (t <= points[0][0])
77
+ return points[0][1];
78
+ if (t >= points[n - 1][0])
79
+ return points[n - 1][1];
80
+ let i = 0;
81
+ while (t > points[i + 1][0])
82
+ i += 1;
83
+ const s = (t - points[i][0]) / h[i];
84
+ const [s2, s3] = [s * s, s * s * s];
85
+ return (2 * s3 - 3 * s2 + 1) * points[i][1] + (s3 - 2 * s2 + s) * h[i] * m[i] + (-2 * s3 + 3 * s2) * points[i + 1][1] + (s3 - s2) * h[i] * m[i + 1];
86
+ };
87
+ }
88
+ /** The great-circle distance in metres between two places on the Moon given in degrees (a sphere of 1,737.4 km). */
89
+ function distance(lat1, lon1, lat2, lon2) {
90
+ const [p1, p2, dl] = [(lat1 * Math.PI) / 180, (lat2 * Math.PI) / 180, ((lon2 - lon1) * Math.PI) / 180];
91
+ const a = Math.sin(p1) * Math.sin(p2) + Math.cos(p1) * Math.cos(p2) * Math.cos(dl);
92
+ return R_MOON * Math.acos(Math.min(1, Math.max(-1, a)));
93
+ }
94
+ /** The place of touchdown the report gives is the lunar module's own place in the package (the orbiter's picture of it): the site point of Apollo 17 as the places list has it. */
95
+ const SITE = { lat: 20.1911, lon: 30.7723 };
96
+ const altitudeAt = monotone(ALTITUDE);
97
+ const DISTANCE = distance(LANDING.start.lat, LANDING.start.lon, SITE.lat, SITE.lon);
98
+ /** The speed curve scaled in its middle so that it covers the real distance from ignition to touchdown, and the distance still to go at each second. */
99
+ const { speedAt, toGoAt } = (() => {
100
+ const total = (k) => {
101
+ const shape = SPEED_SHAPE.map(([t, v], i) => (i === 0 || i === SPEED_SHAPE.length - 1 ? [t, v] : [t, v * k]));
102
+ const f = monotone(shape);
103
+ const to = new Array(LANDING.duration + 1).fill(0);
104
+ for (let t = LANDING.duration - 1; t >= 0; t -= 1)
105
+ to[t] = to[t + 1] + (f(t) + f(t + 1)) / 2;
106
+ return { f, to };
107
+ };
108
+ let [lo, hi] = [0.5, 1.5];
109
+ for (let i = 0; i < 50; i += 1) {
110
+ const mid = (lo + hi) / 2;
111
+ if (total(mid).to[0] < DISTANCE)
112
+ lo = mid;
113
+ else
114
+ hi = mid;
115
+ }
116
+ const fit = total((lo + hi) / 2);
117
+ return {
118
+ speedAt: fit.f,
119
+ toGoAt: (t) => {
120
+ const c = Math.min(Math.max(t, 0), LANDING.duration);
121
+ const i = Math.min(LANDING.duration - 1, Math.floor(c));
122
+ return fit.to[i] - (fit.to[i] - fit.to[i + 1]) * (c - i);
123
+ },
124
+ };
125
+ })();
126
+ /** The direction from the touchdown back to the start of the descent on the site's plane (east, north), and the heading flown, from the two places. */
127
+ const BACK = (() => {
128
+ const dLat = SITE.lat - LANDING.start.lat;
129
+ const north = -R_MOON * (dLat * Math.PI) / 180;
130
+ const east = R_MOON * Math.cos(((SITE.lat + LANDING.start.lat) / 2 * Math.PI) / 180) * (((LANDING.start.lon - SITE.lon) * Math.PI) / 180);
131
+ const length = Math.hypot(east, north);
132
+ return { east: east / length, north: north / length, heading: ((Math.atan2(-east, -north) * 180) / Math.PI + 360) % 360 };
133
+ })();
134
+ /**
135
+ * The lunar module at a moment of the descent. The altitude passes through the altitudes the report names, the speed starts at the report's and covers the real distance to the touchdown point, and the rest is a
136
+ * smooth curve of ours: `east` and `north` are on a straight line back from the touchdown point toward where the descent began, in metres on the site's plane (the curve of the Moon is the ground's to take off).
137
+ *
138
+ * @param t - Seconds from ignition (held between 0 and the length of the descent).
139
+ * @returns The pose.
140
+ *
141
+ * @example
142
+ * ```ts
143
+ * import { landingAt } from "@johnmorrisdotca/wakusei-planets/surface";
144
+ *
145
+ * const high = landingAt(562);
146
+ * console.log(`${Math.round(high.altitude)} m up at the high gate, ${high.speed.toFixed(0)} m/s along, ${Math.round(high.toGo)} m to go`);
147
+ * ```
148
+ */
149
+ export function landingAt(t) {
150
+ const c = Math.min(Math.max(t, 0), LANDING.duration);
151
+ const altitude = altitudeAt(c);
152
+ const ce = Math.min(Math.max(c, 0.25), LANDING.duration - 0.25);
153
+ const descent = -(altitudeAt(ce + 0.25) - altitudeAt(ce - 0.25)) / 0.5;
154
+ const toGo = toGoAt(c);
155
+ // the window: level in the braking, then the pitchover to look down at the site from the high gate, easing toward the horizon near the ground
156
+ const ease = (a, b, from, to) => {
157
+ const s = Math.min(1, Math.max(0, (c - from) / (to - from)));
158
+ return a + (b - a) * (s * s * (3 - 2 * s));
159
+ };
160
+ const pitch = c < 562 ? ease(10, 14, 0, 562) : c < 658 ? ease(14, -38, 562, 590) : ease(-38, -20, 658, 725);
161
+ const throttle = c < 28 ? 0.1 + 0.9 * (c / 28) : c < 446 ? 1 : c < 562 ? 0.57 : 0.34 + 0.12 * Math.sin(c / 7);
162
+ return {
163
+ t: c,
164
+ altitude,
165
+ descent,
166
+ speed: speedAt(c),
167
+ toGo,
168
+ east: BACK.east * toGo,
169
+ north: BACK.north * toGo,
170
+ heading: BACK.heading,
171
+ pitch,
172
+ throttle,
173
+ };
174
+ }
175
+ const when = (altitude) => {
176
+ let t = 0;
177
+ while (t < LANDING.duration && altitudeAt(t) > altitude)
178
+ t += 0.5;
179
+ return t;
180
+ };
181
+ /**
182
+ * The events of the descent as the report gives them (the times in its table of events) and the altitudes it names (placed on the curve), in the order they pass.
183
+ *
184
+ * @example
185
+ * ```ts
186
+ * import { CALLOUTS } from "@johnmorrisdotca/wakusei-planets/surface";
187
+ *
188
+ * console.log(CALLOUTS.map((c) => `T+${c.t}s ${c.en}`).join("; "));
189
+ * ```
190
+ */
191
+ export const CALLOUTS = [
192
+ { id: "ignition", t: 0, en: "Descent engine ignition", ja: "降下エンジン点火", reported: true },
193
+ { id: "full", t: 28, en: "Full throttle", ja: "全開", reported: true },
194
+ { id: "radar", t: 215, en: "Landing radar locks on", ja: "着陸レーダーが捉える", reported: true },
195
+ { id: "throttle", t: 446, en: "Throttle down", ja: "スロットルを絞る", reported: true },
196
+ { id: "high-gate", t: 562, en: "High gate: the approach phase, pitchover at about 7,500 ft", ja: "ハイゲート:進入フェーズ、高度約7,500フィートでピッチオーバー", reported: true },
197
+ { id: "redesignation", t: 573, en: "First landing-point redesignation (eight in all)", ja: "最初の着陸点の変更(全部で8回)", reported: true },
198
+ { id: "low-gate", t: 658, en: "Low gate: the landing phase", ja: "ローゲート:着陸フェーズ", reported: true },
199
+ { id: "manual", t: when(300 * FT), en: "The Commander takes over by hand, just under 300 ft", ja: "司令官が手動操縦に切り替え(高度約300フィート未満)", reported: false },
200
+ { id: "dust", t: when(70 * FT), en: "Dust first seen, at 60 to 70 ft", ja: "砂ぼこりが見え始める(高度60〜70フィート)", reported: false },
201
+ { id: "touchdown", t: LANDING.duration, en: "Touchdown, 12:05 after ignition, at about 3 ft/s down", ja: "着陸(点火から12分5秒、降下速度は毎秒約3フィート)", reported: true },
202
+ ];
203
+ /**
204
+ * The events that have passed by a moment, the latest last.
205
+ *
206
+ * @param t - Seconds from ignition.
207
+ * @returns The events with a time at or before `t`.
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * import { calloutsBy } from "@johnmorrisdotca/wakusei-planets/surface";
212
+ *
213
+ * console.log(calloutsBy(600).map((c) => c.id).join(", "));
214
+ * ```
215
+ */
216
+ export function calloutsBy(t) {
217
+ return CALLOUTS.filter((c) => c.t <= t + 1e-9);
218
+ }
219
+ /**
220
+ * The clock as the page shows it: `T+04:00` from ignition, and the ground elapsed time of the mission (ignition was 110:09:53).
221
+ *
222
+ * @param t - Seconds from ignition.
223
+ * @returns The two clocks as text.
224
+ *
225
+ * @example
226
+ * ```ts
227
+ * import { clockText } from "@johnmorrisdotca/wakusei-planets/surface";
228
+ *
229
+ * console.log(clockText(240));
230
+ * ```
231
+ */
232
+ export function clockText(t) {
233
+ const two = (n) => String(Math.floor(n)).padStart(2, "0");
234
+ const s = Math.max(0, Math.floor(t));
235
+ const g = 110 * 3600 + 9 * 60 + 53 + s;
236
+ return { t: `T+${two(s / 60)}:${two(s % 60)}`, get: `${Math.floor(g / 3600)}:${two((g % 3600) / 60)}:${two(g % 60)}` };
237
+ }
@@ -1,5 +1,6 @@
1
1
  import type { Item3D, Scene3D } from "@johnmorrisdotca/kazoku-ui/renderer";
2
2
  import type { ThreeParts } from "../scene/body.ts";
3
+ import { type DriveState } from "./drive.ts";
3
4
  import { type SiteObject } from "./objects.ts";
4
5
  import type { HeightLevel, TerrainManifest } from "./height.ts";
5
6
  import type { MoonSky } from "./sky.ts";
@@ -26,6 +27,21 @@ export interface SurfaceState {
26
27
  quality?: "full" | "medium" | "fast";
27
28
  /** The share of the canvas's width and height the ground is drawn at, 1 (the default) to 0.25: below 1 it is drawn to a smaller target and stretched, which is what a draw while the view moves does on a machine that is slow. It needs `WebGLRenderTarget` in the three.js module (a page's own cut-down module may not have it; the draw is then at full size). */
28
29
  scale?: number;
30
+ /** The rover being driven, as `driveStep` leaves it: drawn in place of the one standing at its published place. */
31
+ vehicle?: DriveState;
32
+ /** The path the driven rover has left, east, north, east, north, ... in metres: drawn as tracks. */
33
+ trail?: readonly number[];
34
+ /** The lunar module coming down (Apollo 17's descent): where it is, how high over the ground under it, which way it flies and the share of full thrust; drawn whole, with its plume, in place of the one standing at its place. */
35
+ lander?: {
36
+ east: number;
37
+ north: number;
38
+ altitude: number;
39
+ heading: number;
40
+ throttle: number;
41
+ inside?: boolean;
42
+ };
43
+ /** The grains of dust in flight, east, up, north for each (`DustField.position`), drawn as small squares. */
44
+ dust?: Float32Array;
29
45
  /** Whether the things at the site (the lander, the rover, the flag, the station) and the rover's tracks are drawn (default true; the made ground keeps away from them while they are). */
30
46
  objects?: boolean;
31
47
  /** Time the next draw to the end of the graphics queue (it waits for the card, so it is for a few draws, not every one). */