@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.
Files changed (207) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/NOTICE.md +52 -0
  3. package/README.md +26 -3
  4. package/dist/approaches.d.ts +276 -0
  5. package/dist/approaches.js +255 -0
  6. package/dist/asteroids.d.ts +397 -0
  7. package/dist/asteroids.js +338 -0
  8. package/dist/comets.d.ts +316 -0
  9. package/dist/comets.js +404 -0
  10. package/dist/craft/bepicolombo.d.ts +1 -0
  11. package/dist/craft/bepicolombo.js +923 -0
  12. package/dist/craft/europaclipper.d.ts +1 -0
  13. package/dist/craft/europaclipper.js +342 -0
  14. package/dist/craft/hayabusa2.d.ts +1 -0
  15. package/dist/craft/hayabusa2.js +73 -0
  16. package/dist/craft/juice.d.ts +1 -0
  17. package/dist/craft/juice.js +40 -0
  18. package/dist/craft/lucy.d.ts +1 -0
  19. package/dist/craft/lucy.js +42 -0
  20. package/dist/craft/osirisapex.d.ts +1 -0
  21. package/dist/craft/osirisapex.js +69 -0
  22. package/dist/craft/psyche.d.ts +1 -0
  23. package/dist/craft/psyche.js +30 -0
  24. package/dist/craft/solarorbiter.d.ts +1 -0
  25. package/dist/craft/solarorbiter.js +94 -0
  26. package/dist/data/approaches.d.ts +17 -0
  27. package/dist/data/approaches.js +4192 -0
  28. package/dist/data/asteroids.d.ts +3 -0
  29. package/dist/data/asteroids.js +107 -0
  30. package/dist/data/comets.d.ts +2 -0
  31. package/dist/data/comets.js +36 -0
  32. package/dist/data/places-67p.d.ts +27 -0
  33. package/dist/data/places-67p.js +2 -0
  34. package/dist/data/places-ariel.d.ts +602 -0
  35. package/dist/data/places-ariel.js +27 -0
  36. package/dist/data/places-bennu.d.ts +25 -0
  37. package/dist/data/places-bennu.js +2 -0
  38. package/dist/data/places-callisto.d.ts +3547 -0
  39. package/dist/data/places-callisto.js +155 -0
  40. package/dist/data/places-ceres.d.ts +3436 -0
  41. package/dist/data/places-ceres.js +150 -0
  42. package/dist/data/places-charon.d.ts +349 -0
  43. package/dist/data/places-charon.js +16 -0
  44. package/dist/data/places-dimorphos.d.ts +23 -0
  45. package/dist/data/places-dimorphos.js +2 -0
  46. package/dist/data/places-dione.d.ts +2258 -0
  47. package/dist/data/places-dione.js +99 -0
  48. package/dist/data/places-enceladus.d.ts +2009 -0
  49. package/dist/data/places-enceladus.js +88 -0
  50. package/dist/data/places-eros.d.ts +26 -0
  51. package/dist/data/places-eros.js +2 -0
  52. package/dist/data/places-europa.d.ts +2977 -0
  53. package/dist/data/places-europa.js +130 -0
  54. package/dist/data/places-ganymede.d.ts +4518 -0
  55. package/dist/data/places-ganymede.js +197 -0
  56. package/dist/data/places-iapetus.d.ts +1616 -0
  57. package/dist/data/places-iapetus.js +71 -0
  58. package/dist/data/places-io.d.ts +6012 -0
  59. package/dist/data/places-io.js +262 -0
  60. package/dist/data/places-jupiter.d.ts +46 -0
  61. package/dist/data/places-jupiter.js +3 -0
  62. package/dist/data/places-mars.d.ts +20701 -0
  63. package/dist/data/places-mars.js +942 -0
  64. package/dist/data/places-mercury.d.ts +9256 -0
  65. package/dist/data/places-mercury.js +403 -0
  66. package/dist/data/places-mimas.d.ts +968 -0
  67. package/dist/data/places-mimas.js +43 -0
  68. package/dist/data/places-miranda.d.ts +419 -0
  69. package/dist/data/places-miranda.js +19 -0
  70. package/dist/data/places-moon.d.ts +18849 -0
  71. package/dist/data/places-moon.js +861 -0
  72. package/dist/data/places-oberon.d.ts +235 -0
  73. package/dist/data/places-oberon.js +11 -0
  74. package/dist/data/places-pluto.d.ts +1687 -0
  75. package/dist/data/places-pluto.js +74 -0
  76. package/dist/data/places-rhea.d.ts +3317 -0
  77. package/dist/data/places-rhea.js +145 -0
  78. package/dist/data/places-ryugu.d.ts +87 -0
  79. package/dist/data/places-ryugu.js +5 -0
  80. package/dist/data/places-saturn.d.ts +25 -0
  81. package/dist/data/places-saturn.js +2 -0
  82. package/dist/data/places-tempel-1.d.ts +25 -0
  83. package/dist/data/places-tempel-1.js +2 -0
  84. package/dist/data/places-tethys.d.ts +1222 -0
  85. package/dist/data/places-tethys.js +54 -0
  86. package/dist/data/places-titan.d.ts +7031 -0
  87. package/dist/data/places-titan.js +306 -0
  88. package/dist/data/places-titania.d.ts +418 -0
  89. package/dist/data/places-titania.js +19 -0
  90. package/dist/data/places-triton.d.ts +1457 -0
  91. package/dist/data/places-triton.js +64 -0
  92. package/dist/data/places-umbriel.d.ts +303 -0
  93. package/dist/data/places-umbriel.js +14 -0
  94. package/dist/data/places-venus.d.ts +9290 -0
  95. package/dist/data/places-venus.js +405 -0
  96. package/dist/data/places-vesta.d.ts +2444 -0
  97. package/dist/data/places-vesta.js +107 -0
  98. package/dist/data/roadster.d.ts +8 -0
  99. package/dist/data/roadster.js +686 -0
  100. package/dist/element.d.ts +10 -1
  101. package/dist/element.js +39 -4
  102. package/dist/places/67p.d.ts +13 -0
  103. package/dist/places/67p.js +14 -0
  104. package/dist/places/ariel.d.ts +13 -0
  105. package/dist/places/ariel.js +14 -0
  106. package/dist/places/bennu.d.ts +13 -0
  107. package/dist/places/bennu.js +14 -0
  108. package/dist/places/callisto.d.ts +13 -0
  109. package/dist/places/callisto.js +14 -0
  110. package/dist/places/ceres.d.ts +13 -0
  111. package/dist/places/ceres.js +14 -0
  112. package/dist/places/charon.d.ts +13 -0
  113. package/dist/places/charon.js +14 -0
  114. package/dist/places/dimorphos.d.ts +13 -0
  115. package/dist/places/dimorphos.js +14 -0
  116. package/dist/places/dione.d.ts +13 -0
  117. package/dist/places/dione.js +14 -0
  118. package/dist/places/enceladus.d.ts +13 -0
  119. package/dist/places/enceladus.js +14 -0
  120. package/dist/places/eros.d.ts +13 -0
  121. package/dist/places/eros.js +14 -0
  122. package/dist/places/europa.d.ts +13 -0
  123. package/dist/places/europa.js +14 -0
  124. package/dist/places/ganymede.d.ts +13 -0
  125. package/dist/places/ganymede.js +14 -0
  126. package/dist/places/iapetus.d.ts +13 -0
  127. package/dist/places/iapetus.js +14 -0
  128. package/dist/places/io.d.ts +13 -0
  129. package/dist/places/io.js +14 -0
  130. package/dist/places/jupiter.d.ts +13 -0
  131. package/dist/places/jupiter.js +14 -0
  132. package/dist/places/mars.d.ts +12 -0
  133. package/dist/places/mars.js +13 -0
  134. package/dist/places/mercury.d.ts +13 -0
  135. package/dist/places/mercury.js +14 -0
  136. package/dist/places/mimas.d.ts +13 -0
  137. package/dist/places/mimas.js +14 -0
  138. package/dist/places/miranda.d.ts +13 -0
  139. package/dist/places/miranda.js +14 -0
  140. package/dist/places/moon.d.ts +12 -0
  141. package/dist/places/moon.js +13 -0
  142. package/dist/places/oberon.d.ts +13 -0
  143. package/dist/places/oberon.js +14 -0
  144. package/dist/places/pluto.d.ts +13 -0
  145. package/dist/places/pluto.js +14 -0
  146. package/dist/places/rhea.d.ts +13 -0
  147. package/dist/places/rhea.js +14 -0
  148. package/dist/places/ryugu.d.ts +13 -0
  149. package/dist/places/ryugu.js +14 -0
  150. package/dist/places/saturn.d.ts +13 -0
  151. package/dist/places/saturn.js +14 -0
  152. package/dist/places/tempel-1.d.ts +13 -0
  153. package/dist/places/tempel-1.js +14 -0
  154. package/dist/places/tethys.d.ts +13 -0
  155. package/dist/places/tethys.js +14 -0
  156. package/dist/places/titan.d.ts +13 -0
  157. package/dist/places/titan.js +14 -0
  158. package/dist/places/titania.d.ts +13 -0
  159. package/dist/places/titania.js +14 -0
  160. package/dist/places/triton.d.ts +13 -0
  161. package/dist/places/triton.js +14 -0
  162. package/dist/places/umbriel.d.ts +13 -0
  163. package/dist/places/umbriel.js +14 -0
  164. package/dist/places/venus.d.ts +13 -0
  165. package/dist/places/venus.js +14 -0
  166. package/dist/places/vesta.d.ts +13 -0
  167. package/dist/places/vesta.js +14 -0
  168. package/dist/places.d.ts +354 -0
  169. package/dist/places.js +357 -0
  170. package/dist/plan/element.d.ts +52 -0
  171. package/dist/plan/element.js +258 -0
  172. package/dist/plan/index.d.ts +2 -0
  173. package/dist/plan/index.js +2 -0
  174. package/dist/plan/layout.d.ts +230 -0
  175. package/dist/plan/layout.js +229 -0
  176. package/dist/plan/svg.d.ts +125 -0
  177. package/dist/plan/svg.js +185 -0
  178. package/dist/roadster.d.ts +415 -0
  179. package/dist/roadster.js +496 -0
  180. package/dist/scene/body.d.ts +13 -2
  181. package/dist/scene/body.js +36 -0
  182. package/dist/scene/name-label.d.ts +116 -0
  183. package/dist/scene/name-label.js +232 -0
  184. package/dist/scene/painter.d.ts +30 -1
  185. package/dist/scene/painter.js +56 -4
  186. package/dist/scene/textures.d.ts +2 -2
  187. package/dist/space/beside.d.ts +4 -1
  188. package/dist/space/beside.js +47 -6
  189. package/dist/space/covered.d.ts +102 -0
  190. package/dist/space/covered.js +98 -0
  191. package/dist/space/element.d.ts +37 -1
  192. package/dist/space/element.js +151 -11
  193. package/dist/space/index.d.ts +1 -0
  194. package/dist/space/index.js +1 -0
  195. package/dist/space/scale.d.ts +2 -1
  196. package/dist/space/scale.js +13 -2
  197. package/dist/space/scene.d.ts +23 -1
  198. package/dist/space/scene.js +62 -21
  199. package/dist/spacecraft-facts.d.ts +4 -4
  200. package/dist/spacecraft-facts.js +158 -3
  201. package/dist/spacecraft.d.ts +69 -2
  202. package/dist/spacecraft.js +45 -2
  203. package/dist/textures/mimas-1024.webp +0 -0
  204. package/dist/textures/mimas-512.webp +0 -0
  205. package/dist/version.d.ts +1 -1
  206. package/dist/version.js +1 -1
  207. package/package.json +204 -2
@@ -0,0 +1,255 @@
1
+ // Close approaches of near-Earth objects to the Earth: every approach within 0.05 au from 2026-01-01 to 2036-12-31 (predictions) and the notable ones within 0.002 au (about 0.8 lunar distances) since 1900, from JPL's
2
+ // close-approach data (scripts/make-approaches-data.py, src/data/approaches.ts), imported by this entry point only. A table of the approaches and pure functions to list, filter and search them. Pure: no DOM, no clock reads
3
+ // (a function that needs "now" takes it as a parameter), no three.js.
4
+ import { APPROACH_COVERAGE, APPROACH_FETCHED, APPROACH_ROWS } from "./data/approaches.js";
5
+ import { ttMinusUtc } from "./clock.js";
6
+ import { moment } from "./when.js";
7
+ const AU_KM = 149_597_870.7;
8
+ const LUNAR_KM = 384_400;
9
+ const UNIX_JD = 2_440_587.5;
10
+ const DAY_MS = 86_400_000;
11
+ /**
12
+ * The albedos assumed when a size is worked out from the absolute magnitude H alone: 0.05 (a dark, carbon-rich body, so a larger one) and 0.25 (a bright, stony one, so a smaller one). The range is wide on purpose: for
13
+ * one H the two sizes differ by a factor of 2.2. Where JPL has a measured diameter, it is given as well, and is the better number.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { APPROACH_ALBEDO } from "@johnmorrisdotca/wakusei-planets/approaches";
18
+ *
19
+ * console.log(`sizes assume an albedo from ${APPROACH_ALBEDO.dark} (dark) to ${APPROACH_ALBEDO.bright} (bright)`);
20
+ * ```
21
+ */
22
+ export const APPROACH_ALBEDO = { dark: 0.05, bright: 0.25 };
23
+ /**
24
+ * Every approach in the table, as one list, oldest first: the approaches within 0.002 au from 1900 to the end of 2025 (`APPROACH_NOTE.coverage.close`), then those within 0.05 au from 2026 to the end of 2036 (`wide`).
25
+ *
26
+ * @returns The approaches, which must not be changed.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * import { approachList } from "@johnmorrisdotca/wakusei-planets/approaches";
31
+ *
32
+ * console.log(approachList().length, "approaches in the table");
33
+ * ```
34
+ */
35
+ export function approachList() {
36
+ return all();
37
+ }
38
+ /**
39
+ * The size range of a body from its absolute magnitude.
40
+ *
41
+ * @param H - The absolute magnitude.
42
+ * @returns The diameters in kilometres for the albedos of `APPROACH_ALBEDO`.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * import { approachSizeRange } from "@johnmorrisdotca/wakusei-planets/approaches";
47
+ *
48
+ * const { minKm, maxKm } = approachSizeRange(22);
49
+ * console.log(`H 22: ${Math.round(minKm * 1000)} to ${Math.round(maxKm * 1000)} metres`);
50
+ * ```
51
+ */
52
+ export function approachSizeRange(H) {
53
+ if (!Number.isFinite(H))
54
+ throw new RangeError(`H must be a finite number, got ${String(H)}`);
55
+ const scale = 10 ** (-H / 5);
56
+ return { minKm: (1329 / Math.sqrt(APPROACH_ALBEDO.bright)) * scale, maxKm: (1329 / Math.sqrt(APPROACH_ALBEDO.dark)) * scale };
57
+ }
58
+ /**
59
+ * What the table is and is not: the dates each part covers and how far. A reader of a table of predictions should see this note.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * import { APPROACH_NOTE } from "@johnmorrisdotca/wakusei-planets/approaches";
64
+ *
65
+ * console.log(APPROACH_NOTE.text);
66
+ * ```
67
+ */
68
+ export const APPROACH_NOTE = {
69
+ /** The day the table was fetched from JPL, "2026-11-11". */
70
+ fetched: APPROACH_FETCHED,
71
+ /** In words: these are predictions, they change as orbits are refined and as new objects are found. */
72
+ text: `These are predictions from the orbits JPL knew on ${APPROACH_FETCHED}. An approach changes as the orbit of the body is refined by new observations, and a body found after that day is not here: nearly all the small ones are found only days before they pass. The distance is between the centres of the body and the Earth; the uncertainty of the moment and the least and greatest distances are JPL's 3-sigma values. A size from the absolute magnitude assumes an albedo between 0.05 and 0.25.`,
73
+ /** The two parts of the table: `wide` (every approach within 0.05 au from 2026-01-01 to 2036-12-31) and `close` (those within 0.002 au from 1900-01-01 to 2025-12-31), each with the dates it covers and the greatest distance it holds in astronomical units. */
74
+ coverage: APPROACH_COVERAGE,
75
+ };
76
+ /** The jd of a Julian date in TDB (taken as terrestrial time) as UTC milliseconds. */
77
+ function utcOfJd(jd) {
78
+ const tt = (jd - UNIX_JD) * DAY_MS;
79
+ return tt - ttMinusUtc(tt) * 1000;
80
+ }
81
+ let memo;
82
+ function all() {
83
+ if (memo !== undefined)
84
+ return memo;
85
+ const fetched = Date.parse(`${APPROACH_FETCHED}T00:00:00Z`);
86
+ const out = APPROACH_ROWS.map((row) => {
87
+ const [des, fullName, jd, dist, distMin, distMax, vRel, sigma, H, diameter, sigmaD] = row;
88
+ const date = utcOfJd(jd);
89
+ const name = /^\d+ ([^(]+?)\s*\(/.exec(fullName)?.[1];
90
+ const one = {
91
+ designation: des,
92
+ ...(/^\d+$/.test(des) ? { number: Number(des) } : {}),
93
+ ...(name === undefined ? {} : { name }),
94
+ fullName,
95
+ date,
96
+ jdTdb: jd,
97
+ timeSigma: { minutes: Math.abs(sigma), lessThan: sigma < 0 },
98
+ distanceAu: dist,
99
+ distanceKm: dist * AU_KM,
100
+ distanceLunar: (dist * AU_KM) / LUNAR_KM,
101
+ minDistanceAu: distMin,
102
+ maxDistanceAu: distMax,
103
+ speedKmS: vRel,
104
+ H,
105
+ sizeRange: approachSizeRange(H),
106
+ ...(diameter === null ? {} : { diameterKm: diameter }),
107
+ ...(sigmaD === null ? {} : { diameterSigmaKm: sigmaD }),
108
+ predicted: date >= fetched,
109
+ };
110
+ return Object.freeze(one);
111
+ });
112
+ memo = Object.freeze(out.sort((a, b) => a.date - b.date));
113
+ return memo;
114
+ }
115
+ /** A name or number matched to a record: the designation, the number, the name (ignoring case and accents), or the full name. */
116
+ function same(a, query) {
117
+ if (typeof query === "number")
118
+ return a.number === query;
119
+ const key = query.normalize("NFKD").replace(/[̀-ͯ]/g, "").replace(/\s+/g, " ").trim().toLowerCase();
120
+ if (key === "")
121
+ return false;
122
+ const norm = (text) => text.normalize("NFKD").replace(/[̀-ͯ]/g, "").toLowerCase();
123
+ return norm(a.designation) === key || (a.name !== undefined && norm(a.name) === key) || norm(a.fullName) === key || (a.number !== undefined && String(a.number) === key);
124
+ }
125
+ /**
126
+ * The approaches between two moments, from the first (included) to the last (excluded), oldest first.
127
+ *
128
+ * @param from - A `Date` or milliseconds since 1970 (UTC).
129
+ * @param to - Another.
130
+ * @returns The approaches.
131
+ *
132
+ * @example
133
+ * ```ts
134
+ * import { approachesBetween } from "@johnmorrisdotca/wakusei-planets/approaches";
135
+ *
136
+ * for (const a of approachesBetween(Date.UTC(2029, 0, 1), Date.UTC(2030, 0, 1)).slice(0, 3)) console.log(new Date(a.date).toISOString(), a.fullName, a.distanceLunar.toFixed(1), "LD");
137
+ * ```
138
+ */
139
+ export function approachesBetween(from, to) {
140
+ const a = moment(from, "from");
141
+ const b = moment(to, "to");
142
+ return all().filter((x) => x.date >= a && x.date < b);
143
+ }
144
+ /**
145
+ * The best estimate of a body's width: the measured diameter where JPL has one, else the geometric mean of the sizes the absolute magnitude implies.
146
+ *
147
+ * @param approach - An approach.
148
+ * @returns The diameter in kilometres.
149
+ *
150
+ * @example
151
+ * ```ts
152
+ * import { approachDiameterKm, nextApproach } from "@johnmorrisdotca/wakusei-planets/approaches";
153
+ *
154
+ * const a = nextApproach("Apophis", Date.UTC(2026, 10, 11))!;
155
+ * console.log(Math.round(approachDiameterKm(a) * 1000), "metres");
156
+ * ```
157
+ */
158
+ export function approachDiameterKm(approach) {
159
+ return approach.diameterKm ?? Math.sqrt(approach.sizeRange.minKm * approach.sizeRange.maxKm);
160
+ }
161
+ /**
162
+ * The approaches that pass a filter, oldest first: by date, distance, size, object or prediction.
163
+ *
164
+ * @param filter - What must hold.
165
+ * @returns The approaches.
166
+ *
167
+ * @example
168
+ * ```ts
169
+ * import { approachesWhere } from "@johnmorrisdotca/wakusei-planets/approaches";
170
+ *
171
+ * const close = approachesWhere({ from: Date.UTC(2026, 10, 11), to: Date.UTC(2030, 0, 1), maxLunar: 1 });
172
+ * console.log(close.map((a) => `${a.fullName} ${new Date(a.date).toISOString().slice(0, 10)}`).join("; "));
173
+ * ```
174
+ */
175
+ export function approachesWhere(filter) {
176
+ const from = filter.from === undefined ? -Infinity : moment(filter.from, "from");
177
+ const to = filter.to === undefined ? Infinity : moment(filter.to, "to");
178
+ const limit = Math.min(filter.maxAu ?? Infinity, filter.maxLunar === undefined ? Infinity : (filter.maxLunar * LUNAR_KM) / AU_KM);
179
+ for (const [name, value] of [["maxAu", filter.maxAu], ["maxLunar", filter.maxLunar], ["minDiameterKm", filter.minDiameterKm], ["maxDiameterKm", filter.maxDiameterKm]]) {
180
+ if (value !== undefined && !(value >= 0))
181
+ throw new RangeError(`${name} must be a number of 0 or more, got ${String(value)}`);
182
+ }
183
+ return all().filter((a) => {
184
+ if (a.date < from || a.date >= to || a.distanceAu > limit)
185
+ return false;
186
+ if (filter.predicted !== undefined && a.predicted !== filter.predicted)
187
+ return false;
188
+ if (filter.object !== undefined && !same(a, filter.object))
189
+ return false;
190
+ if (filter.minDiameterKm !== undefined || filter.maxDiameterKm !== undefined) {
191
+ const width = approachDiameterKm(a);
192
+ if (filter.minDiameterKm !== undefined && width < filter.minDiameterKm)
193
+ return false;
194
+ if (filter.maxDiameterKm !== undefined && width > filter.maxDiameterKm)
195
+ return false;
196
+ }
197
+ return true;
198
+ });
199
+ }
200
+ /**
201
+ * The closest approaches, nearest first, among those a filter lets through (all of them with no filter).
202
+ *
203
+ * @param count - How many.
204
+ * @param filter - What must hold; the default is everything in the table.
205
+ * @returns At most `count` approaches, in order of distance.
206
+ *
207
+ * @example
208
+ * ```ts
209
+ * import { nearestApproaches } from "@johnmorrisdotca/wakusei-planets/approaches";
210
+ *
211
+ * for (const a of nearestApproaches(3, { from: Date.UTC(2026, 10, 11) })) console.log(a.fullName, new Date(a.date).toISOString().slice(0, 10), Math.round(a.distanceKm), "km");
212
+ * ```
213
+ */
214
+ export function nearestApproaches(count, filter = {}) {
215
+ if (!Number.isInteger(count) || count < 0)
216
+ throw new RangeError(`count must be a whole number of 0 or more, got ${String(count)}`);
217
+ return approachesWhere(filter)
218
+ .sort((a, b) => a.distanceAu - b.distanceAu || a.date - b.date)
219
+ .slice(0, count);
220
+ }
221
+ /**
222
+ * The next approach of a named object after a moment (that moment excluded).
223
+ *
224
+ * @param object - A number, a designation or a name ("Apophis", 99942, "2024 YR4").
225
+ * @param after - A `Date` or milliseconds since 1970 (UTC): the module reads no clock, so "now" is yours to give.
226
+ * @returns The approach, or `undefined` when the table holds none after it.
227
+ *
228
+ * @example
229
+ * ```ts
230
+ * import { nextApproach } from "@johnmorrisdotca/wakusei-planets/approaches";
231
+ *
232
+ * const a = nextApproach("Apophis", Date.UTC(2026, 10, 11));
233
+ * console.log(a === undefined ? "none" : `${new Date(a.date).toISOString()} at ${a.distanceKm.toFixed(0)} km`);
234
+ * ```
235
+ */
236
+ export function nextApproach(object, after) {
237
+ const t = moment(after, "after");
238
+ return all().find((a) => a.date > t && same(a, object));
239
+ }
240
+ /**
241
+ * Every approach of a named object in the table, oldest first.
242
+ *
243
+ * @param object - A number, a designation or a name.
244
+ * @returns The approaches.
245
+ *
246
+ * @example
247
+ * ```ts
248
+ * import { approachesOf } from "@johnmorrisdotca/wakusei-planets/approaches";
249
+ *
250
+ * console.log(approachesOf("Apophis").map((a) => new Date(a.date).toISOString().slice(0, 10)).join(", "));
251
+ * ```
252
+ */
253
+ export function approachesOf(object) {
254
+ return all().filter((a) => same(a, object));
255
+ }
@@ -0,0 +1,397 @@
1
+ import type { SmallBody } from "./door/small-bodies.ts";
2
+ import { type Vec3 } from "./vec.ts";
3
+ import { type When } from "./when.ts";
4
+ export type { When } from "./when.ts";
5
+ /**
6
+ * The five kinds of body in the set. `main-belt` is the asteroid belt between Mars and Jupiter (JPL's classes inner main belt, main belt, outer main belt and Mars-crosser), `near-earth` an orbit that comes within 1.3 au of the Sun
7
+ * (see `AsteroidGroup`), `trojan` a Jupiter trojan, `centaur` a body between Jupiter and Neptune and `trans-neptunian` one beyond Neptune.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { ASTEROID_KINDS, type AsteroidKind } from "@johnmorrisdotca/wakusei-planets/asteroids";
12
+ *
13
+ * const kind: AsteroidKind = ASTEROID_KINDS[0];
14
+ * console.log(kind);
15
+ * ```
16
+ */
17
+ export type AsteroidKind = "main-belt" | "near-earth" | "trojan" | "centaur" | "trans-neptunian";
18
+ /**
19
+ * The kinds, in the order of their distance from the Sun.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { ASTEROID_KINDS } from "@johnmorrisdotca/wakusei-planets/asteroids";
24
+ *
25
+ * console.log(ASTEROID_KINDS.join(", "));
26
+ * ```
27
+ */
28
+ export declare const ASTEROID_KINDS: readonly AsteroidKind[];
29
+ /**
30
+ * The group of a near-Earth asteroid, named for the first asteroid of its kind: `Atira` (an orbit wholly inside the Earth's), `Aten` (a year shorter than the Earth's, crossing it), `Apollo` (longer, crossing it) and `Amor` (outside it,
31
+ * coming within 1.3 au of the Sun).
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { asteroidsOfKind, type AsteroidGroup } from "@johnmorrisdotca/wakusei-planets/asteroids";
36
+ *
37
+ * const group: AsteroidGroup = "Apollo";
38
+ * console.log(asteroidsOfKind("near-earth", group).length, "Apollo asteroids");
39
+ * ```
40
+ */
41
+ export type AsteroidGroup = "Atira" | "Aten" | "Apollo" | "Amor";
42
+ /**
43
+ * The names of a body in English and Japanese.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * import { findAsteroid, type AsteroidName } from "@johnmorrisdotca/wakusei-planets/asteroids";
48
+ *
49
+ * const name: AsteroidName = findAsteroid("Eros")!.name;
50
+ * console.log(name.en, name.ja);
51
+ * ```
52
+ */
53
+ export interface AsteroidName {
54
+ /** The name in English, or the provisional designation where the body has no name yet. */
55
+ en: string;
56
+ /** The name in Japanese (the usual katakana of the name), or the designation where the body has no name yet. */
57
+ ja: string;
58
+ }
59
+ /**
60
+ * The osculating orbit of a body about the Sun at an epoch: the ellipse it would follow if only the Sun's pull acted. Ecliptic and equinox J2000.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * import { findAsteroid, type AsteroidElements } from "@johnmorrisdotca/wakusei-planets/asteroids";
65
+ *
66
+ * const orbit: AsteroidElements = findAsteroid("Eros")!.elements;
67
+ * console.log(orbit.a.toFixed(3), "au, eccentricity", orbit.e.toFixed(3));
68
+ * ```
69
+ */
70
+ export interface AsteroidElements {
71
+ /** The epoch as a Julian date in TDB (taken as terrestrial time). */
72
+ epochJd: number;
73
+ /** The semi-major axis, in astronomical units. */
74
+ a: number;
75
+ /** The eccentricity: 0 is a circle, and every body here is an ellipse (under 1). */
76
+ e: number;
77
+ /** The inclination to the ecliptic, in degrees. */
78
+ i: number;
79
+ /** The longitude of the ascending node, in degrees. */
80
+ node: number;
81
+ /** The argument of perihelion, in degrees. */
82
+ peri: number;
83
+ /** The mean anomaly at the epoch, in degrees. */
84
+ ma: number;
85
+ /** The mean motion, in degrees a day. */
86
+ n: number;
87
+ /** The perihelion distance, in astronomical units. */
88
+ q: number;
89
+ }
90
+ /**
91
+ * A spacecraft that visited or will visit a body.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * import { findAsteroid, type AsteroidMission } from "@johnmorrisdotca/wakusei-planets/asteroids";
96
+ *
97
+ * const visit: AsteroidMission = findAsteroid("Bennu")!.missions[0]!;
98
+ * console.log(visit.name, visit.year);
99
+ * ```
100
+ */
101
+ export interface AsteroidMission {
102
+ /** The mission. */
103
+ name: string;
104
+ /** The year of the flyby, rendezvous or landing, or, where `planned` is true, the year it is planned for. */
105
+ year: number;
106
+ /** True while the visit is still to come (or was planned and its outcome is not recorded here). */
107
+ planned?: boolean;
108
+ }
109
+ /**
110
+ * One body: who it is, what kind, its orbit and what is known of it. A number the source does not give is left out.
111
+ *
112
+ * @example
113
+ * ```ts
114
+ * import { findAsteroid, type AsteroidRecord } from "@johnmorrisdotca/wakusei-planets/asteroids";
115
+ *
116
+ * const ryugu: AsteroidRecord = findAsteroid("Ryugu")!;
117
+ * console.log(ryugu.name.ja, ryugu.kind, ryugu.group, ryugu.diameterKm, "km, found in", ryugu.discoveryYear);
118
+ * ```
119
+ */
120
+ export interface AsteroidRecord {
121
+ /** A slug of the name: "eros", "apophis", "2024-yr4". Unique in the set. */
122
+ id: string;
123
+ /** The minor-planet number, or `undefined` for a body not yet numbered. */
124
+ number?: number;
125
+ /** The provisional designation ("A898 PA", "2004 MN4", "2024 YR4"). */
126
+ designation: string;
127
+ /** The names. */
128
+ name: AsteroidName;
129
+ /** The kind of body. */
130
+ kind: AsteroidKind;
131
+ /** The group of a near-Earth asteroid (`kind` is `near-earth`), else `undefined`. */
132
+ group?: AsteroidGroup;
133
+ /** JPL's three-letter orbit class ("APO", "MBA", "TJN", "CEN", "TNO", "MCA"...), which says more than `kind` does. */
134
+ orbitClass: string;
135
+ /** True where JPL lists the body as a potentially hazardous asteroid (an Earth orbit crossing within 0.05 au and brighter than H = 22), as the source states it. */
136
+ hazardous: boolean;
137
+ /** JPL's SPK-ID, the number Horizons knows the body by. */
138
+ spkid: number;
139
+ /** The orbit. */
140
+ elements: AsteroidElements;
141
+ /** The absolute magnitude H: the brightness at one au from the Sun and from the observer, full phase. */
142
+ H?: number;
143
+ /** The measured diameter in kilometres, where the source gives one. */
144
+ diameterKm?: number;
145
+ /** The geometric albedo, where the source gives one. */
146
+ albedo?: number;
147
+ /** The rotation period in hours, where the source gives one. */
148
+ rotationHours?: number;
149
+ /** The spectral class (SMASS where given, else Tholen): "S", "C", "V", "Xe"... */
150
+ spectral?: string;
151
+ /** The least distance between the body's orbit and the Earth's, in astronomical units. */
152
+ moidAu?: number;
153
+ /** The number of moons known. */
154
+ satellites?: number;
155
+ /** The year of discovery. */
156
+ discoveryYear?: number;
157
+ /** The spacecraft that visited or will visit it, in date order. */
158
+ missions: readonly AsteroidMission[];
159
+ /** A line worth knowing, in English. */
160
+ note?: string;
161
+ /** Where the numbers come from. */
162
+ source: string;
163
+ }
164
+ /**
165
+ * 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
166
+ * 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.
167
+ *
168
+ * @example
169
+ * ```ts
170
+ * import { ASTEROIDS } from "@johnmorrisdotca/wakusei-planets/asteroids";
171
+ *
172
+ * console.log(ASTEROIDS.length, "bodies;", ASTEROIDS.filter((a) => a.missions.length > 0).length, "visited or to be visited");
173
+ * ```
174
+ */
175
+ export declare const ASTEROIDS: readonly AsteroidRecord[];
176
+ /**
177
+ * 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.
178
+ *
179
+ * @example
180
+ * ```ts
181
+ * import { ASTEROIDS_FETCHED } from "@johnmorrisdotca/wakusei-planets/asteroids";
182
+ *
183
+ * console.log("elements read from JPL on", ASTEROIDS_FETCHED);
184
+ * ```
185
+ */
186
+ export declare const ASTEROIDS_FETCHED: string;
187
+ /**
188
+ * Every body in the set, as `ASTEROIDS`.
189
+ *
190
+ * @returns The records, which must not be changed.
191
+ *
192
+ * @example
193
+ * ```ts
194
+ * import { asteroidList } from "@johnmorrisdotca/wakusei-planets/asteroids";
195
+ *
196
+ * console.log(asteroidList().map((a) => a.name.en).slice(0, 5).join(", "));
197
+ * ```
198
+ */
199
+ export declare function asteroidList(): readonly AsteroidRecord[];
200
+ /**
201
+ * The bodies of one kind, and for the near-Earth asteroids, optionally of one group.
202
+ *
203
+ * @param kind - The kind.
204
+ * @param group - A near-Earth group (`Atira`, `Aten`, `Apollo` or `Amor`), to narrow `near-earth`.
205
+ * @returns The records, in table order.
206
+ *
207
+ * @example
208
+ * ```ts
209
+ * import { asteroidsOfKind } from "@johnmorrisdotca/wakusei-planets/asteroids";
210
+ *
211
+ * console.log(asteroidsOfKind("trojan").map((a) => a.name.en).join(", "));
212
+ * ```
213
+ */
214
+ export declare function asteroidsOfKind(kind: AsteroidKind, group?: AsteroidGroup): readonly AsteroidRecord[];
215
+ /**
216
+ * 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.
217
+ *
218
+ * @param query - "eros", "433", 433, "A898 PA", "2024 YR4", "Šteins" or "エロス".
219
+ * @returns The record, or `undefined`.
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * import { findAsteroid } from "@johnmorrisdotca/wakusei-planets/asteroids";
224
+ *
225
+ * console.log(findAsteroid(99942)?.name.en, findAsteroid("2024 yr4")?.id, findAsteroid("nothing"));
226
+ * ```
227
+ */
228
+ export declare function findAsteroid(query: string | number): AsteroidRecord | undefined;
229
+ /**
230
+ * What the functions take for a body: its id, number, designation or name, or a record (one of `ASTEROIDS`, or one made with `asteroidFromElements`).
231
+ *
232
+ * @example
233
+ * ```ts
234
+ * import { asteroidPositionAu, findAsteroid, type AsteroidRef } from "@johnmorrisdotca/wakusei-planets/asteroids";
235
+ *
236
+ * const refs: AsteroidRef[] = ["Eros", 433, findAsteroid("Eros")!];
237
+ * console.log(refs.map((r) => asteroidPositionAu(r, Date.UTC(2026, 10, 11))[0]!.toFixed(3)).join(" "));
238
+ * ```
239
+ */
240
+ export type AsteroidRef = string | number | Pick<AsteroidRecord, "elements"> & Partial<AsteroidRecord>;
241
+ /**
242
+ * 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
243
+ * answer drifts from the real position the further the date is from the elements' epoch (see `ASTEROID_ACCURACY`).
244
+ *
245
+ * @param body - A body: its id, number, designation or name, or a record.
246
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
247
+ * @returns x, y, z in astronomical units.
248
+ *
249
+ * @example
250
+ * ```ts
251
+ * import { asteroidPositionAu } from "@johnmorrisdotca/wakusei-planets/asteroids";
252
+ *
253
+ * const [x, y, z] = asteroidPositionAu("Eros", new Date("2026-11-11T00:00:00Z"));
254
+ * console.log(Math.hypot(x, y, z).toFixed(3), "au from the Sun");
255
+ * ```
256
+ */
257
+ export declare function asteroidPositionAu(body: AsteroidRef, when: When): Vec3;
258
+ /**
259
+ * The same position in kilometres, the unit `spacecraftPosition` and `roadsterPosition` use.
260
+ *
261
+ * @param body - A body: its id, number, designation or name, or a record.
262
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
263
+ * @returns x, y, z in kilometres.
264
+ *
265
+ * @example
266
+ * ```ts
267
+ * import { asteroidPosition } from "@johnmorrisdotca/wakusei-planets/asteroids";
268
+ *
269
+ * console.log(asteroidPosition(433, Date.UTC(2026, 10, 11)).map((km) => Math.round(km / 1e6)), "million km");
270
+ * ```
271
+ */
272
+ export declare function asteroidPosition(body: AsteroidRef, when: When): Vec3;
273
+ /**
274
+ * How far a body is from the Sun and from the Earth at a moment. The Earth is the package's own (`heliocentric`), and no distance allows for the light's travel.
275
+ *
276
+ * @example
277
+ * ```ts
278
+ * import { asteroidDistances, type AsteroidDistances } from "@johnmorrisdotca/wakusei-planets/asteroids";
279
+ *
280
+ * const d: AsteroidDistances = asteroidDistances("Apophis", Date.UTC(2029, 3, 13, 21, 46));
281
+ * console.log(Math.round(d.earthKm), "km from the Earth");
282
+ * ```
283
+ */
284
+ export interface AsteroidDistances {
285
+ /** The distance from the Sun in astronomical units. */
286
+ sunAu: number;
287
+ /** The distance from the Earth's centre in astronomical units. */
288
+ earthAu: number;
289
+ /** The distance from the Earth's centre in kilometres. */
290
+ earthKm: number;
291
+ /** The same in lunar distances (384,400 km). */
292
+ earthLunar: number;
293
+ /** The one-way light time from the Earth, in minutes. */
294
+ lightMinutes: number;
295
+ }
296
+ /**
297
+ * The distances of a body from the Sun and the Earth at a moment.
298
+ *
299
+ * @param body - A body: its id, number, designation or name, or a record.
300
+ * @param when - A `Date` or milliseconds since 1970 (UTC).
301
+ * @returns The distances.
302
+ *
303
+ * @example
304
+ * ```ts
305
+ * import { asteroidDistances } from "@johnmorrisdotca/wakusei-planets/asteroids";
306
+ *
307
+ * const d = asteroidDistances("Bennu", Date.UTC(2026, 10, 11));
308
+ * console.log(d.sunAu.toFixed(2), "au from the Sun,", d.earthAu.toFixed(2), "from the Earth,", d.lightMinutes.toFixed(1), "light minutes");
309
+ * ```
310
+ */
311
+ export declare function asteroidDistances(body: AsteroidRef, when: When): AsteroidDistances;
312
+ /**
313
+ * 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.
314
+ * The first point is repeated at the end so the line closes.
315
+ *
316
+ * @param body - A body: its id, number, designation or name, or a record.
317
+ * @param count - How many segments (at least 8; 180 by default).
318
+ * @returns `count + 1` points.
319
+ *
320
+ * @example
321
+ * ```ts
322
+ * import { asteroidOrbitPoints } from "@johnmorrisdotca/wakusei-planets/asteroids";
323
+ *
324
+ * const line = asteroidOrbitPoints("Eros", 90);
325
+ * console.log(line.length, "points");
326
+ * ```
327
+ */
328
+ export declare function asteroidOrbitPoints(body: AsteroidRef, count?: number): Vec3[];
329
+ /**
330
+ * A body's period round the Sun, in days, from its mean motion.
331
+ *
332
+ * @param body - A body: its id, number, designation or name, or a record.
333
+ * @returns The period in days.
334
+ *
335
+ * @example
336
+ * ```ts
337
+ * import { asteroidPeriodDays } from "@johnmorrisdotca/wakusei-planets/asteroids";
338
+ *
339
+ * console.log((asteroidPeriodDays("Eros") / 365.25).toFixed(2), "years");
340
+ * ```
341
+ */
342
+ export declare function asteroidPeriodDays(body: AsteroidRef): number;
343
+ /**
344
+ * 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
345
+ * `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.
346
+ *
347
+ * @param name - The name, or the designation.
348
+ * @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`.
349
+ * @returns The record, with `source` set to "elements given by the caller".
350
+ *
351
+ * @example
352
+ * ```ts
353
+ * import { asteroidFromElements, asteroidPositionAu } from "@johnmorrisdotca/wakusei-planets/asteroids";
354
+ *
355
+ * const mine = asteroidFromElements("2026 XX", { epochJd: 2461200.5, a: 1.8, e: 0.4, i: 12, node: 80, peri: 120, ma: 10 });
356
+ * console.log(mine.kind, mine.group, asteroidPositionAu(mine, Date.UTC(2026, 10, 11)).map((au) => au.toFixed(2)));
357
+ * ```
358
+ */
359
+ export declare function asteroidFromElements(name: string, elements: Omit<AsteroidElements, "n" | "q"> & Partial<Pick<AsteroidElements, "n" | "q">>): AsteroidRecord;
360
+ /**
361
+ * 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.
362
+ *
363
+ * @param body - A body: its id, number, designation or name, or a record.
364
+ * @returns A `SmallBody` (without `H` where the source has none, 99 stands for "unknown").
365
+ *
366
+ * @example
367
+ * ```ts
368
+ * import { smallBodyAt } from "@johnmorrisdotca/wakusei-planets/door";
369
+ * import { asteroidAsSmallBody, asteroidPositionAu } from "@johnmorrisdotca/wakusei-planets/asteroids";
370
+ *
371
+ * const eros = asteroidAsSmallBody("Eros");
372
+ * const jd = 2461200.5;
373
+ * console.log(smallBodyAt(eros, jd).map((au) => au.toFixed(3)), asteroidPositionAu("Eros", (jd - 2440587.5) * 86400000).map((au) => au.toFixed(3)));
374
+ * ```
375
+ */
376
+ export declare function asteroidAsSmallBody(body: AsteroidRef): SmallBody;
377
+ /**
378
+ * 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
379
+ * 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`.
380
+ *
381
+ * @example
382
+ * ```ts
383
+ * import { ASTEROID_ACCURACY } from "@johnmorrisdotca/wakusei-planets/asteroids";
384
+ *
385
+ * console.log(`within ${ASTEROID_ACCURACY.yearAu} au of Horizons a year from the epoch`);
386
+ * ```
387
+ */
388
+ export declare const ASTEROID_ACCURACY: {
389
+ /** The worst distance at the epoch itself, in astronomical units (the elements are exact there; this is rounding). */
390
+ readonly epochAu: 1e-7;
391
+ /** The worst distance within half a year of the epoch, over the 16 bodies measured, in astronomical units (about 150,000 km). */
392
+ readonly halfYearAu: 0.001;
393
+ /** 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. */
394
+ readonly yearAu: 0.004;
395
+ /** In words, what the numbers leave out. */
396
+ readonly 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.";
397
+ };