@johnmorrisdotca/wakusei-planets 0.37.2 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/NOTICE.md +12 -1
- package/README.md +5 -3
- package/dist/belts/data.d.ts +2 -0
- package/dist/belts/data.js +12 -0
- package/dist/belts/index.d.ts +270 -0
- package/dist/belts/index.js +308 -0
- package/dist/belts/totals.d.ts +43 -0
- package/dist/belts/totals.js +25 -0
- package/dist/data/orbiters.d.ts +221 -199
- package/dist/data/orbiters.js +288 -200
- package/dist/data-door.d.ts +2 -0
- package/dist/data-door.js +4 -2
- package/dist/door/points.d.ts +14 -5
- package/dist/door/points.js +78 -27
- package/dist/earth-places.d.ts +40 -0
- package/dist/earth-places.js +47 -0
- package/dist/orbiter-facts.d.ts +61 -4
- package/dist/orbiter-facts.js +17 -3
- package/dist/orbiters.d.ts +122 -2
- package/dist/orbiters.js +205 -3
- package/dist/place-marks.d.ts +76 -0
- package/dist/place-marks.js +66 -0
- package/dist/places.d.ts +1 -1
- package/dist/places.js +1 -1
- package/dist/scene/earth-places.d.ts +190 -0
- package/dist/scene/earth-places.js +190 -0
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/element.d.ts +74 -3
- package/dist/space/element.js +293 -8
- package/dist/space/ride.d.ts +4 -4
- package/dist/space/ride.js +10 -3
- package/dist/space/scene.d.ts +44 -2
- package/dist/space/scene.js +139 -11
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +15 -2
package/dist/orbiters.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ORBITER_FITS } from "./data/orbiters.ts";
|
|
2
2
|
import { type OrbiterFacts } from "./orbiter-facts.ts";
|
|
3
3
|
import type { When } from "./when.ts";
|
|
4
|
-
import type
|
|
4
|
+
import { type Vec3 } from "./vec.ts";
|
|
5
5
|
export { ORBITER_FACTS, type OrbiterFacts, type OrbiterInstrument } from "./orbiter-facts.ts";
|
|
6
6
|
export type { When } from "./when.ts";
|
|
7
7
|
/**
|
|
@@ -66,7 +66,7 @@ export interface OrbiterElements {
|
|
|
66
66
|
/** The semi-major axis in kilometres from the body's centre. */
|
|
67
67
|
a: number;
|
|
68
68
|
e: number;
|
|
69
|
-
/** Inclination, node, argument of periapsis and mean anomaly at the epoch, in degrees
|
|
69
|
+
/** Inclination to the body's equator, node (from the ascending node of the body's equator on the Earth's J2000 equator), argument of periapsis and mean anomaly at the epoch, in degrees. */
|
|
70
70
|
i: number;
|
|
71
71
|
raan: number;
|
|
72
72
|
argp: number;
|
|
@@ -202,6 +202,36 @@ export declare function orbiterNumbers(id: OrbiterId, when: When): {
|
|
|
202
202
|
status: OrbiterStatus;
|
|
203
203
|
errorKm: number | null;
|
|
204
204
|
} | undefined;
|
|
205
|
+
/**
|
|
206
|
+
* How far a predicted path may miss Horizons, as a share of its body's mean radius, and still be drawn as a tracked one is: 2 per cent, about 35 km at the Moon and 68 km at Mars, a hair's breadth
|
|
207
|
+
* on a picture of the body.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* import { ORBITER_DIM_SHARE } from "@johnmorrisdotca/wakusei-planets/orbiters";
|
|
212
|
+
*
|
|
213
|
+
* console.log((ORBITER_DIM_SHARE * 3389.5).toFixed(0), "km at Mars");
|
|
214
|
+
* ```
|
|
215
|
+
*/
|
|
216
|
+
export declare const ORBITER_DIM_SHARE = 0.02;
|
|
217
|
+
/**
|
|
218
|
+
* Whether a page should draw an orbiter dim at a moment: a `modelled` path always (outside the fit's days, or a mean orbit only), and a `predicted` one when its worst error measured against
|
|
219
|
+
* Horizons in the days after the fit (`predictedErrorKm.max`) is more than `ORBITER_DIM_SHARE` of its body's mean radius. A `tracked` path is never dim; a craft with no path (`none`) is not drawn at all,
|
|
220
|
+
* and answers `true`.
|
|
221
|
+
*
|
|
222
|
+
* @param id - The orbiter.
|
|
223
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
224
|
+
* @returns `true` to draw it dim.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* import { orbiterDim, orbiterStatus } from "@johnmorrisdotca/wakusei-planets/orbiters";
|
|
229
|
+
*
|
|
230
|
+
* const when = Date.UTC(2026, 10, 12);
|
|
231
|
+
* console.log(orbiterStatus("hope", when), orbiterDim("hope", when), orbiterStatus("lro", when), orbiterDim("lro", when));
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
export declare function orbiterDim(id: OrbiterId, when: When): boolean;
|
|
205
235
|
/**
|
|
206
236
|
* The orbit as points round one trip, in kilometres from the body's centre, ecliptic J2000, at the moment's node and periapsis: for an orbit line.
|
|
207
237
|
*
|
|
@@ -218,6 +248,96 @@ export declare function orbiterNumbers(id: OrbiterId, when: When): {
|
|
|
218
248
|
* ```
|
|
219
249
|
*/
|
|
220
250
|
export declare function orbiterPath(id: OrbiterId, when: When, points?: number): Vec3[];
|
|
251
|
+
/**
|
|
252
|
+
* The point on the body straight below an orbiter at a moment: planetocentric latitude and east longitude in degrees (-180 to 180), from the body's IAU pole and prime meridian (the Moon's without
|
|
253
|
+
* its small wobbles, a degree or two).
|
|
254
|
+
*
|
|
255
|
+
* @param id - The orbiter.
|
|
256
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
257
|
+
* @returns The point, or `undefined` for a craft with no path.
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```ts
|
|
261
|
+
* import { orbiterGround } from "@johnmorrisdotca/wakusei-planets/orbiters";
|
|
262
|
+
*
|
|
263
|
+
* const below = orbiterGround("mro", Date.UTC(2026, 10, 12))!;
|
|
264
|
+
* console.log(below.lat.toFixed(1), below.lon.toFixed(1));
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
export declare function orbiterGround(id: OrbiterId, when: When): {
|
|
268
|
+
lat: number;
|
|
269
|
+
lon: number;
|
|
270
|
+
} | undefined;
|
|
271
|
+
/**
|
|
272
|
+
* The ground track: the points under an orbiter from one moment to another, each with its moment, for a line on a map or a globe. The body turns beneath the orbit, so each trip crosses the
|
|
273
|
+
* equator further west.
|
|
274
|
+
*
|
|
275
|
+
* @param id - The orbiter.
|
|
276
|
+
* @param from - The first moment.
|
|
277
|
+
* @param to - The last moment.
|
|
278
|
+
* @param points - How many steps between them (there are `points + 1` points).
|
|
279
|
+
* @returns The points, or an empty list for a craft with no path.
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```ts
|
|
283
|
+
* import { orbiterGroundTrack } from "@johnmorrisdotca/wakusei-planets/orbiters";
|
|
284
|
+
*
|
|
285
|
+
* const start = Date.UTC(2026, 10, 12);
|
|
286
|
+
* const track = orbiterGroundTrack("mro", start, start + 112 * 60_000, 8);
|
|
287
|
+
* console.log(track.map((p) => `${p.lat.toFixed(0)},${p.lon.toFixed(0)}`).join(" "));
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
export declare function orbiterGroundTrack(id: OrbiterId, from: When, to: When, points?: number): {
|
|
291
|
+
lat: number;
|
|
292
|
+
lon: number;
|
|
293
|
+
ms: number;
|
|
294
|
+
}[];
|
|
295
|
+
/**
|
|
296
|
+
* One pass of an orbiter over a place: when it rises above the elevation asked for, when it is highest and how high, when it sets, and where its path came from at the highest moment.
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```ts
|
|
300
|
+
* import { orbiterNextPass, type OrbiterPass } from "@johnmorrisdotca/wakusei-planets/orbiters";
|
|
301
|
+
*
|
|
302
|
+
* const pass: OrbiterPass | undefined = orbiterNextPass("mro", { lat: 18.4446, lon: 77.4508 }, Date.UTC(2026, 10, 12));
|
|
303
|
+
* console.log(pass && new Date(pass.highest).toISOString(), pass?.elevationDeg.toFixed(0));
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
export interface OrbiterPass {
|
|
307
|
+
/** Milliseconds since 1970 (UTC). `rise` is before the moment asked about when the craft was already up then. */
|
|
308
|
+
rise: number;
|
|
309
|
+
highest: number;
|
|
310
|
+
set: number;
|
|
311
|
+
/** The elevation at the highest moment, in degrees above the horizon. */
|
|
312
|
+
elevationDeg: number;
|
|
313
|
+
status: OrbiterStatus;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* The next pass of an orbiter over a place on its body: the first time from `when` it is above `minElevationDeg` as seen from there, with the moment it is highest and the moment it sets. When it is
|
|
317
|
+
* already up at `when`, that pass is the one given (its rise is earlier). Searched in steps of a hundred and twentieth of a trip up to `withinDays` ahead, then narrowed to a second.
|
|
318
|
+
*
|
|
319
|
+
* @param id - The orbiter.
|
|
320
|
+
* @param place - Planetocentric latitude and east longitude on the body, in degrees (a place from `/places` fits).
|
|
321
|
+
* @param when - Where to start looking: a `Date` or milliseconds since 1970 (UTC).
|
|
322
|
+
* @param options - `minElevationDeg` (10 by default) and `withinDays` (30: a polar orbit round the slow-turning Moon comes back over a place about every two weeks).
|
|
323
|
+
* @returns The pass, or `undefined` when there is none in that time or the craft has no path.
|
|
324
|
+
*
|
|
325
|
+
* @example
|
|
326
|
+
* ```ts
|
|
327
|
+
* import { orbiterNextPass } from "@johnmorrisdotca/wakusei-planets/orbiters";
|
|
328
|
+
*
|
|
329
|
+
* // Jezero crater, where Perseverance landed
|
|
330
|
+
* const pass = orbiterNextPass("mro", { lat: 18.4446, lon: 77.4508 }, Date.UTC(2026, 10, 12))!;
|
|
331
|
+
* console.log(new Date(pass.rise).toISOString(), pass.elevationDeg.toFixed(0), "degrees up at best,", pass.status);
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
export declare function orbiterNextPass(id: OrbiterId, place: {
|
|
335
|
+
lat: number;
|
|
336
|
+
lon: number;
|
|
337
|
+
}, when: When, options?: {
|
|
338
|
+
minElevationDeg?: number;
|
|
339
|
+
withinDays?: number;
|
|
340
|
+
}): OrbiterPass | undefined;
|
|
221
341
|
/**
|
|
222
342
|
* What is known about an orbiter: names, operator, launch, instruments, a line about it, and the state of its path.
|
|
223
343
|
*
|
package/dist/orbiters.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// equinox J2000, the same axes as `/roadster` and the ten deep-space craft; `eclipticToScene` from `/space` turns them into the space view's axes.
|
|
4
4
|
import { ORBITER_FITS } from "./data/orbiters.js";
|
|
5
5
|
import { ORBITER_FACTS } from "./orbiter-facts.js";
|
|
6
|
+
import { cross, DEG, dot, fromRaDec, toEcliptic, wrap360 } from "./vec.js";
|
|
6
7
|
export { ORBITER_FACTS } from "./orbiter-facts.js";
|
|
7
8
|
/**
|
|
8
9
|
* The orbiters the package knows: six round the Moon and seven round Mars.
|
|
@@ -161,6 +162,44 @@ export function orbiterNumbers(id, when) {
|
|
|
161
162
|
}
|
|
162
163
|
/** The mean radius of the Moon and Mars in kilometres (IAU), for heights above the surface. */
|
|
163
164
|
const MEAN_RADIUS_KM = { moon: 1737.4, mars: 3389.5 };
|
|
165
|
+
/**
|
|
166
|
+
* How far a predicted path may miss Horizons, as a share of its body's mean radius, and still be drawn as a tracked one is: 2 per cent, about 35 km at the Moon and 68 km at Mars, a hair's breadth
|
|
167
|
+
* on a picture of the body.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* import { ORBITER_DIM_SHARE } from "@johnmorrisdotca/wakusei-planets/orbiters";
|
|
172
|
+
*
|
|
173
|
+
* console.log((ORBITER_DIM_SHARE * 3389.5).toFixed(0), "km at Mars");
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
export const ORBITER_DIM_SHARE = 0.02;
|
|
177
|
+
/**
|
|
178
|
+
* Whether a page should draw an orbiter dim at a moment: a `modelled` path always (outside the fit's days, or a mean orbit only), and a `predicted` one when its worst error measured against
|
|
179
|
+
* Horizons in the days after the fit (`predictedErrorKm.max`) is more than `ORBITER_DIM_SHARE` of its body's mean radius. A `tracked` path is never dim; a craft with no path (`none`) is not drawn at all,
|
|
180
|
+
* and answers `true`.
|
|
181
|
+
*
|
|
182
|
+
* @param id - The orbiter.
|
|
183
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
184
|
+
* @returns `true` to draw it dim.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```ts
|
|
188
|
+
* import { orbiterDim, orbiterStatus } from "@johnmorrisdotca/wakusei-planets/orbiters";
|
|
189
|
+
*
|
|
190
|
+
* const when = Date.UTC(2026, 10, 12);
|
|
191
|
+
* console.log(orbiterStatus("hope", when), orbiterDim("hope", when), orbiterStatus("lro", when), orbiterDim("lro", when));
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export function orbiterDim(id, when) {
|
|
195
|
+
const status = orbiterStatus(id, when);
|
|
196
|
+
if (status === "tracked")
|
|
197
|
+
return false;
|
|
198
|
+
if (status !== "predicted")
|
|
199
|
+
return true;
|
|
200
|
+
const error = orbiterElements(id)?.predictedErrorKm?.max;
|
|
201
|
+
return error === undefined || error > ORBITER_DIM_SHARE * MEAN_RADIUS_KM[orbiterCentre(id)];
|
|
202
|
+
}
|
|
164
203
|
/**
|
|
165
204
|
* The orbit as points round one trip, in kilometres from the body's centre, ecliptic J2000, at the moment's node and periapsis: for an orbit line.
|
|
166
205
|
*
|
|
@@ -184,7 +223,7 @@ export function orbiterPath(id, when, points = 96) {
|
|
|
184
223
|
const out = [];
|
|
185
224
|
// evenly spaced in eccentric anomaly, not mean: a lopsided orbit (ARTEMIS P1, e about 0.8) is then sampled fastest where it bends least, and has no sharp corner at periapsis
|
|
186
225
|
for (let k = 0; k <= points; k += 1)
|
|
187
|
-
out.push(placeAt(elements, dt, (2 * Math.PI * k) / points));
|
|
226
|
+
out.push(toEclipticOf(id, placeAt(elements, dt, (2 * Math.PI * k) / points)));
|
|
188
227
|
return out;
|
|
189
228
|
}
|
|
190
229
|
function stateOf(id, when) {
|
|
@@ -195,10 +234,24 @@ function stateOf(id, when) {
|
|
|
195
234
|
const dt = tdbJdOf(when) - elements.epochJd;
|
|
196
235
|
const n = meanMotion(elements, centre);
|
|
197
236
|
const m = (elements.m0 + n * dt) % 360;
|
|
198
|
-
const
|
|
237
|
+
const body = placeOf(elements, centre, dt, undefined, m);
|
|
199
238
|
// the velocity from the ellipse: a small step along it in time
|
|
200
239
|
const later = placeOf(elements, centre, dt + 1 / 86_400, undefined, (elements.m0 + n * (dt + 1 / 86_400)) % 360);
|
|
201
|
-
return { position, velocity: [later[0] -
|
|
240
|
+
return { position: toEclipticOf(id, body), velocity: toEclipticOf(id, [later[0] - body[0], later[1] - body[1], later[2] - body[2]]), body };
|
|
241
|
+
}
|
|
242
|
+
/** The body's equator frame in ecliptic J2000 axes, from the pole the data file carries: x to the ascending node of the body's equator on the Earth's J2000 equator, z to the pole. */
|
|
243
|
+
const frames = new Map();
|
|
244
|
+
function toEclipticOf(id, v) {
|
|
245
|
+
const [ra, dec] = ORBITER_FITS[id].pole;
|
|
246
|
+
let frame = frames.get(id);
|
|
247
|
+
if (frame === undefined) {
|
|
248
|
+
const pole = toEcliptic(fromRaDec(ra, dec));
|
|
249
|
+
const node = toEcliptic(fromRaDec(ra + 90, 0));
|
|
250
|
+
frame = [node, cross(pole, node), pole];
|
|
251
|
+
frames.set(id, frame);
|
|
252
|
+
}
|
|
253
|
+
const [x, y, z] = frame;
|
|
254
|
+
return [v[0] * x[0] + v[1] * y[0] + v[2] * z[0], v[0] * x[1] + v[1] * y[1] + v[2] * z[1], v[0] * x[2] + v[1] * y[2] + v[2] * z[2]];
|
|
202
255
|
}
|
|
203
256
|
/** The mean motion in degrees a day: Kepler's for `a`, corrected by the fit. */
|
|
204
257
|
const meanMotion = (elements, centre) => (Math.sqrt(GM[centre] / elements.a ** 3) * 86_400) / RAD + elements.meanMotionCorrection;
|
|
@@ -227,6 +280,155 @@ function placeAt(elements, dt, ea) {
|
|
|
227
280
|
r * Math.sin(u) * Math.sin(inc),
|
|
228
281
|
];
|
|
229
282
|
}
|
|
283
|
+
const J2000_TDB_JD = 2451545.0;
|
|
284
|
+
/** The latitude and east longitude under a point of the body's equator frame at a TDB Julian date, from the IAU prime meridian the data file carries. */
|
|
285
|
+
function groundOf(id, body, jd) {
|
|
286
|
+
const [w0, rate] = ORBITER_FITS[id].prime;
|
|
287
|
+
const r = Math.hypot(body[0], body[1], body[2]);
|
|
288
|
+
const lon = wrap360(Math.atan2(body[1], body[0]) * DEG - (w0 + rate * (jd - J2000_TDB_JD)) + 180) - 180;
|
|
289
|
+
return { lat: Math.asin(body[2] / r) * DEG, lon };
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* The point on the body straight below an orbiter at a moment: planetocentric latitude and east longitude in degrees (-180 to 180), from the body's IAU pole and prime meridian (the Moon's without
|
|
293
|
+
* its small wobbles, a degree or two).
|
|
294
|
+
*
|
|
295
|
+
* @param id - The orbiter.
|
|
296
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
297
|
+
* @returns The point, or `undefined` for a craft with no path.
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```ts
|
|
301
|
+
* import { orbiterGround } from "@johnmorrisdotca/wakusei-planets/orbiters";
|
|
302
|
+
*
|
|
303
|
+
* const below = orbiterGround("mro", Date.UTC(2026, 10, 12))!;
|
|
304
|
+
* console.log(below.lat.toFixed(1), below.lon.toFixed(1));
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
export function orbiterGround(id, when) {
|
|
308
|
+
if (orbiterElements(id) === undefined)
|
|
309
|
+
return undefined;
|
|
310
|
+
return groundOf(id, stateOf(id, when).body, tdbJdOf(when));
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* The ground track: the points under an orbiter from one moment to another, each with its moment, for a line on a map or a globe. The body turns beneath the orbit, so each trip crosses the
|
|
314
|
+
* equator further west.
|
|
315
|
+
*
|
|
316
|
+
* @param id - The orbiter.
|
|
317
|
+
* @param from - The first moment.
|
|
318
|
+
* @param to - The last moment.
|
|
319
|
+
* @param points - How many steps between them (there are `points + 1` points).
|
|
320
|
+
* @returns The points, or an empty list for a craft with no path.
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```ts
|
|
324
|
+
* import { orbiterGroundTrack } from "@johnmorrisdotca/wakusei-planets/orbiters";
|
|
325
|
+
*
|
|
326
|
+
* const start = Date.UTC(2026, 10, 12);
|
|
327
|
+
* const track = orbiterGroundTrack("mro", start, start + 112 * 60_000, 8);
|
|
328
|
+
* console.log(track.map((p) => `${p.lat.toFixed(0)},${p.lon.toFixed(0)}`).join(" "));
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
export function orbiterGroundTrack(id, from, to, points = 120) {
|
|
332
|
+
if (orbiterElements(id) === undefined)
|
|
333
|
+
return [];
|
|
334
|
+
const a = msOf(from);
|
|
335
|
+
const b = msOf(to);
|
|
336
|
+
const out = [];
|
|
337
|
+
for (let k = 0; k <= points; k += 1) {
|
|
338
|
+
const ms = a + ((b - a) * k) / points;
|
|
339
|
+
out.push({ ...groundOf(id, stateOf(id, ms).body, tdbJdOf(ms)), ms });
|
|
340
|
+
}
|
|
341
|
+
return out;
|
|
342
|
+
}
|
|
343
|
+
/** The elevation of a craft above the horizon of a place on the body's mean sphere, in degrees. */
|
|
344
|
+
function elevationAt(id, site, ms) {
|
|
345
|
+
const jd = tdbJdOf(ms);
|
|
346
|
+
const body = stateOf(id, ms).body;
|
|
347
|
+
const [w0, rate] = ORBITER_FITS[id].prime;
|
|
348
|
+
const lon = (site.lon + w0 + rate * (jd - J2000_TDB_JD)) * RAD;
|
|
349
|
+
const lat = site.lat * RAD;
|
|
350
|
+
const up = [Math.cos(lat) * Math.cos(lon), Math.cos(lat) * Math.sin(lon), Math.sin(lat)];
|
|
351
|
+
const radius = MEAN_RADIUS_KM[orbiterCentre(id)];
|
|
352
|
+
const d = [body[0] - up[0] * radius, body[1] - up[1] * radius, body[2] - up[2] * radius];
|
|
353
|
+
return Math.asin(Math.max(-1, Math.min(1, dot(d, up) / Math.hypot(d[0], d[1], d[2])))) * DEG;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* The next pass of an orbiter over a place on its body: the first time from `when` it is above `minElevationDeg` as seen from there, with the moment it is highest and the moment it sets. When it is
|
|
357
|
+
* already up at `when`, that pass is the one given (its rise is earlier). Searched in steps of a hundred and twentieth of a trip up to `withinDays` ahead, then narrowed to a second.
|
|
358
|
+
*
|
|
359
|
+
* @param id - The orbiter.
|
|
360
|
+
* @param place - Planetocentric latitude and east longitude on the body, in degrees (a place from `/places` fits).
|
|
361
|
+
* @param when - Where to start looking: a `Date` or milliseconds since 1970 (UTC).
|
|
362
|
+
* @param options - `minElevationDeg` (10 by default) and `withinDays` (30: a polar orbit round the slow-turning Moon comes back over a place about every two weeks).
|
|
363
|
+
* @returns The pass, or `undefined` when there is none in that time or the craft has no path.
|
|
364
|
+
*
|
|
365
|
+
* @example
|
|
366
|
+
* ```ts
|
|
367
|
+
* import { orbiterNextPass } from "@johnmorrisdotca/wakusei-planets/orbiters";
|
|
368
|
+
*
|
|
369
|
+
* // Jezero crater, where Perseverance landed
|
|
370
|
+
* const pass = orbiterNextPass("mro", { lat: 18.4446, lon: 77.4508 }, Date.UTC(2026, 10, 12))!;
|
|
371
|
+
* console.log(new Date(pass.rise).toISOString(), pass.elevationDeg.toFixed(0), "degrees up at best,", pass.status);
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
export function orbiterNextPass(id, place, when, options = {}) {
|
|
375
|
+
const elements = orbiterElements(id);
|
|
376
|
+
if (elements === undefined)
|
|
377
|
+
return undefined;
|
|
378
|
+
const start = msOf(when);
|
|
379
|
+
const min = options.minElevationDeg ?? 10;
|
|
380
|
+
const end = start + (options.withinDays ?? 30) * 86_400_000;
|
|
381
|
+
const trip = elements.periodDays * 86_400_000;
|
|
382
|
+
const step = Math.max(10_000, trip / 120);
|
|
383
|
+
const above = (ms) => elevationAt(id, place, ms) - min;
|
|
384
|
+
// the moment between two others where the elevation crosses the limit, to a second
|
|
385
|
+
const edge = (lo, hi) => {
|
|
386
|
+
const belowAtLo = above(lo) < 0;
|
|
387
|
+
while (hi - lo > 1000) {
|
|
388
|
+
const mid = (lo + hi) / 2;
|
|
389
|
+
if (above(mid) < 0 === belowAtLo)
|
|
390
|
+
lo = mid;
|
|
391
|
+
else
|
|
392
|
+
hi = mid;
|
|
393
|
+
}
|
|
394
|
+
return Math.round((lo + hi) / 2);
|
|
395
|
+
};
|
|
396
|
+
let rise;
|
|
397
|
+
let t = start;
|
|
398
|
+
if (above(t) >= 0) {
|
|
399
|
+
// up already: back to its rise, no further than a trip
|
|
400
|
+
let back = t;
|
|
401
|
+
while (above(back - step) >= 0 && t - back < trip)
|
|
402
|
+
back -= step;
|
|
403
|
+
rise = above(back - step) < 0 ? edge(back - step, back) : back;
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
while (t < end && above(t + step) < 0)
|
|
407
|
+
t += step;
|
|
408
|
+
if (t >= end)
|
|
409
|
+
return undefined;
|
|
410
|
+
rise = edge(t, t + step);
|
|
411
|
+
t += step;
|
|
412
|
+
}
|
|
413
|
+
let set = Math.max(t, rise);
|
|
414
|
+
while (above(set + step) >= 0 && set - rise < trip)
|
|
415
|
+
set += step;
|
|
416
|
+
set = above(set + step) < 0 ? edge(set, set + step) : set;
|
|
417
|
+
// the highest moment: golden-section search between rise and set
|
|
418
|
+
let lo = rise;
|
|
419
|
+
let hi = set;
|
|
420
|
+
const g = (Math.sqrt(5) - 1) / 2;
|
|
421
|
+
while (hi - lo > 1000) {
|
|
422
|
+
const m1 = hi - g * (hi - lo);
|
|
423
|
+
const m2 = lo + g * (hi - lo);
|
|
424
|
+
if (above(m1) < above(m2))
|
|
425
|
+
lo = m1;
|
|
426
|
+
else
|
|
427
|
+
hi = m2;
|
|
428
|
+
}
|
|
429
|
+
const highest = Math.round((lo + hi) / 2);
|
|
430
|
+
return { rise, highest, set, elevationDeg: elevationAt(id, place, highest), status: orbiterStatus(id, highest) };
|
|
431
|
+
}
|
|
230
432
|
/**
|
|
231
433
|
* What is known about an orbiter: names, operator, launch, instruments, a line about it, and the state of its path.
|
|
232
434
|
*
|
package/dist/place-marks.d.ts
CHANGED
|
@@ -180,3 +180,79 @@ export declare function turnToPlace(pole: Vec3, meridian: Vec3, lat: number, lon
|
|
|
180
180
|
yaw: number;
|
|
181
181
|
tilt: number;
|
|
182
182
|
};
|
|
183
|
+
/**
|
|
184
|
+
* A point of a body's surface as one picture shows it: where it falls (CSS pixels in the view), which way straight up from the ground there points on the screen (`upX`, `upY`: a direction whose length is how much of an upright
|
|
185
|
+
* stick the reader sees, 0 looking straight down on it and 1 seeing it side on) and `facing`, the cosine between the ground's upright and the way to the camera (above 0 it faces the reader, at or below it is on the far side).
|
|
186
|
+
* The shape is chikyu-earth's `SurfacePoint`, so its `layoutPlaces` reads it as it is.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* import type { SurfaceSpot } from "@johnmorrisdotca/wakusei-planets/places";
|
|
191
|
+
*
|
|
192
|
+
* const middle: SurfaceSpot = { x: 160, y: 160, upX: 0, upY: 0, facing: 1 };
|
|
193
|
+
* console.log(middle.facing);
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
export interface SurfaceSpot {
|
|
197
|
+
x: number;
|
|
198
|
+
y: number;
|
|
199
|
+
upX: number;
|
|
200
|
+
upY: number;
|
|
201
|
+
facing: number;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* A picture of a body for places to be laid on by someone else's layout: its size and a way to find a point of its surface in it. The shape is chikyu-earth's `PlaceView`.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```ts
|
|
208
|
+
* import type { SpotView } from "@johnmorrisdotca/wakusei-planets/places";
|
|
209
|
+
*
|
|
210
|
+
* const view: SpotView = { width: 320, height: 320, radius: 100, at: (lon, lat, out) => ((out.x = 160 + lon), (out.y = 160 - lat), (out.upX = 0), (out.upY = 0), (out.facing = 1), true) };
|
|
211
|
+
* console.log(view.width);
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
export interface SpotView {
|
|
215
|
+
width: number;
|
|
216
|
+
height: number;
|
|
217
|
+
/** The body's radius in the picture, in CSS pixels. */
|
|
218
|
+
radius: number;
|
|
219
|
+
/** Find a longitude and latitude in the picture, writing it to `out`; false when it cannot be drawn. */
|
|
220
|
+
at(lon: number, lat: number, out: SurfaceSpot): boolean;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* A body as a view draws it, made into a picture places can be laid on: for each longitude and latitude, where it falls, which way is up from the ground there and whether it faces the reader. Works with the
|
|
224
|
+
* perspective of the camera (`eye`) or without it (`toward`), on the body's own ellipsoid, so a tipped, turned or flattened body is right. A point the projection cannot place gives `false`.
|
|
225
|
+
*
|
|
226
|
+
* @param view - The body as drawn.
|
|
227
|
+
* @returns The picture, for a layout such as chikyu-earth's `layoutPlaces`.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```ts
|
|
231
|
+
* import { spotView } from "@johnmorrisdotca/wakusei-planets/places";
|
|
232
|
+
*
|
|
233
|
+
* const view = spotView({ centre: [0, 0, 0], radius: 1, pole: [0, 1, 0], meridian: [0, 0, 1], scale: [1, 1, 1], toward: [0, 0, 1], project: (p) => ({ x: 160 + p[0] * 100, y: 160 - p[1] * 100 }), width: 320, height: 320, radiusPx: 100 });
|
|
234
|
+
* const spot = { x: 0, y: 0, upX: 0, upY: 0, facing: 0 };
|
|
235
|
+
* view.at(0, 0, spot);
|
|
236
|
+
* console.log(Math.round(spot.x), Math.round(spot.y), spot.facing);
|
|
237
|
+
* ```
|
|
238
|
+
*/
|
|
239
|
+
export declare function spotView(view: SurfaceView): SpotView;
|
|
240
|
+
/**
|
|
241
|
+
* The longitude and latitude, in degrees, of the point of a body's surface that lies in a direction from its centre in the scene (the Sun's, for the `sun` of a layout that dims the night), from the body's axes.
|
|
242
|
+
*
|
|
243
|
+
* @param direction - The direction from the body's centre, in the scene.
|
|
244
|
+
* @param pole - The body's north pole.
|
|
245
|
+
* @param meridian - Its longitude 0 on the equator.
|
|
246
|
+
* @returns The point, `{ lon, lat }`.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* import { pointUnder } from "@johnmorrisdotca/wakusei-planets/places";
|
|
251
|
+
*
|
|
252
|
+
* console.log(pointUnder([1, 0, 0], [0, 1, 0], [0, 0, 1])); // longitude 90 east on the equator
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
export declare function pointUnder(direction: Vec3, pole: Vec3, meridian: Vec3): {
|
|
256
|
+
lon: number;
|
|
257
|
+
lat: number;
|
|
258
|
+
};
|
package/dist/place-marks.js
CHANGED
|
@@ -192,3 +192,69 @@ export function turnToPlace(pole, meridian, lat, lon) {
|
|
|
192
192
|
const wrap = (deg) => ((((deg + 180) % 360) + 360) % 360) - 180;
|
|
193
193
|
return { yaw: wrap(yaw / RAD), tilt: tilt / RAD };
|
|
194
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* A body as a view draws it, made into a picture places can be laid on: for each longitude and latitude, where it falls, which way is up from the ground there and whether it faces the reader. Works with the
|
|
197
|
+
* perspective of the camera (`eye`) or without it (`toward`), on the body's own ellipsoid, so a tipped, turned or flattened body is right. A point the projection cannot place gives `false`.
|
|
198
|
+
*
|
|
199
|
+
* @param view - The body as drawn.
|
|
200
|
+
* @returns The picture, for a layout such as chikyu-earth's `layoutPlaces`.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
204
|
+
* import { spotView } from "@johnmorrisdotca/wakusei-planets/places";
|
|
205
|
+
*
|
|
206
|
+
* const view = spotView({ centre: [0, 0, 0], radius: 1, pole: [0, 1, 0], meridian: [0, 0, 1], scale: [1, 1, 1], toward: [0, 0, 1], project: (p) => ({ x: 160 + p[0] * 100, y: 160 - p[1] * 100 }), width: 320, height: 320, radiusPx: 100 });
|
|
207
|
+
* const spot = { x: 0, y: 0, upX: 0, upY: 0, facing: 0 };
|
|
208
|
+
* view.at(0, 0, spot);
|
|
209
|
+
* console.log(Math.round(spot.x), Math.round(spot.y), spot.facing);
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
export function spotView(view) {
|
|
213
|
+
return {
|
|
214
|
+
width: view.width,
|
|
215
|
+
height: view.height,
|
|
216
|
+
radius: view.radiusPx,
|
|
217
|
+
at(lon, lat, out) {
|
|
218
|
+
const { point, normal } = surfacePoint(view, lat, lon);
|
|
219
|
+
const sight = view.eye !== undefined ? [view.eye[0] - point[0], view.eye[1] - point[1], view.eye[2] - point[2]] : (view.toward ?? [0, 0, 1]);
|
|
220
|
+
const facing = dot(normal, sight) / (Math.hypot(sight[0], sight[1], sight[2]) || 1);
|
|
221
|
+
const foot = view.project(point);
|
|
222
|
+
if (foot === null)
|
|
223
|
+
return false;
|
|
224
|
+
// the upright is found by projecting a point a little way out along the normal: its direction on the screen, its length how much of the stick is seen side on
|
|
225
|
+
const reach = view.radius * 0.05;
|
|
226
|
+
const top = view.project([point[0] + normal[0] * reach, point[1] + normal[1] * reach, point[2] + normal[2] * reach]);
|
|
227
|
+
const dx = top === null ? 0 : top.x - foot.x;
|
|
228
|
+
const dy = top === null ? 0 : top.y - foot.y;
|
|
229
|
+
const length = Math.hypot(dx, dy);
|
|
230
|
+
const side = Math.sqrt(Math.max(0, 1 - facing * facing));
|
|
231
|
+
out.x = foot.x;
|
|
232
|
+
out.y = foot.y;
|
|
233
|
+
out.upX = length > 1e-6 ? (dx / length) * side : 0;
|
|
234
|
+
out.upY = length > 1e-6 ? (dy / length) * side : 0;
|
|
235
|
+
out.facing = facing;
|
|
236
|
+
return true;
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The longitude and latitude, in degrees, of the point of a body's surface that lies in a direction from its centre in the scene (the Sun's, for the `sun` of a layout that dims the night), from the body's axes.
|
|
242
|
+
*
|
|
243
|
+
* @param direction - The direction from the body's centre, in the scene.
|
|
244
|
+
* @param pole - The body's north pole.
|
|
245
|
+
* @param meridian - Its longitude 0 on the equator.
|
|
246
|
+
* @returns The point, `{ lon, lat }`.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```ts
|
|
250
|
+
* import { pointUnder } from "@johnmorrisdotca/wakusei-planets/places";
|
|
251
|
+
*
|
|
252
|
+
* console.log(pointUnder([1, 0, 0], [0, 1, 0], [0, 0, 1])); // longitude 90 east on the equator
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
export function pointUnder(direction, pole, meridian) {
|
|
256
|
+
const east = [pole[1] * meridian[2] - pole[2] * meridian[1], pole[2] * meridian[0] - pole[0] * meridian[2], pole[0] * meridian[1] - pole[1] * meridian[0]];
|
|
257
|
+
const len = Math.hypot(direction[0], direction[1], direction[2]) || 1;
|
|
258
|
+
const s = [direction[0] / len, direction[1] / len, direction[2] / len];
|
|
259
|
+
return { lon: Math.atan2(dot(s, east), dot(s, meridian)) / RAD, lat: Math.asin(Math.max(-1, Math.min(1, dot(s, pole)))) / RAD };
|
|
260
|
+
}
|
package/dist/places.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type BodyId } from "./facts.ts";
|
|
2
2
|
import { type When } from "./when.ts";
|
|
3
3
|
export type { When } from "./when.ts";
|
|
4
|
-
export { layerOf, MARK_RULES, PLACE_LAYERS, placeMarks, readPlaceLayers, surfacePoint, turnToPlace, type PlaceLayer, type PlaceMark, type SurfaceView } from "./place-marks.ts";
|
|
4
|
+
export { layerOf, MARK_RULES, PLACE_LAYERS, placeMarks, pointUnder, readPlaceLayers, spotView, surfacePoint, turnToPlace, type PlaceLayer, type PlaceMark, type SpotView, type SurfaceSpot, type SurfaceView } from "./place-marks.ts";
|
|
5
5
|
/**
|
|
6
6
|
* What a place is: a `crewed` landing (an Apollo lunar module), a `landing` (a lander that worked after touchdown), a `rover` that drove there, a `crash` (a craft that hit the surface and was lost, by accident or at the end of its mission), an
|
|
7
7
|
* `impact` (a craft sent to hit it on purpose), an `entry` (a probe or orbiter lost in the atmosphere of Venus, Jupiter or Saturn: no surface was reached or none is there), a `planned` landing (announced, not flown) or a named `feature` of the surface.
|
package/dist/places.js
CHANGED
|
@@ -5,7 +5,7 @@ import { apparent } from "./ephemeris.js";
|
|
|
5
5
|
import { BODIES } from "./facts.js";
|
|
6
6
|
import { cross, dot } from "./vec.js";
|
|
7
7
|
import { moment } from "./when.js";
|
|
8
|
-
export { layerOf, MARK_RULES, PLACE_LAYERS, placeMarks, readPlaceLayers, surfacePoint, turnToPlace } from "./place-marks.js";
|
|
8
|
+
export { layerOf, MARK_RULES, PLACE_LAYERS, placeMarks, pointUnder, readPlaceLayers, spotView, surfacePoint, turnToPlace } from "./place-marks.js";
|
|
9
9
|
/**
|
|
10
10
|
* The credit a page that shows places owes each source, one row for every `source.id` the tables use: the line to print, the licence or terms it rests on and the address. The lander catalogue's is a condition of its licence (CC BY 4.0: "data from GCAT (J. McDowell,
|
|
11
11
|
* planet4589.org/space/gcat)"); the others are US government works, credited as their owners ask, and the papers' coordinates are facts (each record's `source.url` names the paper).
|