@johnmorrisdotca/chikyu-earth 0.57.0 → 0.58.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.
@@ -1,6 +1,6 @@
1
1
  // SGP4 for a group of satellites, kept cheap: the whole group is run at two moments a step apart and every position in between is an interpolation, so the cost is one batch a step
2
2
  // (about once a second), never one a frame. satellite.js (MIT) does the SGP4 itself; this file never touches the screen and imports on a server.
3
- import { json2satrec, sgp4 } from "satellite.js";
3
+ import { constants, json2satrec, sgp4 } from "satellite.js";
4
4
  import { CLASS_COLOURS } from "../catalogue/kinds.js";
5
5
  import { classOfElements } from "../catalogue/orbit.js";
6
6
  import { DEFAULT_DIM_AFTER_DAYS, DEFAULT_MAX_AGE_DAYS } from "./limits.js";
@@ -27,6 +27,32 @@ const dateOf = (text) => {
27
27
  };
28
28
  /** The height, in kilometres above the mean Earth radius, below which a satellite carried far from its elements is taken to have come down: SGP4 has nothing true to say there, and it is never drawn inside the Earth. */
29
29
  const LOWEST_ESTIMATE_KM = 120;
30
+ /** How long after the hand-over to a steady orbit what is left of the gap between the two records is faded out, so the place never jumps. The gap is nothing for a low orbit and a few kilometres for a high one that carries a drag term. */
31
+ const STEADY_FADE_MS = DAY_MS;
32
+ /**
33
+ * How far the mean motion SGP4 has reached at the hand-over may be from the elements' own, as a ratio either way, for a steady orbit to be made from it. Thirty days of real drag or of an engine raising an orbit change it by a few hundredths;
34
+ * a large drag term run that long can run away to an orbit many times higher, which is the arithmetic and not the satellite, and is never held.
35
+ */
36
+ const STEADY_MOST_CHANGE = 1.25;
37
+ const DEGREES = 180 / Math.PI;
38
+ const wholeTurn = (radians) => (((radians * DEGREES) % 360) + 360) % 360;
39
+ /**
40
+ * The mean motion an element set must state (Kozai's, radians a minute) for SGP4 to start from the mean motion `nm` (Brouwer's, which is what SGP4 itself works in and gives back).
41
+ * SGP4 turns the first into the second when it starts; this is that step run backwards, and it settles in a few rounds because the difference is about a thousandth.
42
+ */
43
+ const statedMeanMotion = (nm, eccentricity, inclination) => {
44
+ const flat = 1 - eccentricity * eccentricity;
45
+ const cos = Math.cos(inclination);
46
+ const d1 = (0.75 * constants.j2 * (3 * cos * cos - 1)) / (Math.sqrt(flat) * flat);
47
+ let stated = nm;
48
+ for (let round = 0; round < 6; round += 1) {
49
+ const ak = Math.pow(constants.xke / stated, 2 / 3);
50
+ const del = d1 / (ak * ak);
51
+ const adel = ak * (1 - del * del - del * (1 / 3 + (134 * del * del) / 81));
52
+ stated = nm * (1 + d1 / (adel * adel));
53
+ }
54
+ return stated;
55
+ };
30
56
  const epochOf = (text) => Date.parse(/[zZ]|[+-]\d\d:?\d\d$/.test(text) ? text : `${text}Z`);
31
57
  /**
32
58
  * Make a group of satellites from their element sets. Each starts SGP4 once here; one that does not (bad numbers, decayed at its own epoch) is listed in `refused` and left out.
@@ -101,7 +127,6 @@ export function createSatellites(sets, options = {}) {
101
127
  }
102
128
  }
103
129
  const n = recs.length;
104
- const normal = new Float32Array(n * 3);
105
130
  const rate = new Float64Array(n);
106
131
  const classColour = new Float32Array(n * 3);
107
132
  const eccentric = [];
@@ -111,13 +136,6 @@ export function createSatellites(sets, options = {}) {
111
136
  const epoch = epochs[i];
112
137
  if (epoch > newestEpochMs)
113
138
  newestEpochMs = epoch;
114
- const iRad = (set.INCLINATION * Math.PI) / 180;
115
- const oRad = (set.RA_OF_ASC_NODE * Math.PI) / 180;
116
- const si = Math.sin(iRad);
117
- const ci = Math.cos(iRad);
118
- normal[i * 3] = Math.sin(oRad) * si;
119
- normal[i * 3 + 1] = ci;
120
- normal[i * 3 + 2] = Math.cos(oRad) * si;
121
139
  rate[i] = (set.MEAN_MOTION * 2 * Math.PI) / DAY_MS;
122
140
  if (set.ECCENTRICITY >= ECCENTRIC_FROM)
123
141
  eccentric.push(i);
@@ -145,7 +163,8 @@ export function createSatellites(sets, options = {}) {
145
163
  let propagations = 0;
146
164
  let placed = 0;
147
165
  const timing = { lastBatchMs: 0, maxBatchMs: 0 };
148
- let estimate = options.estimateFar === true;
166
+ let steady = options.estimateFar === "steady";
167
+ let estimate = steady || options.estimateFar === true;
149
168
  let estimatedCount = 0;
150
169
  /** Whether a satellite is placed at a moment: within `maxAgeDays` of its elements, or, when far moments are estimated, inside the time it was in orbit. */
