@johnmorrisdotca/wakusei-planets 0.37.2 → 0.39.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/NOTICE.md +14 -3
  3. package/README.md +6 -4
  4. package/dist/belts/data.d.ts +2 -0
  5. package/dist/belts/data.js +12 -0
  6. package/dist/belts/index.d.ts +270 -0
  7. package/dist/belts/index.js +308 -0
  8. package/dist/belts/totals.d.ts +43 -0
  9. package/dist/belts/totals.js +25 -0
  10. package/dist/data/orbiters.d.ts +221 -199
  11. package/dist/data/orbiters.js +288 -200
  12. package/dist/data-door.d.ts +2 -0
  13. package/dist/data-door.js +4 -2
  14. package/dist/door/own.js +4 -2
  15. package/dist/door/points.d.ts +14 -5
  16. package/dist/door/points.js +78 -27
  17. package/dist/earth-places.d.ts +40 -0
  18. package/dist/earth-places.js +47 -0
  19. package/dist/embed.d.ts +4 -1
  20. package/dist/embed.js +21 -10
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.js +1 -0
  23. package/dist/orbiter-facts.d.ts +61 -4
  24. package/dist/orbiter-facts.js +17 -3
  25. package/dist/orbiters.d.ts +122 -2
  26. package/dist/orbiters.js +205 -3
  27. package/dist/picture-credits.d.ts +78 -0
  28. package/dist/picture-credits.js +120 -0
  29. package/dist/place-marks.d.ts +76 -0
  30. package/dist/place-marks.js +66 -0
  31. package/dist/places.d.ts +1 -1
  32. package/dist/places.js +1 -1
  33. package/dist/scene/earth-places.d.ts +190 -0
  34. package/dist/scene/earth-places.js +190 -0
  35. package/dist/scene/painter.d.ts +11 -0
  36. package/dist/scene/painter.js +30 -2
  37. package/dist/scene/textures.d.ts +2 -2
  38. package/dist/space/element.d.ts +74 -3
  39. package/dist/space/element.js +293 -8
  40. package/dist/space/ride.d.ts +4 -4
  41. package/dist/space/ride.js +10 -3
  42. package/dist/space/scene.d.ts +44 -2
  43. package/dist/space/scene.js +139 -11
  44. package/dist/version.d.ts +1 -1
  45. package/dist/version.js +1 -1
  46. package/package.json +15 -2
@@ -0,0 +1,270 @@
1
+ import { BELT_EPOCH, BELT_TOTALS } from "./totals.ts";
2
+ import type { SmallBody, SmallBodySource } from "../door/small-bodies.ts";
3
+ /**
4
+ * The belts, nearest the Sun first.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { BELT_IDS } from "@johnmorrisdotca/wakusei-planets/belts";
9
+ *
10
+ * console.log(BELT_IDS.join(", "));
11
+ * ```
12
+ */
13
+ export declare const BELT_IDS: readonly ["main", "hilda", "trojan", "centaur", "classical", "resonant", "scattered"];
14
+ /**
15
+ * The name of a belt: `main`, `hilda`, `trojan`, `centaur`, `classical`, `resonant` or `scattered`.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { BELT_IDS, type BeltId } from "@johnmorrisdotca/wakusei-planets/belts";
20
+ *
21
+ * const id: BeltId = BELT_IDS[2];
22
+ * console.log(id);
23
+ * ```
24
+ */
25
+ export type BeltId = (typeof BELT_IDS)[number];
26
+ /**
27
+ * What one belt is: its names, the colour its points are drawn in, how many of its bodies the database holds (`known`) and how many of those this package carries (`sample`, the brightest numbered ones).
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { BELTS, type BeltInfo } from "@johnmorrisdotca/wakusei-planets/belts";
32
+ *
33
+ * const main: BeltInfo = BELTS.main;
34
+ * console.log(main.name.en, main.sample, main.known);
35
+ * ```
36
+ */
37
+ export interface BeltInfo {
38
+ id: BeltId;
39
+ name: {
40
+ en: string;
41
+ ja: string;
42
+ };
43
+ /** What the belt is, in a few words. */
44
+ about: {
45
+ en: string;
46
+ ja: string;
47
+ };
48
+ /** The colour of its points, `#rrggbb`. */
49
+ colour: string;
50
+ /** How many bodies of this belt the Small-Body Database held on 2026-11-10. */
51
+ known: number;
52
+ /** How many of them this package carries: the brightest numbered ones. */
53
+ sample: number;
54
+ }
55
+ /**
56
+ * The seven belts, by name.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * import { BELTS } from "@johnmorrisdotca/wakusei-planets/belts";
61
+ *
62
+ * console.log(BELTS.trojan.known > BELTS.centaur.known);
63
+ * ```
64
+ */
65
+ export declare const BELTS: Readonly<Record<BeltId, BeltInfo>>;
66
+ /**
67
+ * The Oort cloud, which no orbit in this package is drawn for: a shell of comets thought to lie round the whole solar system, from about 2,000 to about 100,000 astronomical units from the Sun (the outer edge
68
+ * is far beyond anything measured). The space view draws it as a labelled shell where its distances fit.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * import { OORT } from "@johnmorrisdotca/wakusei-planets/belts";
73
+ *
74
+ * console.log(OORT.innerAu, OORT.outerAu);
75
+ * ```
76
+ */
77
+ export declare const OORT: {
78
+ readonly innerAu: 2000;
79
+ readonly outerAu: 100000;
80
+ readonly name: {
81
+ readonly en: "Oort cloud";
82
+ readonly ja: "オールトの雲";
83
+ };
84
+ readonly about: {
85
+ readonly en: "where long-period comets are thought to come from: nothing in it has been seen";
86
+ readonly ja: "長周期彗星の起源と考えられる領域。そこにある天体はまだ見つかっていません";
87
+ };
88
+ };
89
+ export { BELT_EPOCH };
90
+ export { BELT_TOTALS };
91
+ /**
92
+ * A small body of a belt: the elements of `SmallBody` and the belt it is in.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * import type { BeltBody } from "@johnmorrisdotca/wakusei-planets/belts";
97
+ *
98
+ * const achilles: BeltBody = { name: "588 Achilles", a: 5.216, e: 0.148, i: 10.3, node: 316.5, peri: 134.3, M0: 93.3, epoch: 2461200.5, H: 8.2, belt: "trojan" };
99
+ * console.log(achilles.belt);
100
+ * ```
101
+ */
102
+ export interface BeltBody extends SmallBody {
103
+ belt: BeltId;
104
+ }
105
+ /**
106
+ * Reads the rows of one belt (`name|a|e|i|node|peri|M0|H`, one body to a line) into bodies.
107
+ *
108
+ * @param belt - The belt they are in.
109
+ * @param rows - The text.
110
+ * @param epoch - The Julian date the elements are given at.
111
+ * @returns The bodies.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * import { parseBeltRows } from "@johnmorrisdotca/wakusei-planets/belts";
116
+ *
117
+ * console.log(parseBeltRows("trojan", "588 Achilles|5.216|.148|10.3|316.5|134.3|93.3|8.2", 2461200.5)[0]?.name);
118
+ * ```
119
+ */
120
+ export declare function parseBeltRows(belt: BeltId, rows: string, epoch: number): BeltBody[];
121
+ /**
122
+ * Fetches the bodies of every belt: a chunk of its own (about 70 kB gzipped), read once. A page that never calls this, and never draws the belts, does not carry it.
123
+ *
124
+ * @returns The bodies, belt by belt, the brightest first in each.
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * import { loadBeltBodies } from "@johnmorrisdotca/wakusei-planets/belts";
129
+ *
130
+ * const bodies = await loadBeltBodies();
131
+ * console.log(bodies.length, bodies[0]?.belt);
132
+ * ```
133
+ */
134
+ export declare function loadBeltBodies(): Promise<readonly BeltBody[]>;
135
+ /**
136
+ * The belts as a source of the data door, which `<wakusei-space>` adds itself (turn it off with `belts="off"`, or `space.enableSource("wakusei-belts", false)`): the records are fetched when the view first reads them. It is the
137
+ * package's own source, so it is credited with the rest of the package's data and `data="own"` keeps it.
138
+ *
139
+ * @returns A record source of `BeltBody` records.
140
+ *
141
+ * @example
142
+ * ```ts
143
+ * import { beltsSource } from "@johnmorrisdotca/wakusei-planets/belts";
144
+ *
145
+ * console.log(beltsSource().info.id, beltsSource().info.licence.name);
146
+ * ```
147
+ */
148
+ export declare function beltsSource(): SmallBodySource;
149
+ /**
150
+ * Where the bodies are on a date: heliocentric ecliptic coordinates of J2000, in astronomical units, as `x, y, z` for each (the two-body orbit of each one's elements).
151
+ *
152
+ * @param bodies - The bodies, from `loadBeltBodies` or your own.
153
+ * @param jd - The date, as a Julian date (TT).
154
+ * @returns A `Float32Array` of three numbers a body.
155
+ *
156
+ * @example
157
+ * ```ts
158
+ * import { beltPositions } from "@johnmorrisdotca/wakusei-planets/belts";
159
+ *
160
+ * const place = beltPositions([{ name: "T", a: 2.7, e: 0.1, i: 5, node: 80, peri: 70, M0: 10, epoch: 2461200.5, H: 9 }], 2461200.5);
161
+ * console.log(Math.hypot(place[0]!, place[1]!, place[2]!).toFixed(2));
162
+ * ```
163
+ */
164
+ export declare function beltPositions(bodies: readonly SmallBody[], jd: number): Float32Array;
165
+ /**
166
+ * How many bodies each belt has among the ones given.
167
+ *
168
+ * @param bodies - The bodies.
169
+ * @returns A count for every belt (zero where there are none).
170
+ *
171
+ * @example
172
+ * ```ts
173
+ * import { beltCounts } from "@johnmorrisdotca/wakusei-planets/belts";
174
+ *
175
+ * console.log(beltCounts([{ name: "T", a: 2.7, e: 0.1, i: 5, node: 80, peri: 70, M0: 10, epoch: 2461200.5, H: 9, belt: "main" }]).main);
176
+ * ```
177
+ */
178
+ export declare function beltCounts(bodies: readonly BeltBody[]): Record<BeltId, number>;
179
+ /**
180
+ * How the bodies lie by distance from the Sun on a date: for each slice of distance, how many there are and how many to the cubic astronomical unit (the slice is a ring as thick as the bodies in it are spread above and
181
+ * below the ecliptic).
182
+ *
183
+ * @param bodies - The bodies.
184
+ * @param jd - The date, as a Julian date (TT).
185
+ * @param options - `from` and `to` (astronomical units, 0 and 60 by default) and `bins` (60 by default).
186
+ * @returns The start of each slice, the count in it and the density in it.
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * import { beltDensity } from "@johnmorrisdotca/wakusei-planets/belts";
191
+ *
192
+ * const bodies = [{ name: "T", a: 2.7, e: 0.1, i: 5, node: 80, peri: 70, M0: 10, epoch: 2461200.5, H: 9, belt: "main" as const }];
193
+ * console.log(beltDensity(bodies, 2461200.5, { from: 2, to: 4, bins: 4 }).count.join(","));
194
+ * ```
195
+ */
196
+ export declare function beltDensity(bodies: readonly SmallBody[], jd: number, options?: {
197
+ from?: number;
198
+ to?: number;
199
+ bins?: number;
200
+ }): {
201
+ start: number[];
202
+ count: number[];
203
+ perCubicAu: number[];
204
+ };
205
+ /**
206
+ * How far apart the bodies of a belt really are, as a typical distance between neighbours: the belt as a ring (from the tenth to the ninetieth percentile of its bodies' distances from the Sun, as thick as they are
207
+ * spread above and below the ecliptic) shared among the bodies the database holds. Space is mostly empty: even the main belt's 1.4 million known bodies are millions of kilometres apart (the Moon is 384,000 km from the Earth), and the ones
208
+ * this package draws, a few hundred or thousand of them, are much further apart than that. The estimate is rough (a belt's edge is not sharp) and the real number of bodies is more than the known one, so the true spacing is less.
209
+ *
210
+ * @param belt - The belt.
211
+ * @param bodies - The bodies of every belt (or at least of this one).
212
+ * @param jd - The date, as a Julian date (TT).
213
+ * @returns `known` (kilometres between neighbours if the belt held only the bodies the database knows of), `drawn` (the same for the bodies given), and the ring's `innerAu`, `outerAu` and `thicknessAu`.
214
+ *
215
+ * @example
216
+ * ```ts
217
+ * import { beltSpacing } from "@johnmorrisdotca/wakusei-planets/belts";
218
+ *
219
+ * const bodies = Array.from({ length: 50 }, (_, k) => ({ name: String(k), a: 2.2 + k * 0.02, e: 0.1, i: 5, node: k * 7, peri: 70, M0: k * 11, epoch: 2461200.5, H: 9, belt: "main" as const }));
220
+ * console.log(Math.round(beltSpacing("main", bodies, 2461200.5).known / 1e6), "million km");
221
+ * ```
222
+ */
223
+ export declare function beltSpacing(belt: BeltId, bodies: readonly BeltBody[], jd: number): {
224
+ known: number;
225
+ drawn: number;
226
+ innerAu: number;
227
+ outerAu: number;
228
+ thicknessAu: number;
229
+ };
230
+ /**
231
+ * The sentence the space view shows while the camera is in a belt, in English or Japanese: what it is, how many bodies are known, how far apart they really are (in Moon distances, the Moon being 384,400 km from the Earth), and
232
+ * that the dots drawn are only the brightest few and are made big enough to see.
233
+ *
234
+ * @param belt - The belt.
235
+ * @param spacing - From `beltSpacing`.
236
+ * @param language - `en` or `ja`.
237
+ * @returns A sentence or two.
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * import { beltNote } from "@johnmorrisdotca/wakusei-planets/belts";
242
+ *
243
+ * console.log(beltNote("main", { known: 2_800_000, drawn: 30_000_000 }, "en"));
244
+ * ```
245
+ */
246
+ export declare function beltNote(belt: BeltId, spacing: {
247
+ known: number;
248
+ drawn: number;
249
+ }, language: "en" | "ja"): string;
250
+ /**
251
+ * A point that flies through a belt, for `<wakusei-space>`'s `ride`: a circle round the Sun in the belt's middle at 0.3 astronomical units a day of game time (about 500 kilometres a second, thirty times the speed of the bodies, which drift past), tilted
252
+ * a few degrees to the ecliptic so that it passes through the belt's thickness, going the way the planets go. It returns the place and the velocity in kilometres and kilometres a second from the Sun's centre, in the space view's axes (equatorial J2000, y north).
253
+ *
254
+ * @param belt - The belt.
255
+ * @returns A `RidePoint`: `at(ms)` gives its place and velocity at a moment.
256
+ *
257
+ * @example
258
+ * ```ts
259
+ * import { beltFlight } from "@johnmorrisdotca/wakusei-planets/belts";
260
+ *
261
+ * const at = beltFlight("main").at(Date.UTC(2026, 10, 10));
262
+ * console.log(Math.round(Math.hypot(...at.position) / 149_597_870.7 * 10) / 10, "au");
263
+ * ```
264
+ */
265
+ export declare function beltFlight(belt: BeltId): {
266
+ at(ms: number): {
267
+ position: [number, number, number];
268
+ velocity: [number, number, number];
269
+ };
270
+ };
@@ -0,0 +1,308 @@
1
+ // The asteroid belts and the Kuiper belt as data: a few thousand numbered small bodies from NASA/JPL's Small-Body Database in seven belts (the main belt, the Hildas, the Jupiter Trojans, the Centaurs, and the Kuiper
2
+ // belt as classical, resonant and scattered objects), a source of them for `<wakusei-space>` (the data door: one instanced draw for each belt), where they are on a date, how many there are and how thickly they
3
+ // lie by distance from the Sun, and how far apart the bodies of a belt really are. The elements are in `./data.ts`, a chunk of its own that a page fetches only when it uses it. Pure: no DOM, no three.js.
4
+ import { BELT_EPOCH, BELT_SAMPLE, BELT_TOTALS } from "./totals.js";
5
+ import { smallBodyAt } from "../door/small-bodies.js";
6
+ import { madeHere } from "../door/own.js";
7
+ /**
8
+ * The belts, nearest the Sun first.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { BELT_IDS } from "@johnmorrisdotca/wakusei-planets/belts";
13
+ *
14
+ * console.log(BELT_IDS.join(", "));
15
+ * ```
16
+ */
17
+ export const BELT_IDS = ["main", "hilda", "trojan", "centaur", "classical", "resonant", "scattered"];
18
+ const info = (id, en, ja, aboutEn, aboutJa, colour, known) => ({ id, name: { en, ja }, about: { en: aboutEn, ja: aboutJa }, colour, known, sample: BELT_SAMPLE[id] });
19
+ /**
20
+ * The seven belts, by name.
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * import { BELTS } from "@johnmorrisdotca/wakusei-planets/belts";
25
+ *
26
+ * console.log(BELTS.trojan.known > BELTS.centaur.known);
27
+ * ```
28
+ */
29
+ export const BELTS = {
30
+ main: info("main", "Main belt", "メインベルト", "between Mars and Jupiter, 2.1 to 3.3 au from the Sun", "火星と木星のあいだ、太陽から2.1〜3.3天文単位", "#d9d3c3", BELT_TOTALS.main),
31
+ hilda: info("hilda", "Hildas", "ヒルダ群", "locked to Jupiter, 3.9 to 4.1 au out, in a rounded triangle", "木星と共鳴する天体。太陽から3.9〜4.1天文単位で、丸い三角形をなす", "#ffb86b", BELT_TOTALS.hilda),
32
+ trojan: info("trojan", "Jupiter Trojans", "木星トロヤ群", "two swarms on Jupiter's orbit, 60 degrees ahead of it and 60 behind", "木星の軌道上で、木星の60度前と60度後ろにある2つの群れ", "#7fd4ff", BELT_TOTALS.trojan),
33
+ centaur: info("centaur", "Centaurs", "ケンタウルス族", "icy bodies on orbits that cross the giant planets, 5 to 30 au out", "巨大惑星の軌道と交わる氷の天体。太陽から5〜30天文単位", "#ff8fb1", BELT_TOTALS.centaur),
34
+ classical: info("classical", "Kuiper belt, classical", "カイパーベルト (古典的)", "on nearly round orbits 39 to 48 au out, beyond Neptune", "海王星の外、太陽から39〜48天文単位のほぼ円形の軌道", "#9ee493", BELT_TOTALS.classical),
35
+ resonant: info("resonant", "Kuiper belt, resonant", "カイパーベルト (共鳴)", "in step with Neptune (Pluto and the other plutinos are 3:2)", "海王星と共鳴する天体 (冥王星などのプルティノは3:2共鳴)", "#d6a8ff", BELT_TOTALS.resonant),
36
+ scattered: info("scattered", "Kuiper belt, scattered", "カイパーベルト (散乱円盤)", "on long, tilted orbits thrown outwards by Neptune", "海王星に外へはじき出された、細長くかたむいた軌道", "#ffe36b", BELT_TOTALS.scattered),
37
+ };
38
+ /**
39
+ * The Oort cloud, which no orbit in this package is drawn for: a shell of comets thought to lie round the whole solar system, from about 2,000 to about 100,000 astronomical units from the Sun (the outer edge
40
+ * is far beyond anything measured). The space view draws it as a labelled shell where its distances fit.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { OORT } from "@johnmorrisdotca/wakusei-planets/belts";
45
+ *
46
+ * console.log(OORT.innerAu, OORT.outerAu);
47
+ * ```
48
+ */
49
+ export const OORT = { innerAu: 2000, outerAu: 100_000, name: { en: "Oort cloud", ja: "オールトの雲" }, about: { en: "where long-period comets are thought to come from: nothing in it has been seen", ja: "長周期彗星の起源と考えられる領域。そこにある天体はまだ見つかっていません" } };
50
+ export { BELT_EPOCH };
51
+ export { BELT_TOTALS };
52
+ /**
53
+ * Reads the rows of one belt (`name|a|e|i|node|peri|M0|H`, one body to a line) into bodies.
54
+ *
55
+ * @param belt - The belt they are in.
56
+ * @param rows - The text.
57
+ * @param epoch - The Julian date the elements are given at.
58
+ * @returns The bodies.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * import { parseBeltRows } from "@johnmorrisdotca/wakusei-planets/belts";
63
+ *
64
+ * console.log(parseBeltRows("trojan", "588 Achilles|5.216|.148|10.3|316.5|134.3|93.3|8.2", 2461200.5)[0]?.name);
65
+ * ```
66
+ */
67
+ export function parseBeltRows(belt, rows, epoch) {
68
+ const out = [];
69
+ for (const line of rows.split("\n")) {
70
+ const f = line.split("|");
71
+ if (f.length !== 8)
72
+ continue;
73
+ out.push({ name: f[0], a: Number(f[1]), e: Number(f[2]), i: Number(f[3]), node: Number(f[4]), peri: Number(f[5]), M0: Number(f[6]), epoch, H: Number(f[7]), belt });
74
+ }
75
+ return out;
76
+ }
77
+ let loaded;
78
+ /**
79
+ * Fetches the bodies of every belt: a chunk of its own (about 70 kB gzipped), read once. A page that never calls this, and never draws the belts, does not carry it.
80
+ *
81
+ * @returns The bodies, belt by belt, the brightest first in each.
82
+ *
83
+ * @example
84
+ * ```ts
85
+ * import { loadBeltBodies } from "@johnmorrisdotca/wakusei-planets/belts";
86
+ *
87
+ * const bodies = await loadBeltBodies();
88
+ * console.log(bodies.length, bodies[0]?.belt);
89
+ * ```
90
+ */
91
+ export function loadBeltBodies() {
92
+ loaded ??= import("./data.js").then((data) => Object.freeze(BELT_IDS.flatMap((id) => parseBeltRows(id, data.BELT_ROWS[id] ?? "", BELT_EPOCH))));
93
+ return loaded;
94
+ }
95
+ /**
96
+ * The belts as a source of the data door, which `<wakusei-space>` adds itself (turn it off with `belts="off"`, or `space.enableSource("wakusei-belts", false)`): the records are fetched when the view first reads them. It is the
97
+ * package's own source, so it is credited with the rest of the package's data and `data="own"` keeps it.
98
+ *
99
+ * @returns A record source of `BeltBody` records.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * import { beltsSource } from "@johnmorrisdotca/wakusei-planets/belts";
104
+ *
105
+ * console.log(beltsSource().info.id, beltsSource().info.licence.name);
106
+ * ```
107
+ */
108
+ export function beltsSource() {
109
+ return madeHere({
110
+ kind: "records",
111
+ info: {
112
+ id: "wakusei-belts",
113
+ name: { en: "Asteroid and Kuiper belts", ja: "小惑星帯とカイパーベルト" },
114
+ credit: { en: "Asteroid, Trojan, Centaur and Kuiper belt orbits: NASA/JPL Small-Body Database", ja: "小惑星帯・トロヤ群・ケンタウルス族・カイパーベルトの軌道:NASA/JPL小天体データベース" },
115
+ licence: { name: "Public domain (NASA/JPL: not subject to copyright in the United States)", url: "https://www.nasa.gov/nasa-brand-center/images-and-media/" },
116
+ url: "https://ssd-api.jpl.nasa.gov/doc/sbdb_query.html",
117
+ retrieved: "2026-11-10",
118
+ },
119
+ records: () => loadBeltBodies().then((all) => [...all]),
120
+ });
121
+ }
122
+ /**
123
+ * Where the bodies are on a date: heliocentric ecliptic coordinates of J2000, in astronomical units, as `x, y, z` for each (the two-body orbit of each one's elements).
124
+ *
125
+ * @param bodies - The bodies, from `loadBeltBodies` or your own.
126
+ * @param jd - The date, as a Julian date (TT).
127
+ * @returns A `Float32Array` of three numbers a body.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * import { beltPositions } from "@johnmorrisdotca/wakusei-planets/belts";
132
+ *
133
+ * const place = beltPositions([{ name: "T", a: 2.7, e: 0.1, i: 5, node: 80, peri: 70, M0: 10, epoch: 2461200.5, H: 9 }], 2461200.5);
134
+ * console.log(Math.hypot(place[0]!, place[1]!, place[2]!).toFixed(2));
135
+ * ```
136
+ */
137
+ export function beltPositions(bodies, jd) {
138
+ const out = new Float32Array(bodies.length * 3);
139
+ bodies.forEach((body, k) => out.set(smallBodyAt(body, jd), k * 3));
140
+ return out;
141
+ }
142
+ /**
143
+ * How many bodies each belt has among the ones given.
144
+ *
145
+ * @param bodies - The bodies.
146
+ * @returns A count for every belt (zero where there are none).
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * import { beltCounts } from "@johnmorrisdotca/wakusei-planets/belts";
151
+ *
152
+ * console.log(beltCounts([{ name: "T", a: 2.7, e: 0.1, i: 5, node: 80, peri: 70, M0: 10, epoch: 2461200.5, H: 9, belt: "main" }]).main);
153
+ * ```
154
+ */
155
+ export function beltCounts(bodies) {
156
+ const out = Object.fromEntries(BELT_IDS.map((id) => [id, 0]));
157
+ for (const body of bodies)
158
+ out[body.belt] += 1;
159
+ return out;
160
+ }
161
+ /**
162
+ * How the bodies lie by distance from the Sun on a date: for each slice of distance, how many there are and how many to the cubic astronomical unit (the slice is a ring as thick as the bodies in it are spread above and
163
+ * below the ecliptic).
164
+ *
165
+ * @param bodies - The bodies.
166
+ * @param jd - The date, as a Julian date (TT).
167
+ * @param options - `from` and `to` (astronomical units, 0 and 60 by default) and `bins` (60 by default).
168
+ * @returns The start of each slice, the count in it and the density in it.
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * import { beltDensity } from "@johnmorrisdotca/wakusei-planets/belts";
173
+ *
174
+ * const bodies = [{ name: "T", a: 2.7, e: 0.1, i: 5, node: 80, peri: 70, M0: 10, epoch: 2461200.5, H: 9, belt: "main" as const }];
175
+ * console.log(beltDensity(bodies, 2461200.5, { from: 2, to: 4, bins: 4 }).count.join(","));
176
+ * ```
177
+ */
178
+ export function beltDensity(bodies, jd, options = {}) {
179
+ const from = options.from ?? 0;
180
+ const to = options.to ?? 60;
181
+ const bins = Math.max(1, Math.round(options.bins ?? 60));
182
+ const width = (to - from) / bins;
183
+ const count = new Array(bins).fill(0);
184
+ const z2 = new Array(bins).fill(0);
185
+ for (const body of bodies) {
186
+ const [x, y, z] = smallBodyAt(body, jd);
187
+ const k = Math.floor((Math.hypot(x, y, z) - from) / width);
188
+ if (k < 0 || k >= bins)
189
+ continue;
190
+ count[k] += 1;
191
+ z2[k] += z * z;
192
+ }
193
+ const start = count.map((_, k) => from + k * width);
194
+ const perCubicAu = count.map((n, k) => {
195
+ if (n < 2)
196
+ return 0;
197
+ // a flat ring of the slice's width: its half-thickness from the spread of the bodies above and below the plane (a uniform layer of half-thickness h has a root-mean-square height of h over the square root of three)
198
+ const h = Math.max(0.02, Math.sqrt(3 * (z2[k] / n)));
199
+ const r0 = from + k * width;
200
+ return n / (Math.PI * ((r0 + width) ** 2 - r0 ** 2) * 2 * h);
201
+ });
202
+ return { start, count, perCubicAu };
203
+ }
204
+ /** Kilometres in an astronomical unit. */
205
+ const AU_KM = 149_597_870.7;
206
+ /**
207
+ * How far apart the bodies of a belt really are, as a typical distance between neighbours: the belt as a ring (from the tenth to the ninetieth percentile of its bodies' distances from the Sun, as thick as they are
208
+ * spread above and below the ecliptic) shared among the bodies the database holds. Space is mostly empty: even the main belt's 1.4 million known bodies are millions of kilometres apart (the Moon is 384,000 km from the Earth), and the ones
209
+ * this package draws, a few hundred or thousand of them, are much further apart than that. The estimate is rough (a belt's edge is not sharp) and the real number of bodies is more than the known one, so the true spacing is less.
210
+ *
211
+ * @param belt - The belt.
212
+ * @param bodies - The bodies of every belt (or at least of this one).
213
+ * @param jd - The date, as a Julian date (TT).
214
+ * @returns `known` (kilometres between neighbours if the belt held only the bodies the database knows of), `drawn` (the same for the bodies given), and the ring's `innerAu`, `outerAu` and `thicknessAu`.
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * import { beltSpacing } from "@johnmorrisdotca/wakusei-planets/belts";
219
+ *
220
+ * const bodies = Array.from({ length: 50 }, (_, k) => ({ name: String(k), a: 2.2 + k * 0.02, e: 0.1, i: 5, node: k * 7, peri: 70, M0: k * 11, epoch: 2461200.5, H: 9, belt: "main" as const }));
221
+ * console.log(Math.round(beltSpacing("main", bodies, 2461200.5).known / 1e6), "million km");
222
+ * ```
223
+ */
224
+ export function beltSpacing(belt, bodies, jd) {
225
+ const mine = bodies.filter((body) => body.belt === belt);
226
+ const r = [];
227
+ let z2 = 0;
228
+ for (const body of mine) {
229
+ const [x, y, z] = smallBodyAt(body, jd);
230
+ r.push(Math.hypot(x, y, z));
231
+ z2 += z * z;
232
+ }
233
+ r.sort((a, b) => a - b);
234
+ const at = (q) => r[Math.min(r.length - 1, Math.max(0, Math.floor(q * r.length)))] ?? 0;
235
+ const inner = at(0.1);
236
+ const outer = at(0.9);
237
+ const half = Math.sqrt(3 * (z2 / Math.max(1, mine.length)));
238
+ const volume = Math.PI * (outer ** 2 - inner ** 2) * 2 * half;
239
+ const apart = (n) => (n > 0 && volume > 0 ? Math.cbrt(volume / n) * AU_KM : 0);
240
+ return { known: apart(BELTS[belt].known), drawn: apart(mine.length), innerAu: inner, outerAu: outer, thicknessAu: 2 * half };
241
+ }
242
+ /**
243
+ * The sentence the space view shows while the camera is in a belt, in English or Japanese: what it is, how many bodies are known, how far apart they really are (in Moon distances, the Moon being 384,400 km from the Earth), and
244
+ * that the dots drawn are only the brightest few and are made big enough to see.
245
+ *
246
+ * @param belt - The belt.
247
+ * @param spacing - From `beltSpacing`.
248
+ * @param language - `en` or `ja`.
249
+ * @returns A sentence or two.
250
+ *
251
+ * @example
252
+ * ```ts
253
+ * import { beltNote } from "@johnmorrisdotca/wakusei-planets/belts";
254
+ *
255
+ * console.log(beltNote("main", { known: 2_800_000, drawn: 30_000_000 }, "en"));
256
+ * ```
257
+ */
258
+ export function beltNote(belt, spacing, language) {
259
+ const b = BELTS[belt];
260
+ const moons = (km) => (km / 384_400 < 10 ? (km / 384_400).toFixed(1) : String(Math.round(km / 384_400)));
261
+ const million = (km) => (km / 1e6 < 10 ? (km / 1e6).toFixed(1) : String(Math.round(km / 1e6)));
262
+ const known = b.known.toLocaleString(language === "ja" ? "ja-JP" : "en-US");
263
+ // in Japanese a distance is in 万 (ten thousand) or 億 (a hundred million) kilometres
264
+ const wide = (km) => (km >= 1e8 ? `${(km / 1e8).toFixed(1)}億km` : `${Math.round(km / 1e4).toLocaleString("ja-JP")}万km`);
265
+ if (language === "ja") {
266
+ return `${b.name.ja}:知られている天体は${known}個ありますが、空間がとても広いので、となりの天体まではふつう約${wide(spacing.known)} (月までの距離の約${Number(moons(spacing.known)).toLocaleString("ja-JP")}倍) も離れています。ここはほとんど何もない空間です。描いてあるのは、いちばん明るい${b.sample.toLocaleString("ja-JP")}個だけで (間隔は約${wide(spacing.drawn)})、見えるように大きめの点にしています。`;
267
+ }
268
+ return `${b.name.en}: ${known} bodies are known, but they fill so much room that neighbours are typically ${million(spacing.known)} million km apart, about ${moons(spacing.known)} Moon distances: space here is almost all empty. The ${b.sample.toLocaleString("en-US")} drawn are only the brightest, about ${million(spacing.drawn)} million km apart, and each dot is made large enough to see.`;
269
+ }
270
+ /** How fast the flight goes, in astronomical units a day of game time (it is a flight, not an orbit: the belt's own bodies go about thirty times slower, so they drift past). */
271
+ const FLIGHT_AU_PER_DAY = 0.3;
272
+ /**
273
+ * A point that flies through a belt, for `<wakusei-space>`'s `ride`: a circle round the Sun in the belt's middle at 0.3 astronomical units a day of game time (about 500 kilometres a second, thirty times the speed of the bodies, which drift past), tilted
274
+ * a few degrees to the ecliptic so that it passes through the belt's thickness, going the way the planets go. It returns the place and the velocity in kilometres and kilometres a second from the Sun's centre, in the space view's axes (equatorial J2000, y north).
275
+ *
276
+ * @param belt - The belt.
277
+ * @returns A `RidePoint`: `at(ms)` gives its place and velocity at a moment.
278
+ *
279
+ * @example
280
+ * ```ts
281
+ * import { beltFlight } from "@johnmorrisdotca/wakusei-planets/belts";
282
+ *
283
+ * const at = beltFlight("main").at(Date.UTC(2026, 10, 10));
284
+ * console.log(Math.round(Math.hypot(...at.position) / 149_597_870.7 * 10) / 10, "au");
285
+ * ```
286
+ */
287
+ export function beltFlight(belt) {
288
+ const radii = { main: 2.7, hilda: 4, trojan: 5.2, centaur: 12, classical: 43, resonant: 39.5, scattered: 60 };
289
+ const r = radii[belt] * AU_KM;
290
+ const speed = (FLIGHT_AU_PER_DAY * AU_KM) / 86400;
291
+ const tilt = (6 * Math.PI) / 180;
292
+ const obliquity = (23.4392911 * Math.PI) / 180;
293
+ const omega = speed / r;
294
+ // from the ecliptic of J2000 to the scene's axes: x the same, the others turned by the obliquity (as space/frame.ts does)
295
+ const scene = (v) => [v[0], v[1] * Math.sin(obliquity) + v[2] * Math.cos(obliquity), -(v[1] * Math.cos(obliquity) - v[2] * Math.sin(obliquity))];
296
+ return {
297
+ at(ms) {
298
+ const t = (ms - Date.UTC(2000, 0, 1, 12)) / 1000;
299
+ const phase = omega * t;
300
+ // a circle in the plane tilted `tilt` about the x axis
301
+ const c = Math.cos(phase);
302
+ const s = Math.sin(phase);
303
+ const position = [r * c, r * s * Math.cos(tilt), r * s * Math.sin(tilt)];
304
+ const velocity = [-speed * s, speed * c * Math.cos(tilt), speed * c * Math.sin(tilt)];
305
+ return { position: scene(position), velocity: scene(velocity) };
306
+ },
307
+ };
308
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The Julian date (TT) of the elements of every body in `data.ts`: each body's mean anomaly was carried to it with the two-body mean motion.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { BELT_EPOCH } from "@johnmorrisdotca/wakusei-planets/belts";
7
+ *
8
+ * console.log(BELT_EPOCH);
9
+ * ```
10
+ */
11
+ export declare const BELT_EPOCH = 2461200.5;
12
+ /**
13
+ * What the database held on 2026-11-10: all asteroids, the numbered ones, and each group (the three kinds of the Kuiper belt are cut by their elements, see the script).
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { BELT_TOTALS } from "@johnmorrisdotca/wakusei-planets/belts";
18
+ *
19
+ * console.log(BELT_TOTALS.all > 1_500_000);
20
+ * ```
21
+ */
22
+ export declare const BELT_TOTALS: {
23
+ readonly all: 1580096;
24
+ readonly numbered: 895910;
25
+ readonly main: 1429419;
26
+ readonly hilda: 7929;
27
+ readonly trojan: 16472;
28
+ readonly centaur: 1087;
29
+ readonly tno: 8338;
30
+ readonly classical: 3000;
31
+ readonly resonant: 2306;
32
+ readonly scattered: 2266;
33
+ };
34
+ /** How many bodies of each belt `data.ts` holds: the brightest numbered ones. */
35
+ export declare const BELT_SAMPLE: {
36
+ readonly main: 1300;
37
+ readonly hilda: 220;
38
+ readonly trojan: 520;
39
+ readonly centaur: 200;
40
+ readonly classical: 300;
41
+ readonly resonant: 500;
42
+ readonly scattered: 300;
43
+ };
@@ -0,0 +1,25 @@
1
+ // Made by scripts/make-belts-data.py from NASA/JPL's Small-Body Database (https://ssd-api.jpl.nasa.gov/sbdb_query.api, read 2026-11-10). NASA/JPL data, not subject to copyright in the United States (credit: NASA/JPL-Caltech). Do not edit by hand.
2
+ /**
3
+ * The Julian date (TT) of the elements of every body in `data.ts`: each body's mean anomaly was carried to it with the two-body mean motion.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { BELT_EPOCH } from "@johnmorrisdotca/wakusei-planets/belts";
8
+ *
9
+ * console.log(BELT_EPOCH);
10
+ * ```
11
+ */
12
+ export const BELT_EPOCH = 2461200.5;
13
+ /**
14
+ * What the database held on 2026-11-10: all asteroids, the numbered ones, and each group (the three kinds of the Kuiper belt are cut by their elements, see the script).
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { BELT_TOTALS } from "@johnmorrisdotca/wakusei-planets/belts";
19
+ *
20
+ * console.log(BELT_TOTALS.all > 1_500_000);
21
+ * ```
22
+ */
23
+ export const BELT_TOTALS = { "all": 1580096, "numbered": 895910, "main": 1429419, "hilda": 7929, "trojan": 16472, "centaur": 1087, "tno": 8338, "classical": 3000, "resonant": 2306, "scattered": 2266 };
24
+ /** How many bodies of each belt `data.ts` holds: the brightest numbered ones. */
25
+ export const BELT_SAMPLE = { "main": 1300, "hilda": 220, "trojan": 520, "centaur": 200, "classical": 300, "resonant": 500, "scattered": 300 };