@johnmorrisdotca/wakusei-planets 0.33.0 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/NOTICE.md +52 -0
- package/README.md +26 -3
- package/dist/approaches.d.ts +276 -0
- package/dist/approaches.js +255 -0
- package/dist/asteroids.d.ts +397 -0
- package/dist/asteroids.js +338 -0
- package/dist/comets.d.ts +316 -0
- package/dist/comets.js +404 -0
- package/dist/craft/bepicolombo.d.ts +1 -0
- package/dist/craft/bepicolombo.js +923 -0
- package/dist/craft/europaclipper.d.ts +1 -0
- package/dist/craft/europaclipper.js +342 -0
- package/dist/craft/hayabusa2.d.ts +1 -0
- package/dist/craft/hayabusa2.js +73 -0
- package/dist/craft/juice.d.ts +1 -0
- package/dist/craft/juice.js +40 -0
- package/dist/craft/lucy.d.ts +1 -0
- package/dist/craft/lucy.js +42 -0
- package/dist/craft/osirisapex.d.ts +1 -0
- package/dist/craft/osirisapex.js +69 -0
- package/dist/craft/psyche.d.ts +1 -0
- package/dist/craft/psyche.js +30 -0
- package/dist/craft/solarorbiter.d.ts +1 -0
- package/dist/craft/solarorbiter.js +94 -0
- package/dist/data/approaches.d.ts +17 -0
- package/dist/data/approaches.js +4192 -0
- package/dist/data/asteroids.d.ts +3 -0
- package/dist/data/asteroids.js +107 -0
- package/dist/data/comets.d.ts +2 -0
- package/dist/data/comets.js +36 -0
- package/dist/data/places-67p.d.ts +27 -0
- package/dist/data/places-67p.js +2 -0
- package/dist/data/places-ariel.d.ts +602 -0
- package/dist/data/places-ariel.js +27 -0
- package/dist/data/places-bennu.d.ts +25 -0
- package/dist/data/places-bennu.js +2 -0
- package/dist/data/places-callisto.d.ts +3547 -0
- package/dist/data/places-callisto.js +155 -0
- package/dist/data/places-ceres.d.ts +3436 -0
- package/dist/data/places-ceres.js +150 -0
- package/dist/data/places-charon.d.ts +349 -0
- package/dist/data/places-charon.js +16 -0
- package/dist/data/places-dimorphos.d.ts +23 -0
- package/dist/data/places-dimorphos.js +2 -0
- package/dist/data/places-dione.d.ts +2258 -0
- package/dist/data/places-dione.js +99 -0
- package/dist/data/places-enceladus.d.ts +2009 -0
- package/dist/data/places-enceladus.js +88 -0
- package/dist/data/places-eros.d.ts +26 -0
- package/dist/data/places-eros.js +2 -0
- package/dist/data/places-europa.d.ts +2977 -0
- package/dist/data/places-europa.js +130 -0
- package/dist/data/places-ganymede.d.ts +4518 -0
- package/dist/data/places-ganymede.js +197 -0
- package/dist/data/places-iapetus.d.ts +1616 -0
- package/dist/data/places-iapetus.js +71 -0
- package/dist/data/places-io.d.ts +6012 -0
- package/dist/data/places-io.js +262 -0
- package/dist/data/places-jupiter.d.ts +46 -0
- package/dist/data/places-jupiter.js +3 -0
- package/dist/data/places-mars.d.ts +20701 -0
- package/dist/data/places-mars.js +942 -0
- package/dist/data/places-mercury.d.ts +9256 -0
- package/dist/data/places-mercury.js +403 -0
- package/dist/data/places-mimas.d.ts +968 -0
- package/dist/data/places-mimas.js +43 -0
- package/dist/data/places-miranda.d.ts +419 -0
- package/dist/data/places-miranda.js +19 -0
- package/dist/data/places-moon.d.ts +18849 -0
- package/dist/data/places-moon.js +861 -0
- package/dist/data/places-oberon.d.ts +235 -0
- package/dist/data/places-oberon.js +11 -0
- package/dist/data/places-pluto.d.ts +1687 -0
- package/dist/data/places-pluto.js +74 -0
- package/dist/data/places-rhea.d.ts +3317 -0
- package/dist/data/places-rhea.js +145 -0
- package/dist/data/places-ryugu.d.ts +87 -0
- package/dist/data/places-ryugu.js +5 -0
- package/dist/data/places-saturn.d.ts +25 -0
- package/dist/data/places-saturn.js +2 -0
- package/dist/data/places-tempel-1.d.ts +25 -0
- package/dist/data/places-tempel-1.js +2 -0
- package/dist/data/places-tethys.d.ts +1222 -0
- package/dist/data/places-tethys.js +54 -0
- package/dist/data/places-titan.d.ts +7031 -0
- package/dist/data/places-titan.js +306 -0
- package/dist/data/places-titania.d.ts +418 -0
- package/dist/data/places-titania.js +19 -0
- package/dist/data/places-triton.d.ts +1457 -0
- package/dist/data/places-triton.js +64 -0
- package/dist/data/places-umbriel.d.ts +303 -0
- package/dist/data/places-umbriel.js +14 -0
- package/dist/data/places-venus.d.ts +9290 -0
- package/dist/data/places-venus.js +405 -0
- package/dist/data/places-vesta.d.ts +2444 -0
- package/dist/data/places-vesta.js +107 -0
- package/dist/data/roadster.d.ts +8 -0
- package/dist/data/roadster.js +686 -0
- package/dist/element.d.ts +10 -1
- package/dist/element.js +39 -4
- package/dist/places/67p.d.ts +13 -0
- package/dist/places/67p.js +14 -0
- package/dist/places/ariel.d.ts +13 -0
- package/dist/places/ariel.js +14 -0
- package/dist/places/bennu.d.ts +13 -0
- package/dist/places/bennu.js +14 -0
- package/dist/places/callisto.d.ts +13 -0
- package/dist/places/callisto.js +14 -0
- package/dist/places/ceres.d.ts +13 -0
- package/dist/places/ceres.js +14 -0
- package/dist/places/charon.d.ts +13 -0
- package/dist/places/charon.js +14 -0
- package/dist/places/dimorphos.d.ts +13 -0
- package/dist/places/dimorphos.js +14 -0
- package/dist/places/dione.d.ts +13 -0
- package/dist/places/dione.js +14 -0
- package/dist/places/enceladus.d.ts +13 -0
- package/dist/places/enceladus.js +14 -0
- package/dist/places/eros.d.ts +13 -0
- package/dist/places/eros.js +14 -0
- package/dist/places/europa.d.ts +13 -0
- package/dist/places/europa.js +14 -0
- package/dist/places/ganymede.d.ts +13 -0
- package/dist/places/ganymede.js +14 -0
- package/dist/places/iapetus.d.ts +13 -0
- package/dist/places/iapetus.js +14 -0
- package/dist/places/io.d.ts +13 -0
- package/dist/places/io.js +14 -0
- package/dist/places/jupiter.d.ts +13 -0
- package/dist/places/jupiter.js +14 -0
- package/dist/places/mars.d.ts +12 -0
- package/dist/places/mars.js +13 -0
- package/dist/places/mercury.d.ts +13 -0
- package/dist/places/mercury.js +14 -0
- package/dist/places/mimas.d.ts +13 -0
- package/dist/places/mimas.js +14 -0
- package/dist/places/miranda.d.ts +13 -0
- package/dist/places/miranda.js +14 -0
- package/dist/places/moon.d.ts +12 -0
- package/dist/places/moon.js +13 -0
- package/dist/places/oberon.d.ts +13 -0
- package/dist/places/oberon.js +14 -0
- package/dist/places/pluto.d.ts +13 -0
- package/dist/places/pluto.js +14 -0
- package/dist/places/rhea.d.ts +13 -0
- package/dist/places/rhea.js +14 -0
- package/dist/places/ryugu.d.ts +13 -0
- package/dist/places/ryugu.js +14 -0
- package/dist/places/saturn.d.ts +13 -0
- package/dist/places/saturn.js +14 -0
- package/dist/places/tempel-1.d.ts +13 -0
- package/dist/places/tempel-1.js +14 -0
- package/dist/places/tethys.d.ts +13 -0
- package/dist/places/tethys.js +14 -0
- package/dist/places/titan.d.ts +13 -0
- package/dist/places/titan.js +14 -0
- package/dist/places/titania.d.ts +13 -0
- package/dist/places/titania.js +14 -0
- package/dist/places/triton.d.ts +13 -0
- package/dist/places/triton.js +14 -0
- package/dist/places/umbriel.d.ts +13 -0
- package/dist/places/umbriel.js +14 -0
- package/dist/places/venus.d.ts +13 -0
- package/dist/places/venus.js +14 -0
- package/dist/places/vesta.d.ts +13 -0
- package/dist/places/vesta.js +14 -0
- package/dist/places.d.ts +354 -0
- package/dist/places.js +357 -0
- package/dist/plan/element.d.ts +52 -0
- package/dist/plan/element.js +258 -0
- package/dist/plan/index.d.ts +2 -0
- package/dist/plan/index.js +2 -0
- package/dist/plan/layout.d.ts +230 -0
- package/dist/plan/layout.js +229 -0
- package/dist/plan/svg.d.ts +125 -0
- package/dist/plan/svg.js +185 -0
- package/dist/roadster.d.ts +415 -0
- package/dist/roadster.js +496 -0
- package/dist/scene/body.d.ts +13 -2
- package/dist/scene/body.js +36 -0
- package/dist/scene/name-label.d.ts +116 -0
- package/dist/scene/name-label.js +232 -0
- package/dist/scene/painter.d.ts +30 -1
- package/dist/scene/painter.js +56 -4
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/beside.d.ts +4 -1
- package/dist/space/beside.js +47 -6
- package/dist/space/covered.d.ts +102 -0
- package/dist/space/covered.js +98 -0
- package/dist/space/element.d.ts +37 -1
- package/dist/space/element.js +151 -11
- package/dist/space/index.d.ts +1 -0
- package/dist/space/index.js +1 -0
- package/dist/space/scale.d.ts +2 -1
- package/dist/space/scale.js +13 -2
- package/dist/space/scene.d.ts +23 -1
- package/dist/space/scene.js +62 -21
- package/dist/spacecraft-facts.d.ts +4 -4
- package/dist/spacecraft-facts.js +158 -3
- package/dist/spacecraft.d.ts +69 -2
- package/dist/spacecraft.js +45 -2
- package/dist/textures/mimas-1024.webp +0 -0
- package/dist/textures/mimas-512.webp +0 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +204 -2
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
// Asteroids and distant small bodies: about a hundred from JPL's Small-Body Database, each with its orbit (osculating elements at an epoch), size, spin, colour class, the missions that visited it and the year it was found, and
|
|
2
|
+
// where it is on a date from two-body motion. The records (scripts/make-asteroids-data.py, src/data/asteroids.ts) are imported by this entry point only. Positions are heliocentric, in the J2000 ecliptic frame, in kilometres
|
|
3
|
+
// (`asteroidPosition`) or astronomical units (`asteroidPositionAu`, the unit `heliocentric` gives the planets in). The Kepler solver is the package's own. Pure: no DOM, no clock reads, no three.js.
|
|
4
|
+
import { ASTEROID_FETCHED, ASTEROID_TABLE } from "./data/asteroids.js";
|
|
5
|
+
import { toTerrestrialTime } from "./clock.js";
|
|
6
|
+
import { heliocentric, kepler } from "./ephemeris.js";
|
|
7
|
+
import { length, RAD, sub } from "./vec.js";
|
|
8
|
+
import { moment } from "./when.js";
|
|
9
|
+
const AU_KM = 149_597_870.7;
|
|
10
|
+
const LIGHT_KM_PER_SECOND = 299_792.458;
|
|
11
|
+
const DAY_MS = 86_400_000;
|
|
12
|
+
/** The Julian date of 1970-01-01 00:00. */
|
|
13
|
+
const UNIX_JD = 2_440_587.5;
|
|
14
|
+
/**
|
|
15
|
+
* The kinds, in the order of their distance from the Sun.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { ASTEROID_KINDS } from "@johnmorrisdotca/wakusei-planets/asteroids";
|
|
20
|
+
*
|
|
21
|
+
* console.log(ASTEROID_KINDS.join(", "));
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export const ASTEROID_KINDS = ["near-earth", "main-belt", "trojan", "centaur", "trans-neptunian"];
|
|
25
|
+
/**
|
|
26
|
+
* Every body in the set: about a hundred, in the order of the table (the largest main-belt asteroids, then the spacecraft's visits, the near-Earth asteroids, the trojans, the centaurs and the trans-Neptunian objects). The package's
|
|
27
|
+
* own bodies (Ceres, Pallas, Vesta, Chiron, Pholus, Halley, Pluto and the dwarf planets Orcus, Haumea, Quaoar, Makemake, Gonggong, Eris and Sedna) are not repeated here: they have their own, fuller, tables.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { ASTEROIDS } from "@johnmorrisdotca/wakusei-planets/asteroids";
|
|
32
|
+
*
|
|
33
|
+
* console.log(ASTEROIDS.length, "bodies;", ASTEROIDS.filter((a) => a.missions.length > 0).length, "visited or to be visited");
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export const ASTEROIDS = ASTEROID_TABLE;
|
|
37
|
+
/**
|
|
38
|
+
* The day the records were read from the Small-Body Database, "2026-11-11". Orbits are refined as bodies are observed, so a later read gives slightly different elements.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { ASTEROIDS_FETCHED } from "@johnmorrisdotca/wakusei-planets/asteroids";
|
|
43
|
+
*
|
|
44
|
+
* console.log("elements read from JPL on", ASTEROIDS_FETCHED);
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export const ASTEROIDS_FETCHED = ASTEROID_FETCHED;
|
|
48
|
+
/**
|
|
49
|
+
* Every body in the set, as `ASTEROIDS`.
|
|
50
|
+
*
|
|
51
|
+
* @returns The records, which must not be changed.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { asteroidList } from "@johnmorrisdotca/wakusei-planets/asteroids";
|
|
56
|
+
*
|
|
57
|
+
* console.log(asteroidList().map((a) => a.name.en).slice(0, 5).join(", "));
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export function asteroidList() {
|
|
61
|
+
return ASTEROIDS;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The bodies of one kind, and for the near-Earth asteroids, optionally of one group.
|
|
65
|
+
*
|
|
66
|
+
* @param kind - The kind.
|
|
67
|
+
* @param group - A near-Earth group (`Atira`, `Aten`, `Apollo` or `Amor`), to narrow `near-earth`.
|
|
68
|
+
* @returns The records, in table order.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { asteroidsOfKind } from "@johnmorrisdotca/wakusei-planets/asteroids";
|
|
73
|
+
*
|
|
74
|
+
* console.log(asteroidsOfKind("trojan").map((a) => a.name.en).join(", "));
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export function asteroidsOfKind(kind, group) {
|
|
78
|
+
return ASTEROIDS.filter((a) => a.kind === kind && (group === undefined || a.group === group));
|
|
79
|
+
}
|
|
80
|
+
/** A name with its accents, backticks, case and spaces taken out, so "Kamo`oalewa", "kamo‘oalewa" and "KAMOOALEWA" are one. */
|
|
81
|
+
function plain(text) {
|
|
82
|
+
return text
|
|
83
|
+
.normalize("NFKD")
|
|
84
|
+
.replace(/[̀-ͯ]/g, "")
|
|
85
|
+
.replace(/[`'‘’ʻ\s-]/g, "")
|
|
86
|
+
.toLowerCase();
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Finds a body by its id, minor-planet number, designation or name (English or Japanese, ignoring case, accents and spaces). Nothing matches a string that is not one of them.
|
|
90
|
+
*
|
|
91
|
+
* @param query - "eros", "433", 433, "A898 PA", "2024 YR4", "Šteins" or "エロス".
|
|
92
|
+
* @returns The record, or `undefined`.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { findAsteroid } from "@johnmorrisdotca/wakusei-planets/asteroids";
|
|
97
|
+
*
|
|
98
|
+
* console.log(findAsteroid(99942)?.name.en, findAsteroid("2024 yr4")?.id, findAsteroid("nothing"));
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export function findAsteroid(query) {
|
|
102
|
+
if (typeof query === "number")
|
|
103
|
+
return ASTEROIDS.find((a) => a.number === query);
|
|
104
|
+
const key = plain(query);
|
|
105
|
+
if (key === "")
|
|
106
|
+
return undefined;
|
|
107
|
+
return ASTEROIDS.find((a) => plain(a.id) === key || plain(a.name.en) === key || a.name.ja === query.trim() || plain(a.designation) === key || (a.number !== undefined && String(a.number) === key));
|
|
108
|
+
}
|
|
109
|
+
function resolve(body) {
|
|
110
|
+
if (typeof body === "string" || typeof body === "number") {
|
|
111
|
+
const found = findAsteroid(body);
|
|
112
|
+
if (found === undefined)
|
|
113
|
+
throw new RangeError(`unknown asteroid ${JSON.stringify(body)}; look one up with findAsteroid, or hand in a record made with asteroidFromElements`);
|
|
114
|
+
return found;
|
|
115
|
+
}
|
|
116
|
+
if (typeof body !== "object" || body === null || typeof body.elements?.a !== "number")
|
|
117
|
+
throw new TypeError("an asteroid must be an id, a number or a record with elements");
|
|
118
|
+
return body;
|
|
119
|
+
}
|
|
120
|
+
/** The body's position in au at a Julian date (TDB taken as terrestrial time), by Kepler's equation. */
|
|
121
|
+
function atJd(el, jd) {
|
|
122
|
+
const mean = (el.ma + el.n * (jd - el.epochJd)) * RAD;
|
|
123
|
+
const E = kepler(mean, el.e);
|
|
124
|
+
const x = el.a * (Math.cos(E) - el.e);
|
|
125
|
+
const y = el.a * Math.sqrt(1 - el.e * el.e) * Math.sin(E);
|
|
126
|
+
const [cw, sw] = [Math.cos(el.peri * RAD), Math.sin(el.peri * RAD)];
|
|
127
|
+
const [co, so] = [Math.cos(el.node * RAD), Math.sin(el.node * RAD)];
|
|
128
|
+
const [ci, si] = [Math.cos(el.i * RAD), Math.sin(el.i * RAD)];
|
|
129
|
+
const px = cw * x - sw * y;
|
|
130
|
+
const py = sw * x + cw * y;
|
|
131
|
+
return [co * px - so * ci * py, so * px + co * ci * py, si * py];
|
|
132
|
+
}
|
|
133
|
+
const jdOf = (ms) => toTerrestrialTime(ms) / DAY_MS + UNIX_JD;
|
|
134
|
+
/**
|
|
135
|
+
* Where a body is at a moment, in astronomical units from the Sun, in the J2000 ecliptic frame (the axes and unit of `heliocentric`), from its elements by Kepler's equation. The motion is two-body: no planet pulls on it, so the
|
|
136
|
+
* answer drifts from the real position the further the date is from the elements' epoch (see `ASTEROID_ACCURACY`).
|
|
137
|
+
*
|
|
138
|
+
* @param body - A body: its id, number, designation or name, or a record.
|
|
139
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
140
|
+
* @returns x, y, z in astronomical units.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* import { asteroidPositionAu } from "@johnmorrisdotca/wakusei-planets/asteroids";
|
|
145
|
+
*
|
|
146
|
+
* const [x, y, z] = asteroidPositionAu("Eros", new Date("2026-11-11T00:00:00Z"));
|
|
147
|
+
* console.log(Math.hypot(x, y, z).toFixed(3), "au from the Sun");
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
export function asteroidPositionAu(body, when) {
|
|
151
|
+
return atJd(resolve(body).elements, jdOf(moment(when)));
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The same position in kilometres, the unit `spacecraftPosition` and `roadsterPosition` use.
|
|
155
|
+
*
|
|
156
|
+
* @param body - A body: its id, number, designation or name, or a record.
|
|
157
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
158
|
+
* @returns x, y, z in kilometres.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts
|
|
162
|
+
* import { asteroidPosition } from "@johnmorrisdotca/wakusei-planets/asteroids";
|
|
163
|
+
*
|
|
164
|
+
* console.log(asteroidPosition(433, Date.UTC(2026, 10, 11)).map((km) => Math.round(km / 1e6)), "million km");
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
export function asteroidPosition(body, when) {
|
|
168
|
+
const [x, y, z] = asteroidPositionAu(body, when);
|
|
169
|
+
return [x * AU_KM, y * AU_KM, z * AU_KM];
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* The distances of a body from the Sun and the Earth at a moment.
|
|
173
|
+
*
|
|
174
|
+
* @param body - A body: its id, number, designation or name, or a record.
|
|
175
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
176
|
+
* @returns The distances.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* import { asteroidDistances } from "@johnmorrisdotca/wakusei-planets/asteroids";
|
|
181
|
+
*
|
|
182
|
+
* const d = asteroidDistances("Bennu", Date.UTC(2026, 10, 11));
|
|
183
|
+
* console.log(d.sunAu.toFixed(2), "au from the Sun,", d.earthAu.toFixed(2), "from the Earth,", d.lightMinutes.toFixed(1), "light minutes");
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
export function asteroidDistances(body, when) {
|
|
187
|
+
const ms = moment(when);
|
|
188
|
+
const au = asteroidPositionAu(body, ms);
|
|
189
|
+
const earthAu = length(sub(au, heliocentric("earth", ms)));
|
|
190
|
+
const earthKm = earthAu * AU_KM;
|
|
191
|
+
return { sunAu: length(au), earthAu, earthKm, earthLunar: earthKm / 384_400, lightMinutes: earthKm / LIGHT_KM_PER_SECOND / 60 };
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Points round a body's whole orbit, to draw its line: the ellipse of its elements, at equal steps of the eccentric anomaly (so the bends of a long orbit get more points), in astronomical units, in the J2000 ecliptic frame.
|
|
195
|
+
* The first point is repeated at the end so the line closes.
|
|
196
|
+
*
|
|
197
|
+
* @param body - A body: its id, number, designation or name, or a record.
|
|
198
|
+
* @param count - How many segments (at least 8; 180 by default).
|
|
199
|
+
* @returns `count + 1` points.
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```ts
|
|
203
|
+
* import { asteroidOrbitPoints } from "@johnmorrisdotca/wakusei-planets/asteroids";
|
|
204
|
+
*
|
|
205
|
+
* const line = asteroidOrbitPoints("Eros", 90);
|
|
206
|
+
* console.log(line.length, "points");
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
export function asteroidOrbitPoints(body, count = 180) {
|
|
210
|
+
const el = resolve(body).elements;
|
|
211
|
+
const steps = Math.max(8, Math.floor(count));
|
|
212
|
+
const [cw, sw] = [Math.cos(el.peri * RAD), Math.sin(el.peri * RAD)];
|
|
213
|
+
const [co, so] = [Math.cos(el.node * RAD), Math.sin(el.node * RAD)];
|
|
214
|
+
const [ci, si] = [Math.cos(el.i * RAD), Math.sin(el.i * RAD)];
|
|
215
|
+
const b = el.a * Math.sqrt(1 - el.e * el.e);
|
|
216
|
+
const out = [];
|
|
217
|
+
for (let k = 0; k <= steps; k += 1) {
|
|
218
|
+
const E = (2 * Math.PI * (k % steps)) / steps;
|
|
219
|
+
const x = el.a * (Math.cos(E) - el.e);
|
|
220
|
+
const y = b * Math.sin(E);
|
|
221
|
+
const px = cw * x - sw * y;
|
|
222
|
+
const py = sw * x + cw * y;
|
|
223
|
+
out.push([co * px - so * ci * py, so * px + co * ci * py, si * py]);
|
|
224
|
+
}
|
|
225
|
+
return out;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* A body's period round the Sun, in days, from its mean motion.
|
|
229
|
+
*
|
|
230
|
+
* @param body - A body: its id, number, designation or name, or a record.
|
|
231
|
+
* @returns The period in days.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* import { asteroidPeriodDays } from "@johnmorrisdotca/wakusei-planets/asteroids";
|
|
236
|
+
*
|
|
237
|
+
* console.log((asteroidPeriodDays("Eros") / 365.25).toFixed(2), "years");
|
|
238
|
+
* ```
|
|
239
|
+
*/
|
|
240
|
+
export function asteroidPeriodDays(body) {
|
|
241
|
+
return 360 / resolve(body).elements.n;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* The record of a body that is not in the set, made from its elements (the door for a body of your own): its kind and near-Earth group are worked out from the orbit by JPL's own rules for the classes (an asteroid is
|
|
245
|
+
* `near-earth` when its perihelion is under 1.3 au, `main-belt` under 4.6 au, a `trojan` at 4.6 to 5.5 au with an eccentricity under 0.3, a `centaur` to 30.1 au and `trans-neptunian` beyond). Every function of this entry point takes the record.
|
|
246
|
+
*
|
|
247
|
+
* @param name - The name, or the designation.
|
|
248
|
+
* @param elements - The orbit: `epochJd`, `a`, `e` (under 1), `i`, `node`, `peri`, `ma` and `n` (the mean motion in degrees a day; worked out from `a` when left out), with `q` worked out from `a` and `e`.
|
|
249
|
+
* @returns The record, with `source` set to "elements given by the caller".
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```ts
|
|
253
|
+
* import { asteroidFromElements, asteroidPositionAu } from "@johnmorrisdotca/wakusei-planets/asteroids";
|
|
254
|
+
*
|
|
255
|
+
* const mine = asteroidFromElements("2026 XX", { epochJd: 2461200.5, a: 1.8, e: 0.4, i: 12, node: 80, peri: 120, ma: 10 });
|
|
256
|
+
* console.log(mine.kind, mine.group, asteroidPositionAu(mine, Date.UTC(2026, 10, 11)).map((au) => au.toFixed(2)));
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
export function asteroidFromElements(name, elements) {
|
|
260
|
+
const { a, e } = elements;
|
|
261
|
+
if (!(a > 0) || !Number.isFinite(a) || !(e >= 0 && e < 1))
|
|
262
|
+
throw new RangeError("the orbit must be an ellipse: a above 0 and e from 0 to just under 1");
|
|
263
|
+
for (const key of ["epochJd", "i", "node", "peri", "ma"])
|
|
264
|
+
if (!Number.isFinite(elements[key]))
|
|
265
|
+
throw new RangeError(`the element ${key} must be a finite number`);
|
|
266
|
+
const q = elements.q ?? a * (1 - e);
|
|
267
|
+
const apo = a * (1 + e);
|
|
268
|
+
const n = elements.n ?? 360 / (Math.sqrt(a * a * a) * 365.256_363);
|
|
269
|
+
let kind;
|
|
270
|
+
let group;
|
|
271
|
+
if (q < 1.3) {
|
|
272
|
+
kind = "near-earth";
|
|
273
|
+
group = apo < 0.983 ? "Atira" : a < 1 ? "Aten" : q < 1.017 ? "Apollo" : "Amor";
|
|
274
|
+
}
|
|
275
|
+
else if (a < 4.6)
|
|
276
|
+
kind = "main-belt";
|
|
277
|
+
else if (a < 5.5 && e < 0.3)
|
|
278
|
+
kind = "trojan";
|
|
279
|
+
else if (a < 30.1)
|
|
280
|
+
kind = "centaur";
|
|
281
|
+
else
|
|
282
|
+
kind = "trans-neptunian";
|
|
283
|
+
return {
|
|
284
|
+
id: name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, ""),
|
|
285
|
+
designation: name,
|
|
286
|
+
name: { en: name, ja: name },
|
|
287
|
+
kind,
|
|
288
|
+
...(group === undefined ? {} : { group }),
|
|
289
|
+
orbitClass: "",
|
|
290
|
+
hazardous: false,
|
|
291
|
+
spkid: 0,
|
|
292
|
+
elements: { ...elements, n, q },
|
|
293
|
+
missions: [],
|
|
294
|
+
source: "elements given by the caller",
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* A body as the data door's small-body record, to draw it with the other points of `<wakusei-space>` (`readSmallBodies` and `smallBodyAt` of `/door` take it): the same orbit, in the door's field names.
|
|
299
|
+
*
|
|
300
|
+
* @param body - A body: its id, number, designation or name, or a record.
|
|
301
|
+
* @returns A `SmallBody` (without `H` where the source has none, 99 stands for "unknown").
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```ts
|
|
305
|
+
* import { smallBodyAt } from "@johnmorrisdotca/wakusei-planets/door";
|
|
306
|
+
* import { asteroidAsSmallBody, asteroidPositionAu } from "@johnmorrisdotca/wakusei-planets/asteroids";
|
|
307
|
+
*
|
|
308
|
+
* const eros = asteroidAsSmallBody("Eros");
|
|
309
|
+
* const jd = 2461200.5;
|
|
310
|
+
* console.log(smallBodyAt(eros, jd).map((au) => au.toFixed(3)), asteroidPositionAu("Eros", (jd - 2440587.5) * 86400000).map((au) => au.toFixed(3)));
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
export function asteroidAsSmallBody(body) {
|
|
314
|
+
const record = resolve(body);
|
|
315
|
+
const el = record.elements;
|
|
316
|
+
return { name: record.name?.en ?? record.designation ?? "asteroid", a: el.a, e: el.e, i: el.i, node: el.node, peri: el.peri, M0: el.ma, epoch: el.epochJd, H: record.H ?? 99 };
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* How far to trust `asteroidPosition`, stated: the elements are osculating at one epoch each and the motion is two-body, so the error grows with the time from the epoch and with the planets' pull. The worst distances, in
|
|
320
|
+
* astronomical units, between the two-body position and JPL Horizons' own (which includes the planets) at the epoch, half a year and a year either side of it, measured on the bodies of `test/data/asteroids-horizons.json`.
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```ts
|
|
324
|
+
* import { ASTEROID_ACCURACY } from "@johnmorrisdotca/wakusei-planets/asteroids";
|
|
325
|
+
*
|
|
326
|
+
* console.log(`within ${ASTEROID_ACCURACY.yearAu} au of Horizons a year from the epoch`);
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
export const ASTEROID_ACCURACY = {
|
|
330
|
+
/** The worst distance at the epoch itself, in astronomical units (the elements are exact there; this is rounding). */
|
|
331
|
+
epochAu: 1e-7,
|
|
332
|
+
/** The worst distance within half a year of the epoch, over the 16 bodies measured, in astronomical units (about 150,000 km). */
|
|
333
|
+
halfYearAu: 0.001,
|
|
334
|
+
/** The worst distance within a year of the epoch, over the same bodies, in astronomical units (about 600,000 km): the main-belt asteroids are the worst, the others stay under a quarter of it. */
|
|
335
|
+
yearAu: 0.004,
|
|
336
|
+
/** In words, what the numbers leave out. */
|
|
337
|
+
note: "Two-body motion: the planets' pull is not included, so a body that passes close to the Earth or Jupiter, and every body far from its epoch, drifts further. Positions of near-Earth asteroids a year or more from the epoch are a guide, not an ephemeris.",
|
|
338
|
+
};
|
package/dist/comets.d.ts
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { type Vec3 } from "./vec.ts";
|
|
2
|
+
import { type When } from "./when.ts";
|
|
3
|
+
export type { When } from "./when.ts";
|
|
4
|
+
/**
|
|
5
|
+
* What a comet is: `periodic` (a closed orbit of under 200 years that has come back more than once), `long-period` (a closed orbit of 200 years or more, or one open to within what the orbit fit can tell) or
|
|
6
|
+
* `interstellar` (an open orbit that comes from outside the Sun's family: 1I, 2I and 3I).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { listComets, type CometKind } from "@johnmorrisdotca/wakusei-planets/comets";
|
|
11
|
+
*
|
|
12
|
+
* const kind: CometKind = "interstellar";
|
|
13
|
+
* console.log(listComets(kind).map((comet) => comet.designation));
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export type CometKind = "periodic" | "long-period" | "interstellar";
|
|
17
|
+
/**
|
|
18
|
+
* A meteor shower a comet feeds.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { findComet } from "@johnmorrisdotca/wakusei-planets/comets";
|
|
23
|
+
*
|
|
24
|
+
* const shower = findComet("1P")!.showers[0]!;
|
|
25
|
+
* console.log(shower.code, shower.en, shower.ja);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export interface CometShower {
|
|
29
|
+
/** The shower's code in the IAU's list of meteor showers: `PER`, `LEO`, `ORI`. */
|
|
30
|
+
code: string;
|
|
31
|
+
/** The shower's name in English. */
|
|
32
|
+
en: string;
|
|
33
|
+
/** The shower's name in Japanese. */
|
|
34
|
+
ja: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A comet and its orbit.
|
|
38
|
+
*
|
|
39
|
+
* The orbit is one solution of the NASA/JPL Small-Body Database: heliocentric osculating elements at one `epoch`, in the ecliptic and equinox of J2000. Angles are in degrees, distances in astronomical units and times
|
|
40
|
+
* are Julian dates in TDB (the scale the database uses; it differs from terrestrial time by under 2 milliseconds).
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { findComet, type CometRecord } from "@johnmorrisdotca/wakusei-planets/comets";
|
|
45
|
+
*
|
|
46
|
+
* const comet: CometRecord = findComet("109P")!;
|
|
47
|
+
* console.log(comet.name.en, comet.e, comet.q, comet.periodYears);
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export interface CometRecord {
|
|
51
|
+
/** A short name for the comet in lower case with hyphens: `halley`, `hale-bopp`. The comet in `heliocentric` and the space view is `halley`; the same id names it here. */
|
|
52
|
+
id: string;
|
|
53
|
+
/** The comet's designation: `1P`, `C/1995 O1`, `2I`. */
|
|
54
|
+
designation: string;
|
|
55
|
+
/** The database's full name for it: `1P/Halley`, `C/1995 O1 (Hale-Bopp)`. */
|
|
56
|
+
fullName: string;
|
|
57
|
+
/** The name of the comet in English and in Japanese. */
|
|
58
|
+
name: {
|
|
59
|
+
en: string;
|
|
60
|
+
ja: string;
|
|
61
|
+
};
|
|
62
|
+
/** What kind of comet it is. */
|
|
63
|
+
kind: CometKind;
|
|
64
|
+
/** The eccentricity: under 1 a closed orbit, 1 a parabola, over 1 an open one. */
|
|
65
|
+
e: number;
|
|
66
|
+
/** The perihelion distance, in astronomical units. */
|
|
67
|
+
q: number;
|
|
68
|
+
/** The inclination to the ecliptic, in degrees. 90 to 180 is a backwards (retrograde) orbit. */
|
|
69
|
+
i: number;
|
|
70
|
+
/** The longitude of the ascending node, in degrees. */
|
|
71
|
+
node: number;
|
|
72
|
+
/** The argument of perihelion, in degrees. */
|
|
73
|
+
w: number;
|
|
74
|
+
/** The time of perihelion, as a Julian date in TDB. For a periodic comet it is the passage the solution was made with, not necessarily the latest. */
|
|
75
|
+
tp: number;
|
|
76
|
+
/** The epoch of the elements, as a Julian date in TDB: the moment the osculating orbit is exact for. */
|
|
77
|
+
epoch: number;
|
|
78
|
+
/** The semi-major axis in astronomical units, for a closed orbit; `null` for a parabola or an open orbit. */
|
|
79
|
+
a: number | null;
|
|
80
|
+
/** The orbital period in years (365.25 days) of the osculating ellipse; `null` for a parabola or an open orbit. */
|
|
81
|
+
periodYears: number | null;
|
|
82
|
+
/** The database's orbit condition code, 0 (best) to 9 (worst) for how well the orbit is determined, where the database gives one; `null` where it does not. */
|
|
83
|
+
condition: number | null;
|
|
84
|
+
/** How many observations the solution used. */
|
|
85
|
+
observations: number | null;
|
|
86
|
+
/** The days between the first and last observation the solution used. */
|
|
87
|
+
arcDays: number | null;
|
|
88
|
+
/** The date of the solution, `YYYY-MM-DD`. */
|
|
89
|
+
solution: string | null;
|
|
90
|
+
/** The nucleus's effective diameter in kilometres where the database has one, else `null`. */
|
|
91
|
+
nucleusKm: number | null;
|
|
92
|
+
/** The nucleus's size along its axes where the database has them, as text in kilometres (`14.9x8.2`), else `null`. */
|
|
93
|
+
nucleusExtentKm: string | null;
|
|
94
|
+
/** The meteor showers the comet feeds, where that is well established. Empty for most comets. */
|
|
95
|
+
showers: readonly CometShower[];
|
|
96
|
+
/** The number JPL gives the comet for Horizons and its other services, or `null` for a comet added with `cometFromElements`. */
|
|
97
|
+
spkid: string | null;
|
|
98
|
+
/**
|
|
99
|
+
* For a periodic comet of the set, its last and next perihelion as JPL gives them (Julian dates in TDB): JPL Horizons' osculating elements of the comet's latest apparition record at the passage nearest 2026-11-11. `lastObserved` is what JPL's orbit solution records, not whether the comet was seen: true when
|
|
100
|
+
* the solution's last observation is within 150 days of the last passage, false when the solution is older and the date is JPL's prediction from it (21P and 46P were seen at their passages of 2025 and 2024, but the solution in the record predates them). `source` names the record. Absent on any other comet.
|
|
101
|
+
*/
|
|
102
|
+
perihelion?: {
|
|
103
|
+
last: number;
|
|
104
|
+
lastObserved: boolean;
|
|
105
|
+
next: number;
|
|
106
|
+
source: string;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* How far to trust a comet's position, stated. The elements are one osculating orbit: the planets pull on a comet, and a comet's own jets push on it, so the real orbit drifts from the ellipse, a little in a year and
|
|
111
|
+
* more the further from the epoch. A comet that has not been near a planet is good to the numbers below within a year of its epoch; a long-period comet's position is good only near its epoch, and a periodic comet's
|
|
112
|
+
* period is the osculating one, which is not the mean (Halley's comes out a year off).
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* import { COMET_ACCURACY } from "@johnmorrisdotca/wakusei-planets/comets";
|
|
117
|
+
*
|
|
118
|
+
* console.log(COMET_ACCURACY.read, COMET_ACCURACY.note);
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare const COMET_ACCURACY: {
|
|
122
|
+
/** The date the elements were read from the Small-Body Database, `YYYY-MM-DD`. */
|
|
123
|
+
readonly read: "2026-11-11";
|
|
124
|
+
/** The source of the elements. */
|
|
125
|
+
readonly source: "NASA/JPL Small-Body Database, https://ssd-api.jpl.nasa.gov/sbdb.api";
|
|
126
|
+
/** The days from an epoch within which `cometTrust` says a position is inside what was measured. */
|
|
127
|
+
readonly trustedDays: 365;
|
|
128
|
+
/** In words, what the numbers leave out. */
|
|
129
|
+
readonly note: "The orbit is two-body motion on the elements of one epoch: the planets' pull and a comet's own jets move the real orbit away from it, so a position is good near the epoch and drifts away from it, by days or years later a comet's closest approach to the Sun may be off. A long-period comet is good only near its epoch; a periodic comet's last and next perihelion are JPL's own dates inside the span they cover and are repeated from the osculating period outside it. For a close look at one date use JPL Horizons.";
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* The well-known comets of the set, in the order of the table (the periodic ones by number, then the long-period ones and the interstellar ones). Give a kind to list only that kind.
|
|
133
|
+
* The comet `halley` is the same one `heliocentric("halley", ...)` draws; the table here is the plain two-body orbit of the Small-Body Database, and inside 1800 to 2200 `heliocentric` has the more exact one (see `COMET_ACCURACY`).
|
|
134
|
+
*
|
|
135
|
+
* @param kind - `periodic`, `long-period` or `interstellar`; leave it out for all.
|
|
136
|
+
* @returns A new array of the comets.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* import { listComets } from "@johnmorrisdotca/wakusei-planets/comets";
|
|
141
|
+
*
|
|
142
|
+
* console.log(listComets("periodic").map((comet) => comet.designation).join(" "));
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export declare function listComets(kind?: CometKind): CometRecord[];
|
|
146
|
+
/**
|
|
147
|
+
* The comet with an id (`halley`), a designation (`1P`, `C/1995 O1`) or an English name (`Halley`), or `undefined` when the set has none. Case does not matter.
|
|
148
|
+
*
|
|
149
|
+
* @param key - The id, designation or English name.
|
|
150
|
+
* @returns The comet, or `undefined`.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* import { findComet } from "@johnmorrisdotca/wakusei-planets/comets";
|
|
155
|
+
*
|
|
156
|
+
* const comet = findComet("c/1995 o1");
|
|
157
|
+
* console.log(comet?.name.en, comet?.name.ja);
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare function findComet(key: string): CometRecord | undefined;
|
|
161
|
+
/**
|
|
162
|
+
* Where a comet is at a moment: x, y, z in astronomical units from the Sun, in the J2000 ecliptic frame (the axes of `heliocentric`), from two-body motion on the comet's elements. Closed, parabolic and open orbits all work.
|
|
163
|
+
* A date far from the comet's epoch is accepted and answered, but the real comet is not where two-body motion puts it, see `COMET_ACCURACY` and `cometTrust`. A comet that is not in the set throws a `RangeError`, a `when`
|
|
164
|
+
* that is not a date or a finite number a `TypeError` or `RangeError`.
|
|
165
|
+
*
|
|
166
|
+
* @param comet - A comet of the set, one from `cometFromElements`, or the id, designation or name of one in the set.
|
|
167
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
168
|
+
* @returns The position in astronomical units.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* import { cometPosition } from "@johnmorrisdotca/wakusei-planets/comets";
|
|
173
|
+
*
|
|
174
|
+
* const [x, y, z] = cometPosition("67P", Date.UTC(2021, 10, 2));
|
|
175
|
+
* console.log(Math.hypot(x, y, z).toFixed(3), "au from the Sun");
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export declare function cometPosition(comet: CometRecord | string, when: When): Vec3;
|
|
179
|
+
/**
|
|
180
|
+
* How far a comet is from the Sun and from the Earth at a moment, in astronomical units (the Earth from `heliocentric`).
|
|
181
|
+
*
|
|
182
|
+
* @param comet - A comet of the set, one from `cometFromElements`, or the id, designation or name of one in the set.
|
|
183
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
184
|
+
* @returns `sunAu` and `earthAu`.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* import { cometDistance } from "@johnmorrisdotca/wakusei-planets/comets";
|
|
189
|
+
*
|
|
190
|
+
* const d = cometDistance("hale-bopp", Date.UTC(1997, 2, 22));
|
|
191
|
+
* console.log(`${d.sunAu.toFixed(2)} au from the Sun, ${d.earthAu.toFixed(2)} au from the Earth`);
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export declare function cometDistance(comet: CometRecord | string, when: When): {
|
|
195
|
+
sunAu: number;
|
|
196
|
+
earthAu: number;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* A comet's orbit as points to draw a line through: x, y, z in astronomical units from the Sun, in the J2000 ecliptic frame, three numbers a point. A closed orbit whose far end is within `maxAu` is the whole
|
|
200
|
+
* ellipse, with its first point repeated at the end so a line closes; any other orbit is the arc through perihelion from where it comes in to where it goes out, up to `maxAu` from the Sun. Points are closer
|
|
201
|
+
* together near the Sun, where the orbit bends.
|
|
202
|
+
*
|
|
203
|
+
* @param comet - A comet of the set, one from `cometFromElements`, or the id, designation or name of one in the set.
|
|
204
|
+
* @param points - How many points, from 8 (default 180).
|
|
205
|
+
* @param maxAu - The furthest distance from the Sun to draw, in astronomical units (default 40: past Neptune).
|
|
206
|
+
* @returns The points, `3 * points` numbers (one more point for a closed ellipse).
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```ts
|
|
210
|
+
* import { cometOrbit } from "@johnmorrisdotca/wakusei-planets/comets";
|
|
211
|
+
*
|
|
212
|
+
* const line = cometOrbit("halley", 120);
|
|
213
|
+
* console.log(line.length / 3, "points, the first at", line[0]!.toFixed(2), line[1]!.toFixed(2), line[2]!.toFixed(2));
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
export declare function cometOrbit(comet: CometRecord | string, points?: number, maxAu?: number): Float32Array;
|
|
217
|
+
/**
|
|
218
|
+
* The last and the next time a comet is at perihelion, relative to a moment, in milliseconds since 1970 (UTC). For a periodic comet of the set between the two dates JPL gives (`CometRecord.perihelion`: the last, observed or predicted
|
|
219
|
+
* from JPL's solution, and the next, JPL's prediction by integrating that orbit) they are those, `basis` is `"jpl"`, and `lastObserved` is what JPL's orbit solution records (an observation of the solution within 150 days of the last passage), not whether the comet was seen. Outside that span the passages are repeated from the
|
|
220
|
+
* nearest JPL date with the osculating period and `basis` is `"estimated"` (good to months for a short orbit and to a year or more for a long one). A comet of the set on a parabola or an open orbit, or on an ellipse with a period over 10,000 years (Hyakutake's is about 70,000), has one perihelion, JPL's, which is the last when
|
|
221
|
+
* it is behind and the next when it is ahead (the other is `null`: a repetition 70,000 years on would be a date in the year 99940). A comet from `cometFromElements` has the date it was given (`"elements"`) or the repetition of it (`"estimated"`).
|
|
222
|
+
*
|
|
223
|
+
* @param comet - A comet of the set, one from `cometFromElements`, or the id, designation or name of one in the set.
|
|
224
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
225
|
+
* @returns `last` and `next`, in milliseconds since 1970 (UTC), `null` where there is none; `basis`; and `lastObserved`.
|
|
226
|
+
*
|
|
227
|
+
* @example
|
|
228
|
+
* ```ts
|
|
229
|
+
* import { cometPerihelia } from "@johnmorrisdotca/wakusei-planets/comets";
|
|
230
|
+
*
|
|
231
|
+
* const { last, next, basis } = cometPerihelia("1P", Date.UTC(2026, 10, 11));
|
|
232
|
+
* console.log(new Date(last!).toISOString().slice(0, 10), new Date(next!).toISOString().slice(0, 10), basis);
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
export declare function cometPerihelia(comet: CometRecord | string, when: When): {
|
|
236
|
+
last: number | null;
|
|
237
|
+
next: number | null;
|
|
238
|
+
basis: "jpl" | "elements" | "estimated";
|
|
239
|
+
lastObserved: boolean;
|
|
240
|
+
};
|
|
241
|
+
/**
|
|
242
|
+
* How far a moment is from the comet's epoch, and whether it is inside the year around it that the position was measured against Horizons for (`COMET_ACCURACY.trustedDays`).
|
|
243
|
+
*
|
|
244
|
+
* @param comet - A comet of the set, one from `cometFromElements`, or the id, designation or name of one in the set.
|
|
245
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
246
|
+
* @returns `epoch` (milliseconds since 1970, UTC), `daysFromEpoch` (negative before it) and `withinYear`.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* import { cometTrust } from "@johnmorrisdotca/wakusei-planets/comets";
|
|
251
|
+
*
|
|
252
|
+
* const trust = cometTrust("neowise", Date.UTC(2026, 0, 1));
|
|
253
|
+
* console.log(trust.daysFromEpoch.toFixed(0), "days from the epoch;", trust.withinYear ? "near it" : "far from it: two-body motion drifts");
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
export declare function cometTrust(comet: CometRecord | string, when: When): {
|
|
257
|
+
epoch: number;
|
|
258
|
+
daysFromEpoch: number;
|
|
259
|
+
withinYear: boolean;
|
|
260
|
+
};
|
|
261
|
+
/**
|
|
262
|
+
* What a page gives to add a comet that is not in the set (a newly found one) without a release: the elements as the Minor Planet Center and JPL publish them.
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* import { cometFromElements, type CometElementsInput } from "@johnmorrisdotca/wakusei-planets/comets";
|
|
267
|
+
*
|
|
268
|
+
* const elements: CometElementsInput = { designation: "C/2099 B1", e: 1, q: 1.2, i: 80, node: 15, w: 200, tp: 2_488_000.5 };
|
|
269
|
+
* console.log(cometFromElements(elements).kind);
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
export interface CometElementsInput {
|
|
273
|
+
/** The designation: `C/2025 X1`. */
|
|
274
|
+
designation: string;
|
|
275
|
+
/** The id, lower case with hyphens; made from the designation when left out. */
|
|
276
|
+
id?: string;
|
|
277
|
+
/** The names; `ja` is left empty when not given. */
|
|
278
|
+
name?: {
|
|
279
|
+
en: string;
|
|
280
|
+
ja?: string;
|
|
281
|
+
};
|
|
282
|
+
/** The eccentricity, 0 or more (1 is a parabola). */
|
|
283
|
+
e: number;
|
|
284
|
+
/** The perihelion distance in astronomical units, more than 0. */
|
|
285
|
+
q: number;
|
|
286
|
+
/** The inclination in degrees, 0 to 180. */
|
|
287
|
+
i: number;
|
|
288
|
+
/** The longitude of the ascending node in degrees. */
|
|
289
|
+
node: number;
|
|
290
|
+
/** The argument of perihelion in degrees. */
|
|
291
|
+
w: number;
|
|
292
|
+
/** The time of perihelion as a Julian date in TDB (as JPL gives it). Give this or `perihelion`. */
|
|
293
|
+
tp?: number;
|
|
294
|
+
/** The time of perihelion as a `Date` or milliseconds since 1970 (UTC), where the date is known that way. Give this or `tp`. */
|
|
295
|
+
perihelion?: When;
|
|
296
|
+
/** The epoch of the elements as a Julian date in TDB; the time of perihelion when left out. */
|
|
297
|
+
epoch?: number;
|
|
298
|
+
/** `periodic`, `long-period` or `interstellar`; made from the orbit when left out (a closed orbit under 200 years is periodic, any other is long-period). */
|
|
299
|
+
kind?: CometKind;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* A comet made from elements a page supplies, to use with every function here, so a newly found comet needs no release. The comet is checked (a bad number throws a `TypeError` or a `RangeError` that names it) and the
|
|
303
|
+
* angles are folded into 0 to 360. Fields the elements do not give are `null` or empty.
|
|
304
|
+
*
|
|
305
|
+
* @param input - The elements.
|
|
306
|
+
* @returns The comet.
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```ts
|
|
310
|
+
* import { cometFromElements, cometPosition } from "@johnmorrisdotca/wakusei-planets/comets";
|
|
311
|
+
*
|
|
312
|
+
* const comet = cometFromElements({ designation: "C/2099 A1", e: 0.99, q: 0.8, i: 45, node: 120, w: 30, perihelion: Date.UTC(2099, 5, 1) });
|
|
313
|
+
* console.log(cometPosition(comet, Date.UTC(2099, 5, 1)).map((v) => v.toFixed(3)).join(" "));
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
export declare function cometFromElements(input: CometElementsInput): CometRecord;
|