@johnmorrisdotca/wakusei-planets 0.60.0 → 0.61.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 +14 -0
- package/NOTICE.md +9 -0
- package/README.md +18 -3
- package/dist/bodies/earth.js +22 -1
- package/dist/data/places-moon.d.ts +12 -9
- package/dist/data/places-moon.js +3 -3
- package/dist/element.d.ts +1 -1
- package/dist/flat/system-define.d.ts +3 -0
- package/dist/flat/system-define.js +6 -0
- package/dist/flat/system-element.d.ts +133 -0
- package/dist/flat/system-element.js +1435 -0
- package/dist/flat/system-words.d.ts +28 -0
- package/dist/flat/system-words.js +102 -0
- package/dist/flat/system.d.ts +440 -0
- package/dist/flat/system.js +521 -0
- package/dist/space/travel.js +36 -5
- package/dist/surface/drive.d.ts +5 -2
- package/dist/surface/drive.js +13 -15
- package/dist/surface/element.d.ts +38 -1
- package/dist/surface/element.js +144 -14
- package/dist/surface/index.d.ts +1 -0
- package/dist/surface/index.js +1 -0
- package/dist/surface/model.d.ts +54 -0
- package/dist/surface/model.js +147 -0
- package/dist/surface/rig.d.ts +125 -0
- package/dist/surface/rig.js +107 -0
- package/dist/surface/scene.d.ts +3 -0
- package/dist/surface/scene.js +22 -1
- package/package.json +26 -2
|
@@ -0,0 +1,521 @@
|
|
|
1
|
+
// The flat solar system, as numbers: a top-down map of the Sun, the planets, the dwarf planets and small bodies, the belts, the comets and our spacecraft (the Tesla Roadster among them), in the ecliptic plane, with distances
|
|
2
|
+
// squeezed by the plan's logarithm or true. The same family as the flat maps (`./index.ts`): the same view and zoom names, the same words. Pure: no DOM, no clock reads (the moment is always given).
|
|
3
|
+
import { smallBodyAt } from "../door/small-bodies.js";
|
|
4
|
+
import { toJulianDate } from "../clock.js";
|
|
5
|
+
import { cometOrbit, cometPosition, listComets } from "../comets.js";
|
|
6
|
+
import { heliocentric } from "../ephemeris.js";
|
|
7
|
+
import { BODIES, DWARF_IDS, MINOR_IDS, PLANET_IDS } from "../facts.js";
|
|
8
|
+
import { planRadius, planSunExtent } from "../plan/layout.js";
|
|
9
|
+
import { planetOrbit } from "../space/frame.js";
|
|
10
|
+
import { SPACECRAFT, SPACECRAFT_IDS, spacecraftPosition } from "../spacecraft.js";
|
|
11
|
+
import { toEcliptic } from "../vec.js";
|
|
12
|
+
import { MAX_ZOOM } from "./geometry.js";
|
|
13
|
+
const AU_KM = 149_597_870.7;
|
|
14
|
+
const DAY = 86_400_000;
|
|
15
|
+
/**
|
|
16
|
+
* The kinds of thing the flat solar system draws, which a page can switch on and off: `planets` (the eight and Pluto), `dwarfs` (the dwarf planets and the named asteroids and centaurs), `belts` (the asteroid belts and the Kuiper belt, as clouds of points), `comets` and `craft`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { SYSTEM_LAYERS } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
21
|
+
*
|
|
22
|
+
* console.log(SYSTEM_LAYERS.join(", "));
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export const SYSTEM_LAYERS = ["planets", "dwarfs", "belts", "comets", "craft"];
|
|
26
|
+
/**
|
|
27
|
+
* The furthest the map zooms in: the same 8 times as the flat maps of the Moon and Mars.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { SYSTEM_MAX_ZOOM } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
32
|
+
*
|
|
33
|
+
* console.log(SYSTEM_MAX_ZOOM);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export const SYSTEM_MAX_ZOOM = MAX_ZOOM;
|
|
37
|
+
/**
|
|
38
|
+
* The distance, in astronomical units, the squeezed scale treats as near the Sun: the plan's own (`<wakusei-plan>`), so the two maps put a planet in the same place on their radii.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { SYSTEM_INNER } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
43
|
+
*
|
|
44
|
+
* console.log(SYSTEM_INNER);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export const SYSTEM_INNER = 0.1;
|
|
48
|
+
/**
|
|
49
|
+
* The reach of the map, the distance at its edge in astronomical units: the smallest of 50, 100, 200, 500, 1,000 and 2,000 that holds `farthest`, or `fixed` where one is asked for.
|
|
50
|
+
*
|
|
51
|
+
* @param farthest - The distance in the plane of the farthest thing that must be inside, in au.
|
|
52
|
+
* @param fixed - A reach the page asked for, in au; used when it is above zero and finite.
|
|
53
|
+
* @returns The distance at the edge, in au.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { systemExtent } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
58
|
+
*
|
|
59
|
+
* console.log(systemExtent(49.3), systemExtent(141), systemExtent(141, 30));
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export const systemExtent = (farthest, fixed) => (fixed !== undefined && Number.isFinite(fixed) && fixed > 0 ? fixed : planSunExtent(farthest));
|
|
63
|
+
/**
|
|
64
|
+
* Where a place in the ecliptic plane falls on the map's disc: its direction kept, its distance squeezed (`ln(1 + d / 0.1) / ln(1 + edge / 0.1)`, the plan's `planRadius`) or true (`d / edge`). The edge is 1.
|
|
65
|
+
*
|
|
66
|
+
* @param x - Astronomical units toward the March equinox.
|
|
67
|
+
* @param y - Astronomical units a quarter turn on.
|
|
68
|
+
* @param extent - The distance at the edge, in au.
|
|
69
|
+
* @param spacing - `squeezed` or `true`.
|
|
70
|
+
* @returns `x` and `y` in the unit disc, and `r`, the distance from the middle (above 1 beyond the edge).
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { squeezeAu } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
75
|
+
*
|
|
76
|
+
* const earth = squeezeAu(1, 0, 50, "squeezed");
|
|
77
|
+
* console.log(earth.r.toFixed(2), squeezeAu(1, 0, 50, "true").r.toFixed(2));
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export function squeezeAu(x, y, extent, spacing) {
|
|
81
|
+
const d = Math.hypot(x, y);
|
|
82
|
+
if (d === 0)
|
|
83
|
+
return { x: 0, y: 0, r: 0 };
|
|
84
|
+
const r = planRadius(d, extent, spacing, SYSTEM_INNER);
|
|
85
|
+
return { x: (x / d) * r, y: (y / d) * r, r };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The distance in astronomical units that a radius of the disc stands for: the opposite of the squeeze, so a point pressed on the map can be read as a distance.
|
|
89
|
+
*
|
|
90
|
+
* @param r - The distance from the middle in the unit disc.
|
|
91
|
+
* @param extent - The distance at the edge, in au.
|
|
92
|
+
* @param spacing - `squeezed` or `true`.
|
|
93
|
+
* @returns Astronomical units.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { radiusAu, squeezeAu } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
98
|
+
*
|
|
99
|
+
* console.log(radiusAu(squeezeAu(5.2, 0, 50, "squeezed").r, 50, "squeezed").toFixed(2));
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export const radiusAu = (r, extent, spacing) => (spacing === "true" ? r * extent : SYSTEM_INNER * Math.expm1(r * Math.log1p(extent / SYSTEM_INNER)));
|
|
103
|
+
/**
|
|
104
|
+
* Pixels for one unit of the disc: the whole disc fills the box's shorter side at zoom 1.
|
|
105
|
+
*
|
|
106
|
+
* @param view - The view.
|
|
107
|
+
* @returns Pixels to the disc's edge from its middle.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* import { systemScale } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
112
|
+
*
|
|
113
|
+
* console.log(systemScale({ width: 800, height: 400, centerX: 0, centerY: 0, zoom: 1 }), systemScale({ width: 800, height: 400, centerX: 0, centerY: 0, zoom: 2 }));
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
export const systemScale = (view) => (Math.min(view.width, view.height) / 2) * view.zoom * 0.96;
|
|
117
|
+
/**
|
|
118
|
+
* Where a place of the disc falls in the box, in pixels from its top left (y goes up on the map and down on the screen).
|
|
119
|
+
*
|
|
120
|
+
* @param view - The view.
|
|
121
|
+
* @param x - Across the unit disc.
|
|
122
|
+
* @param y - Up the unit disc.
|
|
123
|
+
* @returns `x` and `y` in pixels.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* import { projectSystem } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
128
|
+
*
|
|
129
|
+
* console.log(projectSystem({ width: 800, height: 400, centerX: 0, centerY: 0, zoom: 1 }, 0, 0));
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export function projectSystem(view, x, y) {
|
|
133
|
+
const k = systemScale(view);
|
|
134
|
+
return { x: view.width / 2 + (x - view.centerX) * k, y: view.height / 2 - (y - view.centerY) * k };
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The place of the disc at a point of the box: the opposite of `projectSystem`.
|
|
138
|
+
*
|
|
139
|
+
* @param view - The view.
|
|
140
|
+
* @param px - Pixels from the left.
|
|
141
|
+
* @param py - Pixels from the top.
|
|
142
|
+
* @returns `x` and `y` in the unit disc.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* import { unprojectSystem } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
147
|
+
*
|
|
148
|
+
* console.log(unprojectSystem({ width: 800, height: 400, centerX: 0, centerY: 0, zoom: 1 }, 400, 200));
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export function unprojectSystem(view, px, py) {
|
|
152
|
+
const k = systemScale(view);
|
|
153
|
+
return { x: view.centerX + (px - view.width / 2) / k, y: view.centerY - (py - view.height / 2) / k };
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The view kept inside what the map can show: the zoom between 1 and 8, and the middle never further from the Sun than the disc's edge.
|
|
157
|
+
*
|
|
158
|
+
* @param view - The view asked for.
|
|
159
|
+
* @returns The view to use.
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* import { clampSystemView } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
164
|
+
*
|
|
165
|
+
* console.log(clampSystemView({ width: 800, height: 400, centerX: 3, centerY: 4, zoom: 20 }));
|
|
166
|
+
* ```
|
|
167
|
+
*/
|
|
168
|
+
export function clampSystemView(view) {
|
|
169
|
+
const zoom = Math.min(SYSTEM_MAX_ZOOM, Math.max(1, Number.isFinite(view.zoom) ? view.zoom : 1));
|
|
170
|
+
let x = Number.isFinite(view.centerX) ? view.centerX : 0;
|
|
171
|
+
let y = Number.isFinite(view.centerY) ? view.centerY : 0;
|
|
172
|
+
const d = Math.hypot(x, y);
|
|
173
|
+
if (d > 1) {
|
|
174
|
+
x /= d;
|
|
175
|
+
y /= d;
|
|
176
|
+
}
|
|
177
|
+
return { ...view, zoom, centerX: x, centerY: y };
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Zoom by a factor about a point of the box, so the place under that point stays under it (as far as the clamp allows).
|
|
181
|
+
*
|
|
182
|
+
* @param view - The view.
|
|
183
|
+
* @param factor - Above 1 zooms in.
|
|
184
|
+
* @param px - Pixels from the left; the middle when left out.
|
|
185
|
+
* @param py - Pixels from the top; the middle when left out.
|
|
186
|
+
* @returns The new view, clamped.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* import { zoomSystemAbout } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
191
|
+
*
|
|
192
|
+
* console.log(zoomSystemAbout({ width: 800, height: 400, centerX: 0, centerY: 0, zoom: 1 }, 2, 600, 100).zoom);
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
export function zoomSystemAbout(view, factor, px = view.width / 2, py = view.height / 2) {
|
|
196
|
+
const at = unprojectSystem(view, px, py);
|
|
197
|
+
const zoom = Math.min(SYSTEM_MAX_ZOOM, Math.max(1, view.zoom * factor));
|
|
198
|
+
const next = { ...view, zoom };
|
|
199
|
+
const k = systemScale(next);
|
|
200
|
+
return clampSystemView({ ...next, centerX: at.x - (px - view.width / 2) / k, centerY: at.y + (py - view.height / 2) / k });
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Distances worth a ring on the map, in astronomical units: the Earth's (1), Jupiter's (5), Saturn's (10), Neptune's (30) and 100.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* import { SYSTEM_RINGS } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
208
|
+
*
|
|
209
|
+
* console.log(SYSTEM_RINGS.join(" "));
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
export const SYSTEM_RINGS = [1, 5, 10, 30, 100, 500];
|
|
213
|
+
/** The colour each planet is drawn in: artistic, chosen to tell them apart on a dark map. */
|
|
214
|
+
const PLANET_COLOURS = { mercury: "#b8b2a8", venus: "#efd9a7", earth: "#4fa3ff", mars: "#ee6a4b", jupiter: "#e0a96d", saturn: "#ead591", uranus: "#8fe8ec", neptune: "#6b86ff", pluto: "#cdb8a6" };
|
|
215
|
+
/** The craft's colours, in the package's order of craft. */
|
|
216
|
+
const CRAFT_COLOURS = ["#ffd23f", "#4cc9f0", "#6ee7a0", "#a78bfa", "#ff9ecb", "#f4a261", "#b8e986", "#5eead4", "#7aa2ff", "#e879f9", "#fde68a"];
|
|
217
|
+
/**
|
|
218
|
+
* The colour of a mark: a planet's own, a pale grey for the dwarf planets and small bodies, ice blue for a comet and one of a set for each craft; the Tesla Roadster is red.
|
|
219
|
+
*
|
|
220
|
+
* @param id - A planet, dwarf planet, small body, comet or craft id, or `sun`.
|
|
221
|
+
* @param layer - Its layer.
|
|
222
|
+
* @returns A CSS colour.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```ts
|
|
226
|
+
* import { systemColour } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
227
|
+
*
|
|
228
|
+
* console.log(systemColour("earth", "planets"), systemColour("roadster", "craft"));
|
|
229
|
+
* ```
|
|
230
|
+
*/
|
|
231
|
+
export function systemColour(id, layer) {
|
|
232
|
+
if (layer === "sun")
|
|
233
|
+
return "#ffd54f";
|
|
234
|
+
if (layer === "planets")
|
|
235
|
+
return PLANET_COLOURS[id] ?? "#ffffff";
|
|
236
|
+
if (layer === "dwarfs")
|
|
237
|
+
return "#cfd6e0";
|
|
238
|
+
if (layer === "comets")
|
|
239
|
+
return "#9ee6ff";
|
|
240
|
+
if (layer === "belts")
|
|
241
|
+
return "#d9d3c3";
|
|
242
|
+
if (id === "roadster")
|
|
243
|
+
return "#ff3b30";
|
|
244
|
+
const at = SPACECRAFT_IDS.indexOf(id);
|
|
245
|
+
return CRAFT_COLOURS[(at < 0 ? 0 : at) % CRAFT_COLOURS.length];
|
|
246
|
+
}
|
|
247
|
+
/** The names of the minor bodies the map draws as dwarfs-layer marks: Halley is a comet here. */
|
|
248
|
+
const SMALL_BODIES = MINOR_IDS.filter((id) => id !== "halley");
|
|
249
|
+
/** The ids of the planets and of the dwarf layer, in order. */
|
|
250
|
+
const PLANETS = PLANET_IDS;
|
|
251
|
+
const DWARFS = [...DWARF_IDS, ...SMALL_BODIES];
|
|
252
|
+
/**
|
|
253
|
+
* The ids the dwarfs layer draws: the dwarf planets, then Vesta, Pallas, Chiron and Pholus (Halley is among the comets).
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```ts
|
|
257
|
+
* import { SYSTEM_DWARFS } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
258
|
+
*
|
|
259
|
+
* console.log(SYSTEM_DWARFS.join(", "));
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
export const SYSTEM_DWARFS = DWARFS;
|
|
263
|
+
/**
|
|
264
|
+
* The craft's place at a moment in astronomical units, or `undefined` while its path is not loaded (`loadSpacecraft`) or the moment is outside the record of its path (a craft that has not launched, or whose record has ended).
|
|
265
|
+
*
|
|
266
|
+
* @param id - The craft.
|
|
267
|
+
* @param ms - Milliseconds since 1970 (UTC).
|
|
268
|
+
* @returns The place, or `undefined`.
|
|
269
|
+
*
|
|
270
|
+
* @example
|
|
271
|
+
* ```ts
|
|
272
|
+
* import { loadSpacecraft } from "@johnmorrisdotca/wakusei-planets/spacecraft";
|
|
273
|
+
* import { craftAu } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
274
|
+
*
|
|
275
|
+
* await loadSpacecraft("roadster");
|
|
276
|
+
* const car = craftAu("roadster", Date.UTC(2026, 10, 17));
|
|
277
|
+
* console.log(car === undefined ? "not loaded" : Math.hypot(car[0], car[1]).toFixed(1), "au from the Sun");
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
export function craftAu(id, ms) {
|
|
281
|
+
if (!SPACECRAFT_IDS.includes(id))
|
|
282
|
+
return undefined;
|
|
283
|
+
const craft = SPACECRAFT[id];
|
|
284
|
+
// the Roadster's record is filled in when its path is loaded: 0 until then
|
|
285
|
+
if (craft.record.end === 0 || ms < craft.record.start || ms > craft.record.end)
|
|
286
|
+
return undefined;
|
|
287
|
+
try {
|
|
288
|
+
const p = spacecraftPosition(id, ms);
|
|
289
|
+
return [p[0] / AU_KM, p[1] / AU_KM, p[2] / AU_KM];
|
|
290
|
+
}
|
|
291
|
+
catch {
|
|
292
|
+
return undefined;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/** A comet's place, or undefined where two-body motion has none. */
|
|
296
|
+
function cometAu(record, ms) {
|
|
297
|
+
try {
|
|
298
|
+
return cometPosition(record, ms);
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
return undefined;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/** The places of the planets and of the dwarf layer, in au. */
|
|
305
|
+
function bodyAu(id, ms) {
|
|
306
|
+
return heliocentric(id, ms);
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* The name of a thing on the map in a language: the Sun, a planet, a dwarf planet or small body, a comet or a craft. The Tesla Roadster is called by its car's name (the mannequin is Starman, in the facts).
|
|
310
|
+
*
|
|
311
|
+
* @param id - The thing's id.
|
|
312
|
+
* @param lang - `en` or `ja`.
|
|
313
|
+
* @returns The name, or the id where there is none.
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```ts
|
|
317
|
+
* import { systemName } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
318
|
+
*
|
|
319
|
+
* console.log(systemName("roadster", "en"), "|", systemName("roadster", "ja"), "|", systemName("halley", "ja"));
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
export function systemName(id, lang) {
|
|
323
|
+
if (id === "roadster")
|
|
324
|
+
return lang === "ja" ? "テスラ・ロードスター" : "Tesla Roadster";
|
|
325
|
+
if (SPACECRAFT_IDS.includes(id))
|
|
326
|
+
return SPACECRAFT[id].name[lang];
|
|
327
|
+
const comet = listComets().find((one) => one.id === id);
|
|
328
|
+
if (comet)
|
|
329
|
+
return comet.name[lang];
|
|
330
|
+
const body = BODIES[id];
|
|
331
|
+
return body ? body.name[lang] : id;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* What every drawn thing is at a moment, with its place on the disc. The planets come from VSOP87B and the fitted tables, the dwarf planets and small bodies from their fitted tables or one epoch's elements, the comets by two-body motion on JPL's elements,
|
|
335
|
+
* and the craft from the Horizons paths, which must be loaded first (`loadSpacecraft`); a craft with no path at that moment is left out. A thing further out than the reach is marked `beyond` and not worth drawing.
|
|
336
|
+
*
|
|
337
|
+
* @param ms - Milliseconds since 1970 (UTC).
|
|
338
|
+
* @param options - The layers, the craft and comets wanted, the reach and the spacing.
|
|
339
|
+
* @returns The Sun first, then the planets, dwarfs, comets and craft.
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```ts
|
|
343
|
+
* import { systemMarks } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
344
|
+
*
|
|
345
|
+
* const marks = systemMarks(Date.UTC(2026, 10, 17), { layers: ["planets", "comets"] });
|
|
346
|
+
* const earth = marks.find((m) => m.id === "earth")!;
|
|
347
|
+
* console.log(marks.length, Math.round((Math.atan2(earth.au[1], earth.au[0]) * 180) / Math.PI), "degrees of ecliptic longitude");
|
|
348
|
+
* ```
|
|
349
|
+
*/
|
|
350
|
+
export function systemMarks(ms, options = {}) {
|
|
351
|
+
const layers = new Set(options.layers ?? SYSTEM_LAYERS.filter((one) => one !== "belts"));
|
|
352
|
+
const spacing = options.spacing === "true" ? "true" : "squeezed";
|
|
353
|
+
const raw = [];
|
|
354
|
+
if (layers.has("planets"))
|
|
355
|
+
for (const id of PLANETS)
|
|
356
|
+
raw.push({ id, layer: "planets", kind: "planet", au: bodyAu(id, ms) });
|
|
357
|
+
if (layers.has("dwarfs"))
|
|
358
|
+
for (const id of DWARFS)
|
|
359
|
+
raw.push({ id, layer: "dwarfs", kind: id === "chiron" || id === "pholus" ? "centaur" : id === "vesta" || id === "pallas" ? "asteroid" : "dwarf-planet", au: bodyAu(id, ms) });
|
|
360
|
+
if (layers.has("comets")) {
|
|
361
|
+
const wanted = options.comets;
|
|
362
|
+
for (const record of listComets()) {
|
|
363
|
+
if (wanted !== undefined && !wanted.includes(record.id))
|
|
364
|
+
continue;
|
|
365
|
+
const au = cometAu(record, ms);
|
|
366
|
+
if (au !== undefined)
|
|
367
|
+
raw.push({ id: record.id, layer: "comets", kind: "comet", au });
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
if (layers.has("craft")) {
|
|
371
|
+
const wanted = options.craft;
|
|
372
|
+
for (const id of SPACECRAFT_IDS) {
|
|
373
|
+
if (wanted !== undefined && !wanted.includes(id))
|
|
374
|
+
continue;
|
|
375
|
+
const au = craftAu(id, ms);
|
|
376
|
+
if (au !== undefined)
|
|
377
|
+
raw.push({ id, layer: "craft", kind: "spacecraft", au });
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
// the reach holds the planets, the dwarf planets and the craft drawn; comets and belts further out than it are left off
|
|
381
|
+
const farthest = Math.max(0, ...raw.filter((one) => one.layer !== "comets").map((one) => Math.hypot(one.au[0], one.au[1])));
|
|
382
|
+
const extent = systemExtent(farthest, options.extent);
|
|
383
|
+
const place = (one) => {
|
|
384
|
+
const at = squeezeAu(one.au[0], one.au[1], extent, spacing);
|
|
385
|
+
return { ...one, planeAu: Math.hypot(one.au[0], one.au[1]), distanceAu: Math.hypot(one.au[0], one.au[1], one.au[2]), x: at.x, y: at.y, beyond: at.r > 1 };
|
|
386
|
+
};
|
|
387
|
+
const sun = { id: "sun", layer: "sun", kind: "star", au: [0, 0, 0], planeAu: 0, distanceAu: 0, x: 0, y: 0, beyond: false };
|
|
388
|
+
return [sun, ...raw.map(place)];
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* The reach the map stands at for what is drawn: what `systemMarks` used. Worked out the same way, from the planets, the dwarf planets and the craft shown, so the map's scale can be had without placing the marks again.
|
|
392
|
+
*
|
|
393
|
+
* @param marks - The marks from `systemMarks`.
|
|
394
|
+
* @param fixed - A reach the page asked for, in au.
|
|
395
|
+
* @returns The distance at the edge, in au.
|
|
396
|
+
*
|
|
397
|
+
* @example
|
|
398
|
+
* ```ts
|
|
399
|
+
* import { systemMarks, systemReach } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
400
|
+
*
|
|
401
|
+
* console.log(systemReach(systemMarks(Date.UTC(2026, 10, 17), { layers: ["planets"] })));
|
|
402
|
+
* ```
|
|
403
|
+
*/
|
|
404
|
+
export const systemReach = (marks, fixed) => systemExtent(Math.max(0, ...marks.filter((one) => one.layer !== "comets").map((one) => one.planeAu)), fixed);
|
|
405
|
+
/**
|
|
406
|
+
* Where the bodies of the belts are at a moment, in au in the ecliptic plane: two numbers a body, the Kepler orbit of each one's elements (`beltPositions` without the height, which a view from above does not use).
|
|
407
|
+
*
|
|
408
|
+
* @param bodies - The belt bodies, from `loadBeltBodies`.
|
|
409
|
+
* @param ms - Milliseconds since 1970 (UTC).
|
|
410
|
+
* @param out - A list of `2 * bodies.length` numbers to fill in; made when left out.
|
|
411
|
+
* @returns The list.
|
|
412
|
+
*
|
|
413
|
+
* @example
|
|
414
|
+
* ```ts
|
|
415
|
+
* import { systemBelts } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
416
|
+
*
|
|
417
|
+
* const body = { name: "T", a: 2.7, e: 0, i: 0, node: 0, peri: 0, M0: 0, epoch: 2461200.5, H: 9 };
|
|
418
|
+
* console.log(systemBelts([body], Date.UTC(2026, 10, 17))[0]?.toFixed(2));
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
export function systemBelts(bodies, ms, out = new Float32Array(bodies.length * 2)) {
|
|
422
|
+
const jd = toJulianDate(ms);
|
|
423
|
+
for (let k = 0; k < bodies.length; k += 1) {
|
|
424
|
+
const p = smallBodyAt(bodies[k], jd);
|
|
425
|
+
out[k * 2] = p[0];
|
|
426
|
+
out[k * 2 + 1] = p[1];
|
|
427
|
+
}
|
|
428
|
+
return out;
|
|
429
|
+
}
|
|
430
|
+
const orbitCache = new Map();
|
|
431
|
+
const YEAR = 365.25 * DAY;
|
|
432
|
+
/**
|
|
433
|
+
* The orbit line of a planet, dwarf planet or small body, as points in the ecliptic plane in au: one trip round the Sun from the start of the year the moment is in (a planet's path changes by less than a pixel in a year), kept for that year.
|
|
434
|
+
*
|
|
435
|
+
* @param id - A planet, dwarf planet or small body of the map.
|
|
436
|
+
* @param ms - Milliseconds since 1970 (UTC).
|
|
437
|
+
* @param points - How many steps round it.
|
|
438
|
+
* @returns The points; the last is the first again.
|
|
439
|
+
*
|
|
440
|
+
* @example
|
|
441
|
+
* ```ts
|
|
442
|
+
* import { systemOrbit } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
443
|
+
*
|
|
444
|
+
* const line = systemOrbit("earth", Date.UTC(2026, 10, 17));
|
|
445
|
+
* console.log(line.length, Math.hypot(...line[0]!).toFixed(2));
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
export function systemOrbit(id, ms, points = 96) {
|
|
449
|
+
const bucket = Math.floor(ms / YEAR);
|
|
450
|
+
const key = `${id}|${bucket}|${points}`;
|
|
451
|
+
let found = orbitCache.get(key);
|
|
452
|
+
if (found === undefined) {
|
|
453
|
+
if (orbitCache.size > 300)
|
|
454
|
+
orbitCache.clear();
|
|
455
|
+
// `planetOrbit` answers in the scene's axes (J2000 equatorial, y north): back to the equatorial axes, then the ecliptic
|
|
456
|
+
found = planetOrbit(id, bucket * YEAR, points).map((p) => {
|
|
457
|
+
const e = toEcliptic([p[0], -p[2], p[1]]);
|
|
458
|
+
return [e[0], e[1]];
|
|
459
|
+
});
|
|
460
|
+
orbitCache.set(key, found);
|
|
461
|
+
}
|
|
462
|
+
return found;
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* A comet's orbit line as points in the ecliptic plane in au, as far out as the reach.
|
|
466
|
+
*
|
|
467
|
+
* @param id - The comet's id.
|
|
468
|
+
* @param reach - The furthest distance to draw, in au.
|
|
469
|
+
* @returns The points.
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* ```ts
|
|
473
|
+
* import { systemCometOrbit } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
474
|
+
*
|
|
475
|
+
* console.log(systemCometOrbit("halley", 50).length > 20);
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
export function systemCometOrbit(id, reach) {
|
|
479
|
+
const record = listComets().find((one) => one.id === id);
|
|
480
|
+
if (record === undefined || !(reach > record.q))
|
|
481
|
+
return [];
|
|
482
|
+
const flat = cometOrbit(record, 120, reach);
|
|
483
|
+
const out = [];
|
|
484
|
+
for (let k = 0; k + 2 < flat.length; k += 3)
|
|
485
|
+
out.push([flat[k], flat[k + 1]]);
|
|
486
|
+
return out;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* A craft's whole path as points in the ecliptic plane, `count` steps over its record, each with its moment: what the map draws as the craft's track, the part behind the moment dashed and the part ahead solid. `[]` while the path is not loaded.
|
|
490
|
+
*
|
|
491
|
+
* @param id - The craft.
|
|
492
|
+
* @param count - How many steps (from 2).
|
|
493
|
+
* @returns Points with their moments in milliseconds since 1970.
|
|
494
|
+
*
|
|
495
|
+
* @example
|
|
496
|
+
* ```ts
|
|
497
|
+
* import { loadSpacecraft } from "@johnmorrisdotca/wakusei-planets/spacecraft";
|
|
498
|
+
* import { craftPath } from "@johnmorrisdotca/wakusei-planets/flat/system";
|
|
499
|
+
*
|
|
500
|
+
* await loadSpacecraft("roadster");
|
|
501
|
+
* const path = craftPath("roadster", 100);
|
|
502
|
+
* console.log(path.length, new Date(path[0]!.ms).getUTCFullYear(), new Date(path[path.length - 1]!.ms).getUTCFullYear());
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
505
|
+
export function craftPath(id, count = 300) {
|
|
506
|
+
if (!SPACECRAFT_IDS.includes(id))
|
|
507
|
+
return [];
|
|
508
|
+
const { start, end } = SPACECRAFT[id].record;
|
|
509
|
+
if (end === 0)
|
|
510
|
+
return [];
|
|
511
|
+
const out = [];
|
|
512
|
+
const n = Math.max(2, Math.floor(count));
|
|
513
|
+
for (let k = 0; k <= n; k += 1) {
|
|
514
|
+
const ms = start + ((end - start) * k) / n;
|
|
515
|
+
const p = craftAu(id, ms);
|
|
516
|
+
if (p !== undefined)
|
|
517
|
+
out.push({ x: p[0], y: p[1], ms });
|
|
518
|
+
}
|
|
519
|
+
return out;
|
|
520
|
+
}
|
|
521
|
+
export { SYSTEM_WORDS, saySystem } from "./system-words.js";
|
package/dist/space/travel.js
CHANGED
|
@@ -232,6 +232,13 @@ function aimDistance(a, p) {
|
|
|
232
232
|
const top = Math.max(a.r0, a.r1) * a.far;
|
|
233
233
|
return Math.exp(Math.log(a.r0) + (Math.log(top) - Math.log(a.r0)) * smooth(p / 0.5) + (Math.log(a.r1) - Math.log(top)) * smooth((p - 0.5) / 0.5));
|
|
234
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* The distance from the aim point that keeps the nearer moon inside the tangent `fit` of the look direction, as the aim goes `w` of the way along the `apart` between the two moons: nothing at either end, and
|
|
237
|
+
* the most in the middle. A turn fitted to it backs off no further than the two moons need, where the plain backing off (a smooth step in the log of the distance) must go many times as far to be far enough early.
|
|
238
|
+
*/
|
|
239
|
+
const aimNeed = (apart, w, fit) => ((apart * Math.sin(Math.PI * w)) / 2) * (1 + 1 / fit);
|
|
240
|
+
/** How far inside the nearer edge of the picture a fitted turn keeps the nearer moon. */
|
|
241
|
+
const AIM_FIT = 0.9;
|
|
235
242
|
/** The backing off to try, in turn, and how far from the middle of the picture the nearer moon may get (1 is the edge), and how many moments of the turn are looked at. */
|
|
236
243
|
const AIM_FAR = Array.from({ length: 19 }, (_, k) => 1.5 ** k);
|
|
237
244
|
const AIM_BEND = [0, 0.5, 1, 2, 4];
|
|
@@ -255,7 +262,8 @@ function turnAt(turn, p, t, share) {
|
|
|
255
262
|
const u = mix(a.facings[i].u, a.facings[i + 1].u, x - i);
|
|
256
263
|
const w = aimPan(q);
|
|
257
264
|
const aim = mix(placeOf(a.from, t), placeOf(a.to, t), w);
|
|
258
|
-
|
|
265
|
+
const d = a.fit === undefined ? aimDistance(a, q) : Math.hypot(aimDistance({ r0: a.r0, r1: a.r1, far: 1 }, q), aimNeed(length(sub(placeOf(a.to, t), placeOf(a.from, t))), w, a.fit));
|
|
266
|
+
return { position: add(aim, scale(aimSide(a, w), d)), o: { f, u: unit(sub(u, scale(f, dot(u, f)))) }, fov: fovBetween(turn.fov0, turn.fov1, p) };
|
|
259
267
|
}
|
|
260
268
|
const o = swingAt(turn.swing, p);
|
|
261
269
|
// the lift is early: the camera backs off as it starts to turn, so the body left goes into the picture, not out of its side
|
|
@@ -965,7 +973,7 @@ function emptyMoments(route) {
|
|
|
965
973
|
}
|
|
966
974
|
return empty;
|
|
967
975
|
}
|
|
968
|
-
function withAim(input, first, stop) {
|
|
976
|
+
function withAim(input, first, stop, fitted = false) {
|
|
969
977
|
const route = first.route;
|
|
970
978
|
if (route.turn === null || first.plan.path !== "circle" || route.cut || route.share <= 0)
|
|
971
979
|
return first;
|
|
@@ -975,6 +983,9 @@ function withAim(input, first, stop) {
|
|
|
975
983
|
const share = route.share;
|
|
976
984
|
const swing = route.turn;
|
|
977
985
|
const flawsOf = (candidate) => aimFlaws(input, candidate, route.shells, route.leg, share);
|
|
986
|
+
const frame = frameOf(input.start.fov, input.aspect);
|
|
987
|
+
const fit = AIM_FIT * Math.min(frame.th, frame.tv);
|
|
988
|
+
const apart = length(sub(placeOf(input.destination, share / 2), placeOf(input.leaving, share / 2)));
|
|
978
989
|
// each way of leaning out and each pace, with the least backing off that keeps the nearer moon inside 0.95 of the way to the edge and every pace of the walk inside its limit; of those the one
|
|
979
990
|
// that costs least (the log of the backing off, the lean and the slowing) is taken, and none if none will do
|
|
980
991
|
let cost = Number.POSITIVE_INFINITY;
|
|
@@ -990,13 +1001,14 @@ function withAim(input, first, stop) {
|
|
|
990
1001
|
if (!bases.has(bend))
|
|
991
1002
|
bases.set(bend, aimOf(input, swing, share, bend, 1));
|
|
992
1003
|
const base = { ...bases.get(bend), slow };
|
|
993
|
-
|
|
1004
|
+
// a fitted turn has one backing off, the one the two moons need
|
|
1005
|
+
for (const far of fitted ? [Math.hypot(1, aimNeed(apart, 0.5, fit) / Math.max(base.r0, base.r1))] : AIM_FAR) {
|
|
994
1006
|
const spent = Math.log(far) + lean;
|
|
995
1007
|
if (best !== null && spent >= cost)
|
|
996
1008
|
break;
|
|
997
1009
|
if (stop?.() === true)
|
|
998
1010
|
break;
|
|
999
|
-
const candidate = { ...swing, aim: { ...base, far } };
|
|
1011
|
+
const candidate = { ...swing, aim: fitted ? { ...base, far, fit } : { ...base, far } };
|
|
1000
1012
|
const flaws = flawsOf(candidate);
|
|
1001
1013
|
if (flaws.edge <= AIM_EDGE && flaws.fair) {
|
|
1002
1014
|
best = candidate;
|
|
@@ -1122,7 +1134,8 @@ function routeMade(input) {
|
|
|
1122
1134
|
// before the other ways were tried and what they are measured against
|
|
1123
1135
|
const started = input.budget?.now();
|
|
1124
1136
|
const stop = input.budget === undefined || started === undefined ? undefined : () => input.budget.now() - started >= input.budget.ms;
|
|
1125
|
-
|
|
1137
|
+
const base = routeBase(input);
|
|
1138
|
+
let first = withAim(input, base);
|
|
1126
1139
|
if (first.plan.path === "pivot" && first.route.turn !== null && first.route.share > 0) {
|
|
1127
1140
|
// a move that turns beside the body left is framed (B1) where there is a picture that holds both bodies, its look direction and stand being those of the picture; it is taken if it has no fault more than the other
|
|
1128
1141
|
const framed = routeBase(input, 0, true);
|
|
@@ -1146,6 +1159,7 @@ function routeMade(input) {
|
|
|
1146
1159
|
// budget, keeping the best so far
|
|
1147
1160
|
let best = first;
|
|
1148
1161
|
let least = was;
|
|
1162
|
+
const made = [base];
|
|
1149
1163
|
for (const variant of WAYS) {
|
|
1150
1164
|
if (stop?.() === true)
|
|
1151
1165
|
break;
|
|
@@ -1169,6 +1183,23 @@ function routeMade(input) {
|
|
|
1169
1183
|
}
|
|
1170
1184
|
if (total(least) === 0)
|
|
1171
1185
|
break;
|
|
1186
|
+
made.push(raw);
|
|
1187
|
+
}
|
|
1188
|
+
// a picture is still empty in the best of them: each way's turn is made once more by an aim point whose backing off is fitted to the two moons, which is quick (one backing off for each lean and pace), so it
|
|
1189
|
+
// is done whatever the budget; a move that had no empty picture left is not looked at, so it is the move it was
|
|
1190
|
+
if (least.empty === 0)
|
|
1191
|
+
return best;
|
|
1192
|
+
for (const raw of made) {
|
|
1193
|
+
const other = withAim(input, raw, undefined, true);
|
|
1194
|
+
if (other.route.turn?.aim === undefined)
|
|
1195
|
+
continue;
|
|
1196
|
+
const faults = faultsOf(other.route);
|
|
1197
|
+
if (betterThan(faults, was) && total(faults) < total(least)) {
|
|
1198
|
+
best = other;
|
|
1199
|
+
least = faults;
|
|
1200
|
+
}
|
|
1201
|
+
if (total(least) === 0)
|
|
1202
|
+
break;
|
|
1172
1203
|
}
|
|
1173
1204
|
return best;
|
|
1174
1205
|
}
|
package/dist/surface/drive.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Rig } from "./rig.ts";
|
|
1
2
|
import { type Part, type V3 } from "./shapes.ts";
|
|
2
3
|
/**
|
|
3
4
|
* The rover's measures: those published (its length and width, the wheels' size and the wheelbase, the gravity of the Moon) and those chosen here (the speeds, the steering, the slope it will not climb, the spring).
|
|
@@ -108,6 +109,7 @@ export declare function toWorld(state: Pick<DriveState, "east" | "north" | "head
|
|
|
108
109
|
* @param dt - Seconds (at most 0.05 are used; call it more often for a longer time).
|
|
109
110
|
* @param ground - The ground's height over the site's ground at a place.
|
|
110
111
|
* @param blocked - True at a place the rover cannot go (a big rock, the lunar module).
|
|
112
|
+
* @param rig - The vehicle's measures (its wheels' places and size); the lunar rover's by default, a model's from `rigOf`.
|
|
111
113
|
* @returns The rover a moment later.
|
|
112
114
|
*
|
|
113
115
|
* @example
|
|
@@ -119,7 +121,7 @@ export declare function toWorld(state: Pick<DriveState, "east" | "north" | "head
|
|
|
119
121
|
* console.log(`${rover.north.toFixed(1)} m north after two seconds, at ${rover.speed.toFixed(1)} m/s`);
|
|
120
122
|
* ```
|
|
121
123
|
*/
|
|
122
|
-
export declare function driveStep(state: DriveState, input: DriveInput, dt: number, ground: (east: number, north: number) => number, blocked?: (east: number, north: number) => boolean): DriveState;
|
|
124
|
+
export declare function driveStep(state: DriveState, input: DriveInput, dt: number, ground: (east: number, north: number) => number, blocked?: (east: number, north: number) => boolean, rig?: Rig): DriveState;
|
|
123
125
|
/**
|
|
124
126
|
* The rover's shape as it is now, turned and placed: the parts of `roverParts` with each wheel turned by how far it has rolled and steered (the back wheels the other way), then moved by the rover's heading, pitch, roll
|
|
125
127
|
* and place. Everything is in the site's plane (x east, y up, z north).
|
|
@@ -181,6 +183,7 @@ export type DriveDrag = "head" | "orbit";
|
|
|
181
183
|
* @param offset - The driver's turn of the view, degrees right and up.
|
|
182
184
|
* @param ground - The ground's height over the site's ground at a place.
|
|
183
185
|
* @param drag - What a drag does in the chase view: `head` or `orbit` (the default).
|
|
186
|
+
* @param rig - The vehicle's measures (where its eyes are); the lunar rover's by default, a model's from `rigOf`.
|
|
184
187
|
* @returns The eyes.
|
|
185
188
|
*
|
|
186
189
|
* @example
|
|
@@ -196,4 +199,4 @@ export type DriveDrag = "head" | "orbit";
|
|
|
196
199
|
export declare function driveView(state: DriveState, view: "chase" | "seat", offset: {
|
|
197
200
|
azimuth: number;
|
|
198
201
|
pitch: number;
|
|
199
|
-
}, ground: (east: number, north: number) => number, drag?: DriveDrag): DriveView;
|
|
202
|
+
}, ground: (east: number, north: number) => number, drag?: DriveDrag, rig?: Rig): DriveView;
|