@johnmorrisdotca/wakusei-planets 0.35.0 → 0.37.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 +18 -0
- package/NOTICE.md +31 -1
- package/README.md +5 -4
- package/dist/data/moon-catalogue.d.ts +31 -0
- package/dist/data/moon-catalogue.js +471 -0
- package/dist/data/orbiters.d.ts +368 -0
- package/dist/data/orbiters.js +370 -0
- package/dist/data/places-planned.d.ts +3 -0
- package/dist/data/places-planned.js +51 -0
- package/dist/element.d.ts +28 -0
- package/dist/element.js +172 -1
- package/dist/moon-catalogue.d.ts +296 -0
- package/dist/moon-catalogue.js +234 -0
- package/dist/orbiter-facts.d.ts +480 -0
- package/dist/orbiter-facts.js +189 -0
- package/dist/orbiters.d.ts +256 -0
- package/dist/orbiters.js +275 -0
- package/dist/place-marks.d.ts +182 -0
- package/dist/place-marks.js +194 -0
- package/dist/places/mars.d.ts +1 -1
- package/dist/places/mars.js +4 -2
- package/dist/places/moon.d.ts +1 -1
- package/dist/places/moon.js +4 -2
- package/dist/places.d.ts +4 -2
- package/dist/places.js +2 -0
- package/dist/scene/place-layer.d.ts +68 -0
- package/dist/scene/place-layer.js +213 -0
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/all-moons.d.ts +30 -0
- package/dist/space/all-moons.js +61 -0
- package/dist/space/bodies.d.ts +18 -0
- package/dist/space/bodies.js +18 -0
- package/dist/space/element.d.ts +182 -6
- package/dist/space/element.js +763 -26
- package/dist/space/frame.d.ts +14 -0
- package/dist/space/frame.js +16 -0
- package/dist/space/index.d.ts +5 -2
- package/dist/space/index.js +5 -2
- package/dist/space/regions.d.ts +111 -0
- package/dist/space/regions.js +84 -0
- package/dist/space/scene.d.ts +131 -8
- package/dist/space/scene.js +312 -15
- package/dist/space/sight.d.ts +106 -0
- package/dist/space/sight.js +84 -0
- package/dist/space/travel.d.ts +256 -0
- package/dist/space/travel.js +597 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +13 -2
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// Every known moon of the planets and the dwarf planets, as a light list: names and designations, who found each and when, the mean orbit, the size where it is known, and where each is on a date from that orbit,
|
|
2
|
+
// with how far that position was measured to be from JPL Horizons. The rows (scripts/make-moon-catalogue.py, src/data/moon-catalogue.ts) are imported by this entry point only, so a page that does not import
|
|
3
|
+
// `/moon-catalogue` does not carry them. Positions are from the planet's centre, in kilometres, in the J2000 ecliptic frame (the axes `moonVector` gives). Pure: no DOM, no clock reads, no three.js.
|
|
4
|
+
import { MOON_CATALOGUE_READ, MOON_CATALOGUE_ROWS } from "./data/moon-catalogue.js";
|
|
5
|
+
import { toTerrestrialTime } from "./clock.js";
|
|
6
|
+
import { kepler } from "./ephemeris.js";
|
|
7
|
+
import { cross, fromRaDec, RAD, toEcliptic } from "./vec.js";
|
|
8
|
+
import { moment } from "./when.js";
|
|
9
|
+
const DAY_MS = 86_400_000;
|
|
10
|
+
const UNIX_JD = 2_440_587.5;
|
|
11
|
+
const YEAR_DAYS = 365.25;
|
|
12
|
+
/**
|
|
13
|
+
* Every group, in the order the guide lists them.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { MOON_GROUPS } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
|
|
18
|
+
*
|
|
19
|
+
* console.log(MOON_GROUPS.join(", "));
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export const MOON_GROUPS = ["inner", "major", "regular", "themisto", "himalia", "carpo", "valetudo", "ananke", "carme", "pasiphae", "inuit", "gallic", "norse", "prograde", "retrograde", "none"];
|
|
23
|
+
/**
|
|
24
|
+
* The albedo a `derived` size takes when the Horizons sheet gives none: 0.04, the albedo the sheet gives for Himalia, the largest of the irregular moons. The few other irregular moons with an albedo on their sheets have 0.03
|
|
25
|
+
* (Elara) to 0.081 (Phoebe), and Nereid 0.2; a darker moon is larger than the estimate and a brighter one smaller, so a derived radius is a guide to the size, not a measurement.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { ASSUMED_ALBEDO } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
|
|
30
|
+
*
|
|
31
|
+
* console.log(ASSUMED_ALBEDO);
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export const ASSUMED_ALBEDO = 0.04;
|
|
35
|
+
const FRAMES = ["ecliptic", "equatorial", "laplace"];
|
|
36
|
+
const SIZE_FROM = ["measured", "sheet"];
|
|
37
|
+
function moonOf(row) {
|
|
38
|
+
const [id, name, designation, number, host, code, year, by, reference, o, radius, sigma, from, albedo, magnitude, worstKm, worstDegrees, farDegrees, group, ja, confirmed] = row;
|
|
39
|
+
const orbit = o === null
|
|
40
|
+
? null
|
|
41
|
+
: {
|
|
42
|
+
frame: FRAMES[o[0]],
|
|
43
|
+
...(o[12] === undefined ? {} : { pole: [o[12], o[13]] }),
|
|
44
|
+
epochJd: o[1],
|
|
45
|
+
a: o[2],
|
|
46
|
+
e: o[3],
|
|
47
|
+
w: o[4],
|
|
48
|
+
m: o[5],
|
|
49
|
+
i: o[6],
|
|
50
|
+
node: o[7],
|
|
51
|
+
periodDays: o[8],
|
|
52
|
+
apsisYears: o[9],
|
|
53
|
+
nodeYears: o[10],
|
|
54
|
+
ephemeris: o[11],
|
|
55
|
+
};
|
|
56
|
+
let radiusKm = radius;
|
|
57
|
+
let radiusFrom = from === null ? null : SIZE_FROM[from];
|
|
58
|
+
if (radiusKm === null && magnitude !== null) {
|
|
59
|
+
radiusKm = Math.round(10 ** (3.1236 - 0.5 * Math.log10(albedo ?? ASSUMED_ALBEDO) - 0.2 * magnitude) * 5) / 10;
|
|
60
|
+
radiusFrom = "derived";
|
|
61
|
+
}
|
|
62
|
+
const grade = orbit === null ? "none" : worstDegrees === null ? "unmeasured" : worstDegrees < 1 ? "close" : worstDegrees < 10 ? "rough" : "loose";
|
|
63
|
+
return {
|
|
64
|
+
id,
|
|
65
|
+
name,
|
|
66
|
+
ja,
|
|
67
|
+
designation,
|
|
68
|
+
label: name ?? designation ?? id,
|
|
69
|
+
number,
|
|
70
|
+
host,
|
|
71
|
+
code,
|
|
72
|
+
named: name !== null,
|
|
73
|
+
confirmed: confirmed !== 0,
|
|
74
|
+
discovery: { year, by, reference },
|
|
75
|
+
orbit,
|
|
76
|
+
retrograde: orbit === null ? null : orbit.i > 90,
|
|
77
|
+
group,
|
|
78
|
+
radiusKm,
|
|
79
|
+
radiusSigmaKm: sigma,
|
|
80
|
+
radiusFrom,
|
|
81
|
+
albedo,
|
|
82
|
+
magnitude,
|
|
83
|
+
accuracy: worstKm === null || worstDegrees === null ? null : { worstKm, worstDegrees, farDegrees },
|
|
84
|
+
grade,
|
|
85
|
+
full: ja !== null,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Every known moon of the planets and the dwarf planets, as JPL lists them on `MOON_CATALOGUE_FETCHED`, in the order of the planets and, within a planet, of JPL's list (the long-known moons first, then by discovery).
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { MOON_CATALOGUE } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
|
|
94
|
+
*
|
|
95
|
+
* console.log(MOON_CATALOGUE.length, "moons;", MOON_CATALOGUE.filter((m) => m.named).length, "with a name");
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export const MOON_CATALOGUE = MOON_CATALOGUE_ROWS.map(moonOf);
|
|
99
|
+
/**
|
|
100
|
+
* The day the catalogue was read from JPL. New moons are announced every year; `scripts/make-moon-catalogue.py --refresh` reads the sources again and prints what changed.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* import { MOON_CATALOGUE_FETCHED } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
|
|
105
|
+
*
|
|
106
|
+
* console.log("moons as of", MOON_CATALOGUE_FETCHED);
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export const MOON_CATALOGUE_FETCHED = MOON_CATALOGUE_READ;
|
|
110
|
+
/**
|
|
111
|
+
* The counts for every planet and dwarf planet that has a moon in the catalogue.
|
|
112
|
+
*
|
|
113
|
+
* @returns A count for each host, in the catalogue's order.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* import { moonCounts } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
|
|
118
|
+
*
|
|
119
|
+
* for (const [host, count] of Object.entries(moonCounts())) console.log(host, count.total);
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export function moonCounts() {
|
|
123
|
+
const out = {};
|
|
124
|
+
for (const moon of MOON_CATALOGUE) {
|
|
125
|
+
const count = (out[moon.host] ??= { total: 0, named: 0, placed: 0 });
|
|
126
|
+
count.total += 1;
|
|
127
|
+
if (moon.named)
|
|
128
|
+
count.named += 1;
|
|
129
|
+
if (moon.orbit !== null)
|
|
130
|
+
count.placed += 1;
|
|
131
|
+
}
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* The moons of one planet or dwarf planet, nearest first (by the mean orbit's semi-major axis; a moon with no orbit last), optionally of one group.
|
|
136
|
+
*
|
|
137
|
+
* @param host - The planet or dwarf planet: "jupiter", "eris".
|
|
138
|
+
* @param group - A group, to narrow the list.
|
|
139
|
+
* @returns The moons, which must not be changed.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* import { catalogueMoonsOf } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
|
|
144
|
+
*
|
|
145
|
+
* console.log(catalogueMoonsOf("jupiter", "himalia").map((m) => m.label).join(", "));
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export function catalogueMoonsOf(host, group) {
|
|
149
|
+
return MOON_CATALOGUE.filter((m) => m.host === host && (group === undefined || m.group === group)).sort((a, b) => (a.orbit?.a ?? Infinity) - (b.orbit?.a ?? Infinity));
|
|
150
|
+
}
|
|
151
|
+
const plain = (text) => text.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[^a-z0-9-ヿ一-鿿]/g, "");
|
|
152
|
+
/**
|
|
153
|
+
* Finds a moon by its id, name (English, or Japanese for the package's own moons), designation (spaces and slashes do not matter: "S/2003 J 18", "s2003j18") or JPL code (501). Ignores case and accents.
|
|
154
|
+
*
|
|
155
|
+
* @param query - The id, name, designation or code.
|
|
156
|
+
* @returns The moon, or `undefined`.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```ts
|
|
160
|
+
* import { findCatalogueMoon } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
|
|
161
|
+
*
|
|
162
|
+
* console.log(findCatalogueMoon("io")?.code, findCatalogueMoon(506)?.label, findCatalogueMoon("s2003j18")?.host, findCatalogueMoon("nothing"));
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export function findCatalogueMoon(query) {
|
|
166
|
+
if (typeof query === "number")
|
|
167
|
+
return MOON_CATALOGUE.find((m) => m.code === query);
|
|
168
|
+
const q = plain(query);
|
|
169
|
+
if (q === "")
|
|
170
|
+
return undefined;
|
|
171
|
+
return MOON_CATALOGUE.find((m) => [m.id, m.name, m.ja, m.designation, m.code === null ? null : String(m.code)].some((v) => v !== null && plain(v) === q));
|
|
172
|
+
}
|
|
173
|
+
const basisCache = new Map();
|
|
174
|
+
function basisOf(pole) {
|
|
175
|
+
if (pole === null)
|
|
176
|
+
return [[1, 0, 0], [0, 1, 0], [0, 0, 1]];
|
|
177
|
+
const key = pole.join();
|
|
178
|
+
let basis = basisCache.get(key);
|
|
179
|
+
if (basis === undefined) {
|
|
180
|
+
const z = fromRaDec(pole[0], pole[1]);
|
|
181
|
+
const x = fromRaDec(pole[0] + 90, 0);
|
|
182
|
+
basis = [toEcliptic(x), toEcliptic(cross(z, x)), toEcliptic(z)];
|
|
183
|
+
basisCache.set(key, basis);
|
|
184
|
+
}
|
|
185
|
+
return basis;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The rates a mean orbit turns at, degrees a day: the mean anomaly's from the sidereal period (the mean longitude goes once round in it, so the mean anomaly runs slower by the turning of the other two); the periapsis turning forwards where 5 cos²i - 1 is positive and backwards where it is negative, and the node backwards on a prograde orbit
|
|
189
|
+
* and forwards on a retrograde one, as a planet's flattening and the Sun's pull turn them; each at the speed of the period the source gives (none where it gives none).
|
|
190
|
+
*/
|
|
191
|
+
function ratesOf(orbit) {
|
|
192
|
+
const ci = Math.cos(orbit.i * RAD);
|
|
193
|
+
const dw = orbit.apsisYears ? (Math.sign(5 * ci * ci - 1) * 360) / (orbit.apsisYears * YEAR_DAYS) : 0;
|
|
194
|
+
const dn = orbit.nodeYears ? (-Math.sign(ci) * 360) / (orbit.nodeYears * YEAR_DAYS) : 0;
|
|
195
|
+
return [360 / orbit.periodDays - dw - dn, dw, dn];
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Where a moon is at a moment, from its planet's centre, in kilometres, in the J2000 ecliptic frame (the axes of `moonVector`): its mean orbit, turned for the precession of its periapsis and node, solved by Kepler's
|
|
199
|
+
* equation. How close that is to the moon's real place near 2026 is the moon's `accuracy` and `grade`; decades away it drifts much further (`accuracy.farDegrees`). A moon the package draws in full is placed far better
|
|
200
|
+
* by the main entry point's `moonVector`.
|
|
201
|
+
*
|
|
202
|
+
* @param moon - A moon of the catalogue, or its id, name, designation or code.
|
|
203
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
204
|
+
* @returns x, y, z in kilometres, or `undefined` for a moon with no orbit.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* import { catalogueMoonPosition } from "@johnmorrisdotca/wakusei-planets/moon-catalogue";
|
|
209
|
+
*
|
|
210
|
+
* const [x, y, z] = catalogueMoonPosition("Himalia", new Date("2026-11-11T00:00:00Z"))!;
|
|
211
|
+
* console.log(Math.round(Math.hypot(x, y, z) / 1e6), "million km from Jupiter");
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
export function catalogueMoonPosition(moon, when) {
|
|
215
|
+
const m = typeof moon === "object" ? moon : findCatalogueMoon(moon);
|
|
216
|
+
if (m === undefined)
|
|
217
|
+
throw new RangeError(`unknown moon ${JSON.stringify(moon)}; look one up with findCatalogueMoon`);
|
|
218
|
+
const orbit = m.orbit;
|
|
219
|
+
if (orbit === null)
|
|
220
|
+
return undefined;
|
|
221
|
+
const [n, dw, dn] = ratesOf(orbit);
|
|
222
|
+
const dt = toTerrestrialTime(moment(when)) / DAY_MS + UNIX_JD - orbit.epochJd;
|
|
223
|
+
const w = (orbit.w + dw * dt) * RAD;
|
|
224
|
+
const node = (orbit.node + dn * dt) * RAD;
|
|
225
|
+
const E = kepler((orbit.m + n * dt) * RAD, orbit.e);
|
|
226
|
+
const x = orbit.a * (Math.cos(E) - orbit.e);
|
|
227
|
+
const y = orbit.a * Math.sqrt(1 - orbit.e * orbit.e) * Math.sin(E);
|
|
228
|
+
const [cw, sw, cn, sn, ci, si] = [Math.cos(w), Math.sin(w), Math.cos(node), Math.sin(node), Math.cos(orbit.i * RAD), Math.sin(orbit.i * RAD)];
|
|
229
|
+
const px = (cw * cn - sw * sn * ci) * x + (-sw * cn - cw * sn * ci) * y;
|
|
230
|
+
const py = (cw * sn + sw * cn * ci) * x + (-sw * sn + cw * cn * ci) * y;
|
|
231
|
+
const pz = sw * si * x + cw * si * y;
|
|
232
|
+
const [bx, by, bz] = basisOf(orbit.frame === "ecliptic" ? null : (orbit.pole ?? null));
|
|
233
|
+
return [px * bx[0] + py * by[0] + pz * bz[0], px * bx[1] + py * by[1] + pz * bz[1], px * bx[2] + py * by[2] + pz * bz[2]];
|
|
234
|
+
}
|