151
170
  const usableAt = (i, ms) => {
@@ -156,8 +175,73 @@ export function createSatellites(sets, options = {}) {
156
175
  const isFar = (i, ms) => estimate && Math.abs(ms - epochs[i]) > maxAgeMs;
157
176
  /** A carried-far position that is down in the air or inside the Earth is no estimate (Earth radii). */
158
177
  const tooLow = (x, y, z) => Math.hypot(x, y, z) < 1 + LOWEST_ESTIMATE_KM / EARTH_RADIUS_KM;
178
+ // each satellite's steady orbit after and before its elements, made the first time it is asked for (null: it cannot be made)
179
+ const steadyAfter = [];
180
+ const steadyBefore = [];
181
+ /**
182
+ * The orbit satellite `i` keeps beyond `maxAgeDays` with the drag off. It starts at that day from the mean elements SGP4 itself has reached there, so the two records give the same place at the hand-over
183
+ * (far under a millimetre for a low orbit; a high orbit starts its Sun and Moon terms again, which leaves a few kilometres, faded out over `STEADY_FADE_MS`).
184
+ * Elements with no drag term are already steady and are used as they are. Null when the elements cannot be carried to that day, or have run away by then (`STEADY_MOST_CHANGE`).
185
+ */
186
+ const makeSteady = (i, after) => {
187
+ const rec = recs[i];
188
+ const epoch = epochs[i];
189
+ if (rec.bstar === 0)
190
+ return { rec, startMs: epoch, dx: 0, dy: 0, dz: 0 };
191
+ const startMs = Math.round(epoch + (after ? maxAgeMs : -maxAgeMs));
192
+ const last = sgp4(rec, (startMs - epoch) / 60_000);
193
+ if (!last || !last.position || !Number.isFinite(last.position.x))
194
+ return null;
195
+ const mean = last.meanElements;
196
+ const change = mean.nm / rec.no;
197
+ if (!(change <= STEADY_MOST_CHANGE && change >= 1 / STEADY_MOST_CHANGE))
198
+ return null;
199
+ try {
200
+ const held = json2satrec({
201
+ ...usable[i],
202
+ EPOCH: new Date(startMs).toISOString(),
203
+ MEAN_MOTION: statedMeanMotion(mean.nm, mean.em, mean.im) * constants.xpdotp,
204
+ ECCENTRICITY: mean.em,
205
+ INCLINATION: mean.im * DEGREES,
206
+ RA_OF_ASC_NODE: wholeTurn(mean.Om),
207
+ ARG_OF_PERICENTER: wholeTurn(mean.om),
208
+ MEAN_ANOMALY: wholeTurn(mean.mm),
209
+ BSTAR: 0,
210
+ MEAN_MOTION_DOT: 0,
211
+ MEAN_MOTION_DDOT: 0,
212
+ });
213
+ const first = sgp4(held, 0);
214
+ if (!first || !first.position || held.error !== 0 || !Number.isFinite(first.position.x))
215
+ return null;
216
+ return { rec: held, startMs, dx: last.position.x - first.position.x, dy: last.position.y - first.position.y, dz: last.position.z - first.position.z };
217
+ }
218
+ catch {
219
+ return null;
220
+ }
221
+ };
222
+ /** SGP4 for satellite `i` at one moment: from its elements, or, beyond `maxAgeDays` with `estimateFar: "steady"`, from its steady orbit. Null, or no position, when it cannot be placed. */
223
+ const carried = (i, ms) => {
224
+ const away = ms - epochs[i];
225
+ if (!steady || Math.abs(away) <= maxAgeMs)
226
+ return sgp4(recs[i], away / 60_000);
227
+ const made = away > 0 ? steadyAfter : steadyBefore;
228
+ const held = made[i] === undefined ? (made[i] = makeSteady(i, away > 0)) : made[i];
229
+ if (held === null)
230
+ return null;
231
+ const result = sgp4(held.rec, (ms - held.startMs) / 60_000);
232
+ const fade = 1 - Math.abs(ms - held.startMs) / STEADY_FADE_MS;
233
+ if (fade > 0 && result && result.position) {
234
+ result.position.x += held.dx * fade;
235
+ result.position.y += held.dy * fade;
236
+ result.position.z += held.dz * fade;
237
+ }
238
+ return result;
239
+ };
159
240
  const pinned = new Float32Array(n * 3);
160
241
  const pinOk = new Uint8Array(n);
242
+ // the unit normal of the orbit plane at each satellite's pin, from the pinned place and SGP4's velocity there (the plane of the moment pinned, not the plane of the elements: a low orbit's plane turns about 5 degrees a day).
243
+ // Worked out once for each pin, in `sample`, and only read by `arc`.
244
+ const pinNormal = new Float32Array(n * 3);
161
245
  // when each satellite was last pinned (NaN: never), so a group can be pinned a slice at a time and `arc` turns each from its own pin
162
246
  const pinMsOf = new Float64Array(n).fill(Number.NaN);
163
247
  let pinnedCount = 0;
@@ -176,19 +260,18 @@ export function createSatellites(sets, options = {}) {
176
260
  for (const i of eccentric)
177
261
  isEccentric[i] = 1;
178
262
  /** SGP4 for satellites `from` up to (not including) `to` at one moment (the whole group by default), into `buffer` in the space view's axes (TEME x, z, -y: x to the vernal equinox, y north). */
179
- const sample = (buffer, ok, ms, from = 0, to = n, skipEccentric = false) => {
263
+ const sample = (buffer, ok, ms, from = 0, to = n, skipEccentric = false, axis) => {
180
264
  const started = performance.now();
181
265
  for (let i = from; i < to; i += 1) {
182
266
  // an eccentric orbit is placed by SGP4 at every frame by `arc` and never read from a pin
183
267
  if (skipEccentric && isEccentric[i] === 1)
184
268
  continue;
185
- const epoch = epochs[i];
186
269
  if (!usableAt(i, ms)) {
187
270
  ok[i] = 0;
188
271
  continue;
189
272
  }
190
273
  propagations += 1;
191
- const result = sgp4(recs[i], (ms - epoch) / 60_000);
274
+ const result = carried(i, ms);
192
275
  const p = result && result.position;
193
276
  if (!p || !Number.isFinite(p.x) || (isFar(i, ms) && tooLow(p.x / EARTH_RADIUS_KM, p.y / EARTH_RADIUS_KM, p.z / EARTH_RADIUS_KM))) {
194
277
  ok[i] = 0;
@@ -198,17 +281,41 @@ export function createSatellites(sets, options = {}) {
198
281
  buffer[i * 3] = p.x / EARTH_RADIUS_KM;
199
282
  buffer[i * 3 + 1] = p.z / EARTH_RADIUS_KM;
200
283
  buffer[i * 3 + 2] = -p.y / EARTH_RADIUS_KM;
284
+ if (axis) {
285
+ // the orbit's normal is the place crossed with the velocity (both in the scene's axes: x, z, -y)
286
+ const v = result.velocity;
287
+ if (!v) {
288
+ ok[i] = 0;
289
+ continue;
290
+ }
291
+ const rx = p.x;
292
+ const ry = p.z;
293
+ const rz = -p.y;
294
+ const vx = v.x;
295
+ const vy = v.z;
296
+ const vz = -v.y;
297
+ const cx = ry * vz - rz * vy;
298
+ const cy = rz * vx - rx * vz;
299
+ const cz = rx * vy - ry * vx;
300
+ const length = Math.hypot(cx, cy, cz);
301
+ if (!(length > 0)) {
302
+ ok[i] = 0;
303
+ continue;
304
+ }
305
+ axis[i * 3] = cx / length;
306
+ axis[i * 3 + 1] = cy / length;
307
+ axis[i * 3 + 2] = cz / length;
308
+ }
201
309
  }
202
310
  timing.lastBatchMs = performance.now() - started;
203
311
  if (timing.lastBatchMs > timing.maxBatchMs)
204
312
  timing.maxBatchMs = timing.lastBatchMs;
205
313
  };
206
314
  const exactAt = (index, ms, out) => {
207
- const epoch = epochs[index];
208
- if (epoch === undefined || !usableAt(index, ms))
315
+ if (epochs[index] === undefined || !usableAt(index, ms))
209
316
  return false;
210
317
  propagations += 1;
211
- const result = sgp4(recs[index], (ms - epoch) / 60_000);
318
+ const result = carried(index, ms);
212
319
  if (!result || !result.position || !result.velocity || !Number.isFinite(result.position.x))
213
320
  return false;
214
321
  if (isFar(index, ms) && tooLow(result.position.x / EARTH_RADIUS_KM, result.position.y / EARTH_RADIUS_KM, result.position.z / EARTH_RADIUS_KM))
@@ -244,12 +351,13 @@ export function createSatellites(sets, options = {}) {
244
351
  return fastest;
245
352
  },
246
353
  get estimateFar() {
247
- return estimate;
354
+ return steady ? "steady" : estimate;
248
355
  },
249
356
  set estimateFar(value) {
250
- if (value === estimate)
357
+ if (value === (steady ? "steady" : estimate))
251
358
  return;
252
- estimate = value;
359
+ steady = value === "steady";
360
+ estimate = steady || value === true;
253
361
  // what was placed was placed under the other rule: place everything again, and draw each satellite's look again
254
362
  ready = false;
255
363
  pinnedCount = 0;
@@ -268,7 +376,7 @@ export function createSatellites(sets, options = {}) {
268
376
  const to = Math.max(from, Math.min(n, from + Math.floor(count)));
269
377
  if (to === from)
270
378
  return;
271
- sample(pinned, pinOk, ms, from, to, true);
379
+ sample(pinned, pinOk, ms, from, to, true, pinNormal);
272
380
  for (let i = from; i < to; i += 1) {
273
381
  if (Number.isNaN(pinMsOf[i]))
274
382
  pinnedCount += 1;
@@ -282,7 +390,7 @@ export function createSatellites(sets, options = {}) {
282
390
  const cap = maxLength > 0 && Number.isFinite(maxLength) ? maxLength : 0;
283
391
  // a satellite never pinned is pinned now, all together
284
392
  if (pinnedCount < n) {
285
- sample(pinned, pinOk, ms, 0, n, true);
393
+ sample(pinned, pinOk, ms, 0, n, true, pinNormal);
286
394
  pinMsOf.fill(ms);
287
395
  pinnedCount = n;
288
396
  }
@@ -336,9 +444,9 @@ export function createSatellites(sets, options = {}) {
336
444
  shown[i] = 0;
337
445
  continue;
338
446
  }
339
- const nx = normal[k];
340
- const ny = normal[k + 1];
341
- const nz = normal[k + 2];
447
+ const nx = pinNormal[k];
448
+ const ny = pinNormal[k + 1];
449
+ const nz = pinNormal[k + 2];
342
450
  let sweep = Math.max(-Math.PI, Math.min(Math.PI, rate[i] * span));
343
451
  if (cap > 0) {
344
452
  // along the orbit a turn of `sweep` is `sweep` times the height in Earth radii, so the cap is a turn of cap / height
@@ -80,7 +80,7 @@ export interface SatelliteInfo {
80
80
  epochMs: number;
81
81
  /** Days between the elements' moment and the moment asked about (negative before it). */
82
82
  ageDays: number;
83
- /** The moment asked about is beyond `maxAgeDays` from the elements, so the place is an estimate (`estimateFar`): where it would be had its orbit not changed. */
83
+ /** The moment asked about is beyond `maxAgeDays` from the elements, so the place is an estimate (`estimateFar`): where it would be had its orbit not changed, or, with `estimateFar: "steady"`, on the orbit it had at `maxAgeDays` with the air drag off. */
84
84
  estimated: boolean;
85
85
  /** How far the moment asked about is from the elements' own, in days, whichever way (0 or more): for a card that says "estimated, 36 days from its last tracking". */
86
86
  estimatedDays: number;
@@ -175,8 +175,11 @@ export interface Satellites {
175
175
  * the places already held, so it costs nothing at a frame; the view uses it to draw a frame whenever the quickest dot has moved half a pixel. Multiply by the Earth's radius on the screen for pixels.
176
176
  */
177
177
  readonly fastest: number;
178
- /** Place satellites beyond `maxAgeDays` from their elements as an estimate (`estimateFar`, off by default). Setting it places everything again at the next draw. */
179
- estimateFar: boolean;
178
+ /**
179
+ * Place satellites beyond `maxAgeDays` from their elements as an estimate (`estimateFar`, off by default): `true` with the elements' air drag left in, so a low satellite sinks and is left out in time, `"steady"` with the drag off beyond `maxAgeDays`, so it keeps its usual orbit.
180
+ * Setting it places everything again at the next draw.
181
+ */
182
+ estimateFar: boolean | "steady";
180
183
  /** How many satellites the last `at` or `arc` placed as an estimate. */
181
184
  readonly estimatedCount: number;
182
185
  /** True if satellite `index` was placed by the last `at` or `arc` as an estimate: its moment is beyond `maxAgeDays` from its elements. */
@@ -194,7 +197,7 @@ export interface Satellites {
194
197
  pin(ms: number, first?: number, count?: number): void;
195
198
  /**
196
199
  * The place of each satellite at `ms` into `positions` (3 numbers each) and the stretch of orbit it travels over `spanMs` of game time into `segments` (6 numbers each: where it was `spanMs` earlier, then where it is).
197
- * The place is the last `pin`, turned about the orbit's axis by the mean motion, so a fast clock does not run SGP4 for every satellite on every frame. A `spanMs` that would turn it more than half a revolution is cut there. `maxLength` (Earth radii, 0 or left out for none) is the longest a streak may be along the orbit: a satellite whose span would carry it further is drawn that long, ending at its place, so the length does not grow with a faster clock. For an orbit placed by SGP4 itself the cap is applied as a shorter span of time, from the speed SGP4 gives there. An orbit with an eccentricity of 0.02 or more is placed by SGP4 itself instead (two calls a frame), because a turn at the mean motion would put it off its path.
200
+ * The place is the last `pin`, turned by the mean motion about the axis of the orbit plane at that pin (worked out once for each pin from the pinned place and SGP4's velocity there, not from the elements, whose plane has turned by days away), so a fast clock does not run SGP4 for every satellite on every frame. A `spanMs` that would turn it more than half a revolution is cut there. `maxLength` (Earth radii, 0 or left out for none) is the longest a streak may be along the orbit: a satellite whose span would carry it further is drawn that long, ending at its place, so the length does not grow with a faster clock. For an orbit placed by SGP4 itself the cap is applied as a shorter span of time, from the speed SGP4 gives there. An orbit with an eccentricity of 0.02 or more is placed by SGP4 itself instead (two calls a frame), because a turn at the mean motion would put it off its path.
198
201
  * Returns how many were written.
199
202
  */
200
203
  arc(ms: number, spanMs: number, positions: Float32Array, segments: Float32Array, maxLength?: number): number;
@@ -16,6 +16,7 @@ import type { TileStats } from "../realistic/tile-set.ts";
16
16
  import { setThreeLoader } from "../realistic/shared.ts";
17
17
  import type { LightMode } from "../realistic/earth.ts";
18
18
  import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/types.ts";
19
+ import type { SatelliteHistory } from "../satellites/history.ts";
19
20
  import { type PlanetName } from "./ephemeris.ts";
20
21
  import { type SatelliteScreen, type SatelliteStyle } from "./satellite-layer.ts";
21
22
  import { type SatelliteOthers } from "./satellite-focus.ts";
@@ -140,6 +141,27 @@ export interface RideOptions {
140
141
  distanceKm?: number;
141
142
  smooth?: boolean;
142
143
  }
144
+ /**
145
+ * What `observe` can be told: how many orbits of trail, its colour, and the ride's own distance and smoothness.
146
+ *
147
+ * @example
148
+ * ```ts no-run
149
+ * import type { ObserveOptions } from "@johnmorrisdotca/chikyu-earth/space/element";
150
+ *
151
+ * const options: ObserveOptions = { orbits: 5, colour: "#ffd479", distanceKm: 2000 };
152
+ * console.log(options.orbits);
153
+ * ```
154
+ */
155
+ export interface ObserveOptions {
156
+ /** How many orbits of the satellite's path before the moment shown are drawn as its trail: 0.25 to 20, 3 when left out. */
157
+ orbits?: number;
158
+ /** Any CSS colour for the trail (a light blue when left out). */
159
+ colour?: string;
160
+ /** How far back the camera keeps from the satellite, kilometres (3000 when left out, as a followed satellite). */
161
+ distanceKm?: number;
162
+ /** Glide to the view (true when left out); false, or a reader who asked for reduced motion, jumps. */
163
+ smooth?: boolean;
164
+ }
143
165
  /**
144
166
  * What the camera is riding along with now: the body or satellite, how (`from`, `follow` or `above`), where it looks, the facing it looks round from (`null` when none was chosen), and the distance kept for a satellite.
145
167
  *
@@ -193,6 +215,8 @@ type SatelliteStats = {
193
215
  selectedOpacity: number;
194
216
  orbitLines: number;
195
217
  estimated: number;
218
+ trailPoints: number;
219
+ trailBuilds: number;
196
220
  };
197
221
  /**
198
222
  * The `<chikyu-space>` custom element: the Earth, the Moon, the Sun and the planets where they are at a date and time, drawn with three.js through the shared renderer. It takes `center`, `time` (`now` or an ISO date), `speed` (1 is real time, 0 holds, 86400 is a day a second, negative runs backwards), `scale` (`compressed` or `true`), `labels` and `orbits` (`off` hides them); positions are computed in the browser by astronomy-engine, an optional peer dependency. It draws only when something changes, and nothing while it is out of sight.
@@ -764,6 +788,33 @@ export declare class ChikyuSpace extends HTMLElement {
764
788
  /** Texels the trail has painted. 0 after `clearPaint`, and again when the painted satellite changes. */
765
789
  get paintPixels(): number;
766
790
  setSatellites(group: string, satellites: Satellites | null, style?: Partial<SatelliteStyle>): void;
791
+ /**
792
+ * Give a satellite its history: a series of element sets, with its launch and decay dates, made by `createSatelliteHistory` (from `@johnmorrisdotca/chikyu-earth/satellites`, which needs satellite.js; this element does not import it).
793
+ * The satellite is set as the group `history:<id>` (one satellite, index 0) and is placed at any moment from the set nearest that moment: not drawn before its launch or after it has come down, shaded after its newest set
794
+ * (a prediction, with its uncertainty stated by `history.describe(ms)`). `null` takes it away. The page brings the sets: nothing is fetched.
795
+ *
796
+ * @param id - The NORAD catalogue number.
797
+ * @param history - What `createSatelliteHistory(sets, options)` returned, or `null` to remove it.
798
+ * @returns `{ group, index }` of the satellite, for `ride`, `observe` and `selectSatellite`, or `null` when removed or the history has no usable set.
799
+ */
800
+ setSatelliteHistory(id: number, history: SatelliteHistory | null): SatelliteRef | null;
801
+ /** The history given to `setSatelliteHistory` for a satellite, or `undefined`: its `describe(ms)` says whether it is launched, tracked, predicted or down, and when. */
802
+ satelliteHistory(id: number): SatelliteHistory | undefined;
803
+ /**
804
+ * The Observe view: the camera outside a satellite (the follow view, 3000 km back by default) with the Earth turning and sliding beneath, and the satellite's trail over its last `orbits` orbits drawn behind it as one line.
805
+ * The trail is the satellite's own path before the moment shown, placed by the same SGP4 (from the set nearest each moment, for a satellite with a history), so it runs back at any clock speed and is shorter where the satellite
806
+ * was not yet launched. It is drawn only while the view is on, rebuilt only when the clock moves, and never at rest or out of sight. `null` stops, and so does any other `ride`.
807
+ *
808
+ * @param target - `{ group, index }`, or a NORAD number: first the history set with `setSatelliteHistory`, else the first group that has it.
809
+ * @param options - `orbits`, `colour`, `distanceKm`, `smooth`.
810
+ * @returns False when the satellite is not set (nothing changes).
811
+ */
812
+ observe(target: SatelliteRef | number | null, options?: ObserveOptions): boolean;
813
+ /** What `observe` is showing now (`{ ref, orbits }`), or null. */
814
+ get observing(): {
815
+ ref: SatelliteRef;
816
+ orbits: number;
817
+ } | null;
767
818
  /** Show or hide a group without losing it. */
768
819
  showSatellites(group: string, on: boolean): void;
769
820
  /**
@@ -811,6 +862,7 @@ export declare class ChikyuSpace extends HTMLElement {
811
862
  * Keep placing satellites that are far from their element sets, as an estimate (the attribute `estimate-far`, off unless set; `estimate-far="off"` is off). A satellite is left out when the moment shown is more than `maxAgeDays` (30) from its elements; on, it is carried forward or back by the same SGP4 code
812
863
  * instead, and drawn lighter than a dimmed one. **An estimate is where the satellite would be if its orbit had not changed since the elements were taken.** It is worst for low orbits (drag changes them within days, and a manoeuvre moves the satellite along its path, so after weeks the estimate can be far along the orbit from the truth, and a satellite that has re-entered is not there at all) and for a long time away; a high orbit changes slowly and is close for months. Never before a satellite's launch or after its decay when its elements carry `LAUNCH_DATE` and `DECAY_DATE` (else the year of its `OBJECT_ID` is the earliest);
813
864
  * one SGP4 cannot carry that far, or brings down below about 120 km, is left out and is not counted as placed. Each estimated satellite is `estimated: true`, with `estimatedDays`, in `placeSatellite`, `satelliteInfo`, `chikyu-satellite-visibility` and `chikyu-satellite-click`, and `stats.satellites.estimated` counts them.
865
+ * **`estimate-far="steady"`** (the property set to `"steady"`) switches the air drag off beyond `maxAgeDays`, so a satellite keeps its usual orbit for as long as the clock runs instead of sinking in the model and being left out; the place does not jump where the drag is switched off.
814
866
  * It applies to every group, those the page made with `createSatellites(sets, { estimateFar: true })` too.
815
867
  *
816
868
  * @example
@@ -824,8 +876,8 @@ export declare class ChikyuSpace extends HTMLElement {
824
876
  * console.log(typeof farFromToday);
825
877
  * ```
826
878
  */
827
- get estimateFar(): boolean;
828
- set estimateFar(value: boolean);
879
+ get estimateFar(): boolean | "steady";
880
+ set estimateFar(value: boolean | "steady");
829
881
  /** The satellite marked by `selectSatellite` or by a press on it, if any. */
830
882
  get selectedSatellite(): SatelliteRef | null;
831
883
  /**
@@ -30,6 +30,7 @@ import { IMMERSIVE_STYLE, immersiveWheel } from "../realistic/immersive.js";
30
30
  import { readMeteorStrength } from "../meteors/strength.js";
31
31
  import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
32
32
  import { MAX_TEXTURE } from "../realistic/tiers.js";
33
+ import { trailOrbits } from "./trail.js";
33
34
  import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, frameAt } from "./ephemeris.js";
34
35
  import { MAX_ORBIT_GROUP, readStreakMax } from "./satellite-layer.js";
35
36
  import { applySatelliteFocus, satelliteEmphasis, satelliteGroupRows, shellRadiusOf, zoomForPerspectiveShell } from "./satellite-focus.js";
@@ -252,6 +253,8 @@ export class ChikyuSpace extends HTMLElement {
252
253
  /** The ease of `follow` from one share to the next, if one is running. */
253
254
  #followTimer;
254
255
  #focusBeforeRide = "Earth";
256
+ #histories = new Map();
257
+ #observed = false;
255
258
  /** The yaw, tilt and zoom from before a satellite group was framed, put back when the focus is cleared. */
256
259
  #focusView = null;
257
260
  #lostTold = false;
@@ -2116,6 +2119,86 @@ export class ChikyuSpace extends HTMLElement {
2116
2119
  this.#schedule();
2117
2120
  this.#gate?.request();
2118
2121
  }
2122
+ /**
2123
+ * Give a satellite its history: a series of element sets, with its launch and decay dates, made by `createSatelliteHistory` (from `@johnmorrisdotca/chikyu-earth/satellites`, which needs satellite.js; this element does not import it).
2124
+ * The satellite is set as the group `history:<id>` (one satellite, index 0) and is placed at any moment from the set nearest that moment: not drawn before its launch or after it has come down, shaded after its newest set
2125
+ * (a prediction, with its uncertainty stated by `history.describe(ms)`). `null` takes it away. The page brings the sets: nothing is fetched.
2126
+ *
2127
+ * @param id - The NORAD catalogue number.
2128
+ * @param history - What `createSatelliteHistory(sets, options)` returned, or `null` to remove it.
2129
+ * @returns `{ group, index }` of the satellite, for `ride`, `observe` and `selectSatellite`, or `null` when removed or the history has no usable set.
2130
+ */
2131
+ setSatelliteHistory(id, history) {
2132
+ const name = `history:${id}`;
2133
+ if (history === null || history.sets.length === 0) {
2134
+ this.#histories.delete(id);
2135
+ this.setSatellites(name, null);
2136
+ return null;
2137
+ }
2138
+ this.#histories.set(id, history);
2139
+ this.setSatellites(name, history.group, { orbits: false });
2140
+ return { group: name, index: 0 };
2141
+ }
2142
+ /** The history given to `setSatelliteHistory` for a satellite, or `undefined`: its `describe(ms)` says whether it is launched, tracked, predicted or down, and when. */
2143
+ satelliteHistory(id) {
2144
+ return this.#histories.get(id);
2145
+ }
2146
+ /**
2147
+ * The Observe view: the camera outside a satellite (the follow view, 3000 km back by default) with the Earth turning and sliding beneath, and the satellite's trail over its last `orbits` orbits drawn behind it as one line.
2148
+ * The trail is the satellite's own path before the moment shown, placed by the same SGP4 (from the set nearest each moment, for a satellite with a history), so it runs back at any clock speed and is shorter where the satellite
2149
+ * was not yet launched. It is drawn only while the view is on, rebuilt only when the clock moves, and never at rest or out of sight. `null` stops, and so does any other `ride`.
2150
+ *
2151
+ * @param target - `{ group, index }`, or a NORAD number: first the history set with `setSatelliteHistory`, else the first group that has it.
2152
+ * @param options - `orbits`, `colour`, `distanceKm`, `smooth`.
2153
+ * @returns False when the satellite is not set (nothing changes).
2154
+ */
2155
+ observe(target, options = {}) {
2156
+ const state = this.#model.satellites;
2157
+ if (target === null) {
2158
+ state.trail.ref = null;
2159
+ state.trail.version += 1;
2160
+ if (this.observing)
2161
+ this.ride(null);
2162
+ this.#observed = false;
2163
+ // the trail comes off at the next draw
2164
+ this.#schedule();
2165
+ this.#gate?.request();
2166
+ return true;
2167
+ }
2168
+ let ref = null;
2169
+ if (typeof target === "number") {
2170
+ if (this.#histories.has(target))
2171
+ ref = { group: `history:${target}`, index: 0 };
2172
+ else {
2173
+ for (const [group, entry] of state.groups) {
2174
+ const index = entry.satellites.sets.findIndex((set) => set.NORAD_CAT_ID === target);
2175
+ if (index >= 0) {
2176
+ ref = { group, index };
2177
+ break;
2178
+ }
2179
+ }
2180
+ }
2181
+ }
2182
+ else if (state.groups.get(target.group))
2183
+ ref = { group: target.group, index: target.index };
2184
+ if (!ref)
2185
+ return false;
2186
+ state.trail.ref = ref;
2187
+ state.trail.orbits = trailOrbits(options.orbits);
2188
+ if (typeof options.colour === "string" && options.colour !== "")
2189
+ state.trail.colour = options.colour;
2190
+ state.trail.version += 1;
2191
+ this.#observed = true;
2192
+ this.ride(ref, { view: "follow", distanceKm: options.distanceKm ?? 3000, ...(options.smooth === undefined ? {} : { smooth: options.smooth }) });
2193
+ return true;
2194
+ }
2195
+ /** What `observe` is showing now (`{ ref, orbits }`), or null. */
2196
+ get observing() {
2197
+ const t = this.#model.satellites.trail;
2198
+ const riding = this.riding;
2199
+ const on = t.ref !== null && this.#observed && riding !== null && typeof riding.target === "object" && riding.target.group === t.ref.group && riding.target.index === t.ref.index;
2200
+ return on && t.ref ? { ref: { ...t.ref }, orbits: t.orbits } : null;
2201
+ }
2119
2202
  /** Show or hide a group without losing it. */
2120
2203
  showSatellites(group, on) {
2121
2204
  const found = this.#model.satellites.groups.get(group);
@@ -2222,6 +2305,7 @@ export class ChikyuSpace extends HTMLElement {
2222
2305
  * Keep placing satellites that are far from their element sets, as an estimate (the attribute `estimate-far`, off unless set; `estimate-far="off"` is off). A satellite is left out when the moment shown is more than `maxAgeDays` (30) from its elements; on, it is carried forward or back by the same SGP4 code
2223
2306
  * instead, and drawn lighter than a dimmed one. **An estimate is where the satellite would be if its orbit had not changed since the elements were taken.** It is worst for low orbits (drag changes them within days, and a manoeuvre moves the satellite along its path, so after weeks the estimate can be far along the orbit from the truth, and a satellite that has re-entered is not there at all) and for a long time away; a high orbit changes slowly and is close for months. Never before a satellite's launch or after its decay when its elements carry `LAUNCH_DATE` and `DECAY_DATE` (else the year of its `OBJECT_ID` is the earliest);
2224
2307
  * one SGP4 cannot carry that far, or brings down below about 120 km, is left out and is not counted as placed. Each estimated satellite is `estimated: true`, with `estimatedDays`, in `placeSatellite`, `satelliteInfo`, `chikyu-satellite-visibility` and `chikyu-satellite-click`, and `stats.satellites.estimated` counts them.
2308
+ * **`estimate-far="steady"`** (the property set to `"steady"`) switches the air drag off beyond `maxAgeDays`, so a satellite keeps its usual orbit for as long as the clock runs instead of sinking in the model and being left out; the place does not jump where the drag is switched off.
2225
2309
  * It applies to every group, those the page made with `createSatellites(sets, { estimateFar: true })` too.
2226
2310
  *
2227
2311
  * @example
@@ -2236,10 +2320,15 @@ export class ChikyuSpace extends HTMLElement {
2236
2320
  * ```
2237
2321
  */
2238
2322
  get estimateFar() {
2239
- return this.hasAttribute("estimate-far") && this.getAttribute("estimate-far") !== "off";
2323
+ const value = this.getAttribute("estimate-far");
2324
+ if (value === null || value === "off")
2325
+ return false;
2326
+ return value.trim().toLowerCase() === "steady" ? "steady" : true;
2240
2327
  }
2241
2328
  set estimateFar(value) {
2242
- if (value)
2329
+ if (value === "steady")
2330
+ this.setAttribute("estimate-far", "steady");
2331
+ else if (value)
2243
2332
  this.setAttribute("estimate-far", "");
2244
2333
  else
2245
2334
  this.removeAttribute("estimate-far");
@@ -2579,7 +2668,7 @@ export class ChikyuSpace extends HTMLElement {
2579
2668
  let epochMs = 0;
2580
2669
  for (const group of this.#model.satellites.groups.values())
2581
2670
  epochMs = Math.max(epochMs, group.satellites.newestEpochMs);
2582
- return { groups: this.#model.satellites.groups.size, placed: drawn.placed, segments: drawn.segments, tooFast: drawn.tooFast, dotScale: drawn.dotScale, longestStreakPx: drawn.longestStreakPx, streakCapPx: drawn.streakCapPx, weight: drawn.weight, fade: drawn.fade, earthPx: drawn.earthPx, epochMs, propagations, lastBatchMs, maxBatchMs, updateMs: drawn.updateMs, maxUpdateMs: drawn.maxUpdateMs, averageUpdateMs: drawn.updates ? drawn.totalMs / drawn.updates : 0, updates: drawn.updates, selectedRing: drawn.selectedRing, hoverPath: drawn.hoverPath, hoverOpacity: drawn.hoverOpacity, selectedOpacity: drawn.selectedOpacity, orbitLines: drawn.orbitLines, estimated: drawn.estimated };
2671
+ return { groups: this.#model.satellites.groups.size, placed: drawn.placed, segments: drawn.segments, tooFast: drawn.tooFast, dotScale: drawn.dotScale, longestStreakPx: drawn.longestStreakPx, streakCapPx: drawn.streakCapPx, weight: drawn.weight, fade: drawn.fade, earthPx: drawn.earthPx, epochMs, propagations, lastBatchMs, maxBatchMs, updateMs: drawn.updateMs, maxUpdateMs: drawn.maxUpdateMs, averageUpdateMs: drawn.updates ? drawn.totalMs / drawn.updates : 0, updates: drawn.updates, selectedRing: drawn.selectedRing, hoverPath: drawn.hoverPath, hoverOpacity: drawn.hoverOpacity, selectedOpacity: drawn.selectedOpacity, orbitLines: drawn.orbitLines, estimated: drawn.estimated, trailPoints: drawn.trailPoints, trailBuilds: drawn.trailBuilds };
2583
2672
  }
2584
2673
  // --- the game clock ----------------------------------------------------------------------------------------------------------------------------
2585
2674
  #readSpeed() {
@@ -9,3 +9,4 @@ export { genericSatellite, satelliteKind, type SatelliteKind } from "./generic-s
9
9
  export { BEAM_ATTRIBUTES, BEAM_COLOUR, BEAM_ELEVATION, beamCells, footprintAngle, footprintKm, readBeam, type BeamCells, type BeamOptions } from "../beam/geometry.ts";
10
10
  export type { BeamStats } from "../beam/layer.ts";
11
11
  export { RIDE_PATH_FADE_KM } from "./path-ribbons.ts";
12
+ export { createTrailBuilder, TRAIL_DEFAULT_ORBITS, TRAIL_MAX_ORBITS, TRAIL_MAX_POINTS, TRAIL_POINTS_PER_ORBIT, trailOrbits, type PlaceAt, type TrailBuilder } from "./trail.ts";
@@ -10,3 +10,4 @@ export { localNorth, NORTH_UP_BLEND_DEG, NORTH_UP_POLE_DEG, northUpYaw, screenAn
10
10
  export { genericSatellite, satelliteKind } from "./generic-satellite.js";
11
11
  export { BEAM_ATTRIBUTES, BEAM_COLOUR, BEAM_ELEVATION, beamCells, footprintAngle, footprintKm, readBeam } from "../beam/geometry.js";
12
12
  export { RIDE_PATH_FADE_KM } from "./path-ribbons.js";
13
+ export { createTrailBuilder, TRAIL_DEFAULT_ORBITS, TRAIL_MAX_ORBITS, TRAIL_MAX_POINTS, TRAIL_POINTS_PER_ORBIT, trailOrbits } from "./trail.js";
@@ -27,6 +27,8 @@ export interface RibbonPath {
27
27
  dark?: Uint8Array;
28
28
  /** Any CSS colour: what the flagged segments are drawn in. Needed with `dark`. */
29
29
  darkInk?: string;
30
+ /** An open line, not a loop: the last segment (from the last point back to the first) is not drawn. A line of more than {@link PATH_POINTS} points is laid in several slots that share their end points. */
31
+ open?: boolean;
30
32
  }
31
33
  export interface PathRibbons {
32
34
  /** Write the paths into the buffers, none for an empty list. Costs nothing on the GPU until the next draw, and nothing is drawn while there are no paths. */
@@ -140,14 +140,14 @@ export function createPathRibbons(three, scene) {
140
140
  set(paths) {
141
141
  count = Math.min(PATH_SLOTS, paths.length);
142
142
  for (let p = 0; p < count; p += 1) {
143
- const { positions, style, fade = 0, dark, darkInk } = paths[p];
143
+ const { positions, style, fade = 0, dark, darkInk, open = false } = paths[p];
144
144
  colour.set(style.color);
145
145
  if (dark && darkInk)
146
146
  shade.set(darkInk);
147
147
  // the arc length at each point, in Earth radii, for the dashes
148
148
  let along = 0;
149
149
  for (let i = 0; i < PATH_POINTS; i += 1) {
150
- const j = (i + 1) % PATH_POINTS;
150
+ const j = open && i === PATH_POINTS - 1 ? i : (i + 1) % PATH_POINTS;
151
151
  const ax = positions[i * 3];
152
152
  const ay = positions[i * 3 + 1];
153
153
  const az = positions[i * 3 + 2];
@@ -65,6 +65,13 @@ export interface SatelliteState {
65
65
  * 0 draws the whole stretch one frame spans, however long that is.
66
66
  */
67
67
  streakMax: number;
68
+ /** The Observe view's trail (`observe`): the satellite it follows, how many orbits it reaches back, its colour, and a number that goes up when the page changes any of them. `ref` null: no trail, and nothing made for one. */
69
+ trail: {
70
+ ref: SatelliteRef | null;
71
+ orbits: number;
72
+ colour: string;
73
+ version: number;
74
+ };
68
75
  /** Set at each draw by the view: the satellite a ride shows as its model while the model is big enough to read. Its ring (the chosen marker) and name are left off while this is so; its orbit line stays. Clears with the ride, or when the model has handed over to the mark. */
69
76
  modelOver: SatelliteRef | null;
70
77
  drawn: {
@@ -89,6 +96,8 @@ export interface SatelliteState {
89
96
  pathsDrawn: number;
90
97
  pathDraws: number;
91
98
  estimated: number;
99
+ trailPoints: number;
100
+ trailBuilds: number;
92
101
  };
93
102
  }
94
103
  /**