@johnmorrisdotca/chikyu-earth 0.62.0 → 0.64.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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## Unreleased
4
+
5
+ ## 0.64.0 - 2026-11-20
6
+
7
+ - **From one satellite to another a ride glides round the Earth** (MODULES-1735). A `ride` call that goes from one satellite to another moved the camera in a straight line, which for a satellite behind the Earth ran through the Earth (held 1 km over the ground since 0.63.0), so a page had to climb, cross and come down in steps of its own. The camera now glides along the great circle round the Earth's centre, its height going evenly from the one ride's to the other's and never under 100 km above the ground (`GLIDE_FLOOR_KM`). The look is carried along the circle and goes over from the first look to the second, so a facing (ahead, down and the rest) stays level, nothing rolls over against the local vertical, and the view turns once towards its end. The glide back is the same flight the other way.
8
+ - **One glide for near and far.** For a satellite in sight the circle is all but the straight line (about 10 m off half way along a 25 km hop), so the great circle is the glide between any two satellites; every other change of ride (to or from a body, the same satellite in another view, a facing, the viewpoint) is the straight glide as before.
9
+ - **Its length.** `glide` sets it as for any glide; with `{ minMs, maxMs }` it follows the way along the circle (`satelliteGlideKm`).
10
+ - **Pure parts** in `/space`: `satelliteGlide(from, to, ease, floorKm?)`, `satelliteGlideKm(from, to)`, `GLIDE_FLOOR_KM` and the types `GlidePose` and `Quat`, with unit tests (`test/ride-glide.test.ts`: behind the Earth, in sight and across the far side, facing ahead and down; the floor; the same way back; a short hop against the straight line).
11
+ - **Tests.** `e2e/ride-glide.gl.ts` reads every frame of a glide on a stepped clock, from the ISS to a station in sight and to one behind the Earth, outside and inside, facing ahead and down: the distance to the end only falls, the camera keeps 100 km over the ground and never rises over both ends, the view only turns towards its end, neither its up nor its line of sight rolls over against the vertical, it arrives facing the way it faced, and the glide back is the same way. It fails on 0.63.0. The ride guide in English and Japanese, `docs/ride-along.md` and the README.
12
+
13
+ ## 0.63.0 - 2026-11-19
14
+
15
+ - **The view above a satellite has no facings, and a ride's camera never goes under the ground** (MODULES-1685).
16
+ - **Above.** `face()` in a ride with `view: "above"` returns `false` and leaves the camera as it was, and a `face` in `ride`'s options is left out there (`riding.face` is `null`). A facing there used to put the camera beside the satellite looking along the ground with the top of the picture (`aboveAxes`) along the line of sight, so three.js's `lookAt` had no way to turn the camera and took one from rounding, a different one each draw: the picture turned by up to 176 degrees between two reads and never settled. `up` put the camera under the satellite, inside the Earth (2,575 km under the ground for the ISS at the default 3,000 km).
17
+ - **Following a satellite** (`view: "follow"`) keeps its facings, and they now settle: along the ground (ahead, behind, left, right) the top of the picture is the sky, square to the line of sight.
18
+ - **Never under the ground.** In every view, facing, drag and glide the camera is held at least 1 km above the ground, and the near plane comes in when it is. A camera that looks at a satellite comes in towards it along its line of sight, so the satellite stays in its place in the picture; any other moves out along its line from the Earth's centre. The cases: a satellite that has come down, a camera following one from the far side of the Earth (it was 90 km under the ground in the test), a facing that would put it under the satellite, the straight line of a glide.
19
+ - **Tests.** `e2e/ride-steady.gl.ts`: above, each facing is refused and the camera holds its look; for every view and facing the camera stays above the ground; from the satellite and following it, every facing turns the camera and it holds still to under half a degree a second. They fail on 0.62.0. The ride guide in English and Japanese, `docs/ride-along.md` and the README.
20
+
3
21
  ## 0.62.0 - 2026-11-19
4
22
 
5
23
  - **A fly-to on the space view, and moves that bend instead of stopping** (MODULES-1582).
package/README.md CHANGED
@@ -359,7 +359,7 @@ Passes are only as good as the orbit data are new: each pass says how old its el
359
359
  <p align="center"><img alt="Riding along with the ISS, tipped towards the horizon: the Earth's curve and atmosphere, and the orbits of the other stations in the sky" src="docs/images/space-ride-horizon.png" width="420"></p>
360
360
 
361
361
  `space.ride({ group: "stations", index: 0 }, { look: "horizon" })` puts the camera on the ISS (or a Starlink satellite, the Moon, a planet) at its real place for the moment shown and looks at the Earth, which goes by beneath
362
- as the body moves along its orbit; switch to another body and the camera glides there. Straight down or toward the horizon, from the body or following it at a distance, time faster or slower. A ridden satellite is in the picture by default (the camera a little behind and above it, a small drawing of it where the page has no model, not to scale); `ride-viewpoint="inside"` (property `rideViewpoint`, option `viewpoint`) puts the camera at the satellite instead. A drag turns the view where the camera is, like turning your head (the satellite leaves the picture as you look away); `ride-drag="orbit"` (property `rideDrag`, option `drag`) takes the camera round the satellite as before. Seen from above, the model shrinks as the ride rises and hands over to the ordinary mark by 2,000 km; `ride-model-size="fixed"` (property `rideModelSize`, option `modelSize`) keeps one size at every height. `ride-up="north"` (property `rideUp`, option `up`) puts north at the top of the view above a satellite, so it is seen to go the way it really goes; a small compass on a ride shows north and the heading (`compass="off"` hides it), `rideTrack` and `chikyu-ride-track` give the heading, ground point and whether the Sun lights it, and the chosen orbit is amber in sunlight and blue in the Earth's shadow (`path-light="off"` for one colour). `ride-model-share`, `ride-model-seat` and `ride-zoom` frame and zoom the ridden satellite (properties `rideModelShare`, `rideModelSeat`, `rideZoom`). It animates continuously, so it keeps to the
362
+ as the body moves along its orbit; switch to another body and the camera glides there; from one satellite to another it glides round the Earth along the great circle, never through it and at least 100 km above the ground, with the facing kept level, so a satellite on the far side is reached in one smooth flight and Back is the same flight the other way. Straight down or toward the horizon, from the body or following it at a distance, time faster or slower. A ridden satellite is in the picture by default (the camera a little behind and above it, a small drawing of it where the page has no model, not to scale); `ride-viewpoint="inside"` (property `rideViewpoint`, option `viewpoint`) puts the camera at the satellite instead. A drag turns the view where the camera is, like turning your head (the satellite leaves the picture as you look away); `ride-drag="orbit"` (property `rideDrag`, option `drag`) takes the camera round the satellite as before. Seen from above, the model shrinks as the ride rises and hands over to the ordinary mark by 2,000 km; `ride-model-size="fixed"` (property `rideModelSize`, option `modelSize`) keeps one size at every height. `ride-up="north"` (property `rideUp`, option `up`) puts north at the top of the view above a satellite, so it is seen to go the way it really goes; a small compass on a ride shows north and the heading (`compass="off"` hides it), `rideTrack` and `chikyu-ride-track` give the heading, ground point and whether the Sun lights it, and the chosen orbit is amber in sunlight and blue in the Earth's shadow (`path-light="off"` for one colour). `ride-model-share`, `ride-model-seat` and `ride-zoom` frame and zoom the ridden satellite (properties `rideModelShare`, `rideModelSeat`, `rideZoom`). `face("ahead")` (behind, left, right, down, up; the keys W, S, A, D, F, R) turns a ride from the satellite or following it that way; the view above a satellite looks down on it and has no facings, so there `face()` returns `false` and the camera stays as it was. In every view the camera is never under the ground: it is held at least 1 km above it. It animates continuously, so it keeps to the
363
363
  same budget: at most 30 frames a second (one a second for reduced motion), nothing drawn while paused, out of sight or hidden. [Ride along guide](docs/guides/ride-along.md), [docs/ride-along.md](docs/ride-along.md).
364
364
 
365
365
  ## Printable sheets
@@ -615,7 +615,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
615
615
 
616
616
  ## How to cite
617
617
 
618
- > Morris, J. (2026). *Chikyu Earth* (version 0.62.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
618
+ > Morris, J. (2026). *Chikyu Earth* (version 0.64.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
619
619
 
620
620
  GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA. Cite the version you used (`npm ls @johnmorrisdotca/chikyu-earth`), and credit the sources behind the numbers and pictures: [NOTICE.md](NOTICE.md) says who made each one and under what terms.
621
621
 
@@ -118,7 +118,7 @@ export type SpacePreset = "earth" | "moon" | "sun" | "inner" | "solar-system" |
118
118
  export interface RideOptions {
119
119
  view?: "from" | "follow" | "above";
120
120
  look?: RideLook;
121
- /** Face this way as the ride opens (`face`). */
121
+ /** Face this way as the ride opens (`face`). Left out of a ride above a satellite and of a body followed, which have no ways to face. */
122
122
  face?: RideFace;
123
123
  /** The radius of the ridden satellite's model as a share of the picture's height (0.02 to 1.2), for this ride: the element's `ride-model-share` when not given. Along the way it goes the default is 0.22, above the satellite 0.17 (its size at the lowest height). */
124
124
  modelShare?: number;
@@ -134,7 +134,7 @@ export interface RideOptions {
134
134
  up?: RideUp;
135
135
  /** How far back the camera is kept from the satellite in an outside ride, in kilometres (`view: "from"`; the element's `ride-outside-km` when not given, else 25). It is never more than half the satellite's height. */
136
136
  outsideKm?: number;
137
- /** How long the glide to this ride lasts: a number of milliseconds (1200 by default), or `{ minMs, maxMs }` for a length that follows how far the camera has to move (`rideGlideMs`: 800 to 4000 ms by default, about 1.2 s for a 25 km hop and 3 s for 3,000 km). */
137
+ /** How long the glide to this ride lasts: a number of milliseconds (1200 by default), or `{ minMs, maxMs }` for a length that follows how far the camera has to move (`rideGlideMs`: 800 to 4000 ms by default, about 1.2 s for a 25 km hop and 3 s for 3,000 km; from one satellite to another, the way along the great circle, `satelliteGlideKm`). */
138
138
  glide?: number | {
139
139
  minMs?: number;
140
140
  maxMs?: number;
@@ -675,8 +675,9 @@ export declare class ChikyuSpace extends HTMLElement {
675
675
  /**
676
676
  * Ride along with a body or a satellite. By default the camera sits at it and looks at the Earth, with the way it is going at the top of the picture, at its real place for the moment shown, so the
677
677
  * Earth turns and slides beneath as it moves along its orbit (an ISS view goes round about every 90 minutes). A drag looks about from there (a drag right turns the camera to its left and a drag up tips it towards the bottom of its picture, so the ground follows the pointer), the shared controls' zoom narrows the view.
678
- * A satellite is `{ group, index }` of a group set with `setSatellites`; it is placed exactly, one SGP4 call a frame, at any speed. Another call switches smoothly; `null` stops. The draw rate follows how
678
+ * A satellite is `{ group, index }` of a group set with `setSatellites`; it is placed exactly, one SGP4 call a frame, at any speed. Another call switches smoothly; `null` stops. From one satellite to another the glide goes round the Earth along the great circle, never through it and at least 100 km above the ground, with the look carried along so a facing stays level (`satelliteGlide`); the glide back is the same flight the other way. The draw rate follows how
679
679
  * fast the picture moves, never more than 30 a second (one a second for a reader who asked for reduced motion), and nothing is drawn out of sight.
680
+ * Whatever the view, facing, drag or glide, the camera is never under the ground: one that would be lower than 1 km above it is held there. A camera that looks at a satellite comes in towards it along its line of sight, so the satellite stays where it is in the picture; any other moves out along its line from the Earth's centre.
680
681
  *
681
682
  * @param target - A body name (`"Moon"`, `"Mars"`, ...) or a satellite `{ group, index }`, or `null` to stop.
682
683
  * @param options - `view`, `look`, `distanceKm`, `smooth` (see `RideOptions`).
@@ -684,11 +685,11 @@ export declare class ChikyuSpace extends HTMLElement {
684
685
  ride(target: RideTarget | null, options?: RideOptions): void;
685
686
  /**
686
687
  * Face one way while riding: `ahead` along the way it goes, `behind`, `left` or `right` (as seen facing ahead), `down` straight at the Earth, `up` straight away from it.
687
- * In the `above` view, `down` looks straight down at the satellite and the Earth below it. The camera glides there in half a second (at once for a reader who asked for reduced motion) and keeps the zoom.
688
+ * The camera glides there in half a second (at once for a reader who asked for reduced motion) and keeps the zoom.
688
689
  * The facing stays pressed until the view is turned or tipped. `chikyu-ride-face` is sent with `{ face }` (`null` when it is let go). Keys, while the element is focused: W ahead, S behind, A left, D right, R up, F down. The arrow keys stay with the view controls.
689
690
  *
690
691
  * @param face - The way to face.
691
- * Following a body (a planet, the Moon) there is no way to face: it returns `false`. Held keys do not repeat, and keys typed in a field or in editable text are left to it.
692
+ * Following a body (a planet, the Moon) there is no way to face, and none in the view above a satellite (`view: "above"`, which looks down on it): it returns `false` and the camera stays as it was. Held keys do not repeat, and keys typed in a field or in editable text are left to it.
692
693
  *
693
694
  * @returns Whether the camera faces that way now (`true` too when it already did, and nothing moves).
694
695
  */
@@ -1764,8 +1764,9 @@ export class ChikyuSpace extends HTMLElement {
1764
1764
  /**
1765
1765
  * Ride along with a body or a satellite. By default the camera sits at it and looks at the Earth, with the way it is going at the top of the picture, at its real place for the moment shown, so the
1766
1766
  * Earth turns and slides beneath as it moves along its orbit (an ISS view goes round about every 90 minutes). A drag looks about from there (a drag right turns the camera to its left and a drag up tips it towards the bottom of its picture, so the ground follows the pointer), the shared controls' zoom narrows the view.
1767
- * A satellite is `{ group, index }` of a group set with `setSatellites`; it is placed exactly, one SGP4 call a frame, at any speed. Another call switches smoothly; `null` stops. The draw rate follows how
1767
+ * A satellite is `{ group, index }` of a group set with `setSatellites`; it is placed exactly, one SGP4 call a frame, at any speed. Another call switches smoothly; `null` stops. From one satellite to another the glide goes round the Earth along the great circle, never through it and at least 100 km above the ground, with the look carried along so a facing stays level (`satelliteGlide`); the glide back is the same flight the other way. The draw rate follows how
1768
1768
  * fast the picture moves, never more than 30 a second (one a second for a reader who asked for reduced motion), and nothing is drawn out of sight.
1769
+ * Whatever the view, facing, drag or glide, the camera is never under the ground: one that would be lower than 1 km above it is held there. A camera that looks at a satellite comes in towards it along its line of sight, so the satellite stays where it is in the picture; any other moves out along its line from the Earth's centre.
1769
1770
  *
1770
1771
  * @param target - A body name (`"Moon"`, `"Mars"`, ...) or a satellite `{ group, index }`, or `null` to stop.
1771
1772
  * @param options - `view`, `look`, `distanceKm`, `smooth` (see `RideOptions`).
@@ -1774,6 +1775,9 @@ export class ChikyuSpace extends HTMLElement {
1774
1775
  const model = this.#model;
1775
1776
  const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
1776
1777
  const wasRiding = model.ride !== null;
1778
+ const was = model.ride?.target;
1779
+ // from one satellite to another the glide goes round the Earth along the great circle (`satelliteGlide`), never through it; any other change of ride glides in a straight line
1780
+ const round = !!was && typeof was !== "string" && !!target && typeof target !== "string" && (was.group !== target.group || was.index !== target.index);
1777
1781
  model.rideFrame.share = clampFrame(options.modelShare, 0.02, 1.2) ?? this.rideModelShare;
1778
1782
  model.rideFrame.seat = clampFrame(options.modelSeat, 0.5, 1.4) ?? this.rideModelSeat;
1779
1783
  model.rideFrame.ms = reduced ? 0 : 400;
@@ -1795,8 +1799,8 @@ export class ChikyuSpace extends HTMLElement {
1795
1799
  const asked = options.view ?? "from";
1796
1800
  // above a body is meant for a satellite: a body is followed
1797
1801
  const view = typeof target === "string" && (target === "Earth" || asked === "above") ? "follow" : asked;
1798
- // a body followed (a planet, the Moon, the Earth) is looked at from round it as the view turns: it has no ways to face
1799
- const faceable = !(view === "follow" && typeof target === "string");
1802
+ // a body followed (a planet, the Moon, the Earth) is looked at from round it as the view turns, and the view above a satellite looks down on it: neither has ways to face
1803
+ const faceable = !(view === "follow" && typeof target === "string") && view !== "above";
1800
1804
  const face = faceable && options.face && RIDE_FACES.includes(options.face) ? options.face : null;
1801
1805
  model.ride = { target: typeof target === "string" ? target : { group: target.group, index: target.index }, view, look: face && view === "from" ? "horizon" : (options.look ?? "down"), face, distanceKm: Math.max(100, options.distanceKm ?? 3000), viewpoint: options.viewpoint === "inside" || options.viewpoint === "outside" ? options.viewpoint : this.rideViewpoint, outsideKm: readOutsideKm(options.outsideKm) ?? this.rideOutsideKm ?? OUTSIDE_KM, modelSize: options.modelSize === "fixed" || options.modelSize === "distance" ? options.modelSize : this.rideModelSize, drag: options.drag === "head" || options.drag === "orbit" ? options.drag : this.rideDrag, up: options.up === "north" || options.up === "travel" ? options.up : this.rideUp };
1802
1806
  if (face) {
@@ -1813,7 +1817,7 @@ export class ChikyuSpace extends HTMLElement {
1813
1817
  this.#lostTold = false;
1814
1818
  const pose = model.pose;
1815
1819
  const glide = readGlide(options.glide);
1816
- model.transition = (options.smooth ?? true) && !reduced && pose.valid ? { start: performance.now(), duration: glide.duration, ...(glide.scaled ? { scaled: glide.scaled } : {}), from: { p: [pose.p[0], pose.p[1], pose.p[2]], q: [pose.q[0], pose.q[1], pose.q[2], pose.q[3]], fov: pose.fov } } : null;
1820
+ model.transition = (options.smooth ?? true) && !reduced && pose.valid ? { start: performance.now(), duration: glide.duration, ...(glide.scaled ? { scaled: glide.scaled } : {}), ...(round ? { round } : {}), from: { p: [pose.p[0], pose.p[1], pose.p[2]], q: [pose.q[0], pose.q[1], pose.q[2], pose.q[3]], fov: pose.fov } } : null;
1817
1821
  this.#last = performance.now();
1818
1822
  this.#schedule();
1819
1823
  this.#gate?.request();
@@ -1822,11 +1826,11 @@ export class ChikyuSpace extends HTMLElement {
1822
1826
  }
1823
1827
  /**
1824
1828
  * Face one way while riding: `ahead` along the way it goes, `behind`, `left` or `right` (as seen facing ahead), `down` straight at the Earth, `up` straight away from it.
1825
- * In the `above` view, `down` looks straight down at the satellite and the Earth below it. The camera glides there in half a second (at once for a reader who asked for reduced motion) and keeps the zoom.
1829
+ * The camera glides there in half a second (at once for a reader who asked for reduced motion) and keeps the zoom.
1826
1830
  * The facing stays pressed until the view is turned or tipped. `chikyu-ride-face` is sent with `{ face }` (`null` when it is let go). Keys, while the element is focused: W ahead, S behind, A left, D right, R up, F down. The arrow keys stay with the view controls.
1827
1831
  *
1828
1832
  * @param face - The way to face.
1829
- * Following a body (a planet, the Moon) there is no way to face: it returns `false`. Held keys do not repeat, and keys typed in a field or in editable text are left to it.
1833
+ * Following a body (a planet, the Moon) there is no way to face, and none in the view above a satellite (`view: "above"`, which looks down on it): it returns `false` and the camera stays as it was. Held keys do not repeat, and keys typed in a field or in editable text are left to it.
1830
1834
  *
1831
1835
  * @returns Whether the camera faces that way now (`true` too when it already did, and nothing moves).
1832
1836
  */
@@ -1835,8 +1839,8 @@ export class ChikyuSpace extends HTMLElement {
1835
1839
  const ride = model.ride;
1836
1840
  if (!ride || !RIDE_FACES.includes(face))
1837
1841
  return false;
1838
- // following a body there is no way to face: only from a body or a satellite, following a satellite, or above it
1839
- if (ride.view === "follow" && typeof ride.target === "string")
1842
+ // following a body there is no way to face, nor above a satellite (the view looks down on it): only from a body or a satellite, or following a satellite
1843
+ if ((ride.view === "follow" && typeof ride.target === "string") || ride.view === "above")
1840
1844
  return false;
1841
1845
  // already facing that way: nothing to turn, and no glide started again
1842
1846
  if (this.facing === face)
@@ -2,6 +2,7 @@ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitP
2
2
  export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
3
3
  export { fitDistance, plainPainter, type BodyDrawing, type RideTrack, type BodyMoon, type BodyPainter, type BodyView, type PaintContext, type SatellitePainter } from "./scene.ts";
4
4
  export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, rideGlideMs, ridePose, rideTiltLimits, rideTurnDegrees, type RideDrag, type RideFace, type RideInput, type RideLook, type RidePose, type RideModelSize, type RideViewpoint } from "./ride.ts";
5
+ export { GLIDE_FLOOR_KM, satelliteGlide, satelliteGlideKm, type GlidePose, type Quat } from "./ride-glide.ts";
5
6
  export { earthHides, type SatelliteScreen } from "./satellite-layer.ts";
6
7
  export { ABOVE_MODEL_KM, ABOVE_MODEL_SHARE, aboveAxes, aboveModelShare, MODEL_FADE_FROM_KM, MODEL_FADE_TO_KM, MODEL_HANDOVER_PX, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.ts";
7
8
  export { localNorth, NORTH_UP_BLEND_DEG, NORTH_UP_POLE_DEG, northUpYaw, screenAngle, type RideUp } from "./north-up.ts";
@@ -4,6 +4,7 @@ export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitP
4
4
  export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition } from "./scale.js";
5
5
  export { fitDistance, plainPainter } from "./scene.js";
6
6
  export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, rideGlideMs, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
7
+ export { GLIDE_FLOOR_KM, satelliteGlide, satelliteGlideKm } from "./ride-glide.js";
7
8
  export { earthHides } from "./satellite-layer.js";
8
9
  export { ABOVE_MODEL_KM, ABOVE_MODEL_SHARE, aboveAxes, aboveModelShare, MODEL_FADE_FROM_KM, MODEL_FADE_TO_KM, MODEL_HANDOVER_PX, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
9
10
  export { localNorth, NORTH_UP_BLEND_DEG, NORTH_UP_POLE_DEG, northUpYaw, screenAngle } from "./north-up.js";
@@ -0,0 +1,78 @@
1
+ import type { Vec3 } from "./ephemeris.ts";
2
+ /**
3
+ * A rotation as a quaternion, `[x, y, z, w]` (three.js's order).
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import type { Quat } from "@johnmorrisdotca/chikyu-earth/space";
8
+ *
9
+ * const still: Quat = [0, 0, 0, 1];
10
+ * console.log(still[3]);
11
+ * ```
12
+ */
13
+ export type Quat = [number, number, number, number];
14
+ /**
15
+ * A camera's place and orientation: `p` in Earth radii from the Earth's centre, `q` the rotation from the camera's own axes (it looks down its -z, its up is +y) to the scene's.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import type { GlidePose } from "@johnmorrisdotca/chikyu-earth/space";
20
+ *
21
+ * const pose: GlidePose = { p: [1.07, 0, 0], q: [0, 0, 0, 1] };
22
+ * console.log(pose.p[0]);
23
+ * ```
24
+ */
25
+ export interface GlidePose {
26
+ p: Vec3;
27
+ q: Quat;
28
+ }
29
+ /**
30
+ * The least height above the ground, in km, that the glide from one satellite's ride to another's keeps between its two ends (`satelliteGlide`). Ends lower than this (a satellite coming down) are left
31
+ * where they are and the glide rises over the floor between them.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { GLIDE_FLOOR_KM } from "@johnmorrisdotca/chikyu-earth/space";
36
+ *
37
+ * console.log(`${GLIDE_FLOOR_KM} km`);
38
+ * ```
39
+ */
40
+ export declare const GLIDE_FLOOR_KM = 100;
41
+ /**
42
+ * Where the camera is, a share `ease` (0 to 1) along the glide from one satellite's ride to another's. It goes along the great circle round the Earth's centre from the first place to the second, its distance from
43
+ * the centre going evenly from the one to the other, so it never passes through the Earth or dips under the two heights; between ends lower than `floorKm` above the ground it rises over that floor in the middle.
44
+ * The look is carried along the circle (turned with it, as the local vertical turns) and goes over the way from the first look to the second in the same frame, so a facing along the ground stays level, a facing
45
+ * down stays down, nothing rolls over, and the view turns once towards its end. The glide back is the same glide the other way: `satelliteGlide(to, from, 1 - ease)` is the same pose. A short hop is all but the
46
+ * straight glide: the circle is about 10 m from the straight line half way along a hop of 25 km.
47
+ *
48
+ * @param from - The camera where the glide began.
49
+ * @param to - The camera of the ride it goes to (its pose this frame: the satellite may move).
50
+ * @param ease - How far along, 0 at the start and 1 at the end (eased by the caller).
51
+ * @param floorKm - The least height above the ground between the ends, km (`GLIDE_FLOOR_KM`).
52
+ * @returns The camera's place and orientation there.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import { satelliteGlide } from "@johnmorrisdotca/chikyu-earth/space";
57
+ *
58
+ * // from over one side of the Earth to over the other: half way, the camera is over the Earth's edge, not inside it
59
+ * const mid = satelliteGlide({ p: [1.07, 0, 0], q: [0, 0, 0, 1] }, { p: [-1.07, 0, 0.01], q: [0, 0, 0, 1] }, 0.5);
60
+ * console.log(Math.hypot(...mid.p).toFixed(2));
61
+ * ```
62
+ */
63
+ export declare function satelliteGlide(from: GlidePose, to: GlidePose, ease: number, floorKm?: number): GlidePose;
64
+ /**
65
+ * How far, in km, the camera goes in the glide from one satellite's ride to another's (`satelliteGlide`): along the great circle, with the change of height. For a glide whose length follows the distance (`rideGlideMs`).
66
+ *
67
+ * @param from - Where the glide begins, Earth radii from the Earth's centre.
68
+ * @param to - Where it ends.
69
+ * @returns The length, km.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * import { satelliteGlideKm } from "@johnmorrisdotca/chikyu-earth/space";
74
+ *
75
+ * console.log(Math.round(satelliteGlideKm([1.07, 0, 0], [0, 1.07, 0])));
76
+ * ```
77
+ */
78
+ export declare function satelliteGlideKm(from: Vec3, to: Vec3): number;
@@ -0,0 +1,112 @@
1
+ /**
2
+ * The least height above the ground, in km, that the glide from one satellite's ride to another's keeps between its two ends (`satelliteGlide`). Ends lower than this (a satellite coming down) are left
3
+ * where they are and the glide rises over the floor between them.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { GLIDE_FLOOR_KM } from "@johnmorrisdotca/chikyu-earth/space";
8
+ *
9
+ * console.log(`${GLIDE_FLOOR_KM} km`);
10
+ * ```
11
+ */
12
+ export const GLIDE_FLOOR_KM = 100;
13
+ const EARTH_KM = 6371;
14
+ const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
15
+ const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
16
+ const norm = (a) => Math.hypot(a[0], a[1], a[2]);
17
+ /** `a` then `b`: the rotation `b` followed by `a` (`a * b`). */
18
+ function mul(a, b) {
19
+ return [
20
+ a[3] * b[0] + a[0] * b[3] + a[1] * b[2] - a[2] * b[1],
21
+ a[3] * b[1] - a[0] * b[2] + a[1] * b[3] + a[2] * b[0],
22
+ a[3] * b[2] + a[0] * b[1] - a[1] * b[0] + a[2] * b[3],
23
+ a[3] * b[3] - a[0] * b[0] - a[1] * b[1] - a[2] * b[2],
24
+ ];
25
+ }
26
+ /** The rotation by `angle` radians about the unit `axis`. */
27
+ const about = (axis, angle) => { const s = Math.sin(angle / 2); return [axis[0] * s, axis[1] * s, axis[2] * s, Math.cos(angle / 2)]; };
28
+ /** The shorter way from `a` to `b`, a share `t` along it, normalised. */
29
+ function slerp(a, b, t) {
30
+ let c = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
31
+ const s = c < 0 ? -1 : 1;
32
+ c *= s;
33
+ let ka = 1 - t, kb = t * s;
34
+ if (c < 0.9995) {
35
+ const half = Math.acos(Math.min(1, c)), sin = Math.sin(half);
36
+ ka = Math.sin((1 - t) * half) / sin;
37
+ kb = (Math.sin(t * half) / sin) * s;
38
+ }
39
+ const out = [a[0] * ka + b[0] * kb, a[1] * ka + b[1] * kb, a[2] * ka + b[2] * kb, a[3] * ka + b[3] * kb];
40
+ const n = Math.hypot(...out) || 1;
41
+ return [out[0] / n, out[1] / n, out[2] / n, out[3] / n];
42
+ }
43
+ /** The great circle from the direction of `a` to that of `b` (both from the Earth's centre): the axis it turns about and the angle, radians. Opposite directions turn about a line square to `a`. */
44
+ function greatCircle(a, b) {
45
+ const c = cross(a, b), sin = norm(c), cos = dot(a, b);
46
+ const angle = Math.atan2(sin, cos);
47
+ if (sin > 1e-9 * norm(a) * norm(b))
48
+ return { axis: [c[0] / sin, c[1] / sin, c[2] / sin], angle };
49
+ if (cos >= 0)
50
+ return { axis: [0, 0, 1], angle: 0 };
51
+ const side = Math.abs(a[1]) < 0.9 * norm(a) ? cross(a, [0, 1, 0]) : cross(a, [1, 0, 0]);
52
+ const n = norm(side);
53
+ return { axis: [side[0] / n, side[1] / n, side[2] / n], angle };
54
+ }
55
+ /**
56
+ * Where the camera is, a share `ease` (0 to 1) along the glide from one satellite's ride to another's. It goes along the great circle round the Earth's centre from the first place to the second, its distance from
57
+ * the centre going evenly from the one to the other, so it never passes through the Earth or dips under the two heights; between ends lower than `floorKm` above the ground it rises over that floor in the middle.
58
+ * The look is carried along the circle (turned with it, as the local vertical turns) and goes over the way from the first look to the second in the same frame, so a facing along the ground stays level, a facing
59
+ * down stays down, nothing rolls over, and the view turns once towards its end. The glide back is the same glide the other way: `satelliteGlide(to, from, 1 - ease)` is the same pose. A short hop is all but the
60
+ * straight glide: the circle is about 10 m from the straight line half way along a hop of 25 km.
61
+ *
62
+ * @param from - The camera where the glide began.
63
+ * @param to - The camera of the ride it goes to (its pose this frame: the satellite may move).
64
+ * @param ease - How far along, 0 at the start and 1 at the end (eased by the caller).
65
+ * @param floorKm - The least height above the ground between the ends, km (`GLIDE_FLOOR_KM`).
66
+ * @returns The camera's place and orientation there.
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * import { satelliteGlide } from "@johnmorrisdotca/chikyu-earth/space";
71
+ *
72
+ * // from over one side of the Earth to over the other: half way, the camera is over the Earth's edge, not inside it
73
+ * const mid = satelliteGlide({ p: [1.07, 0, 0], q: [0, 0, 0, 1] }, { p: [-1.07, 0, 0.01], q: [0, 0, 0, 1] }, 0.5);
74
+ * console.log(Math.hypot(...mid.p).toFixed(2));
75
+ * ```
76
+ */
77
+ export function satelliteGlide(from, to, ease, floorKm = GLIDE_FLOOR_KM) {
78
+ const r0 = norm(from.p), r1 = norm(to.p);
79
+ if (r0 < 1e-9 || r1 < 1e-9)
80
+ return { p: [...to.p], q: [...to.q] };
81
+ const { axis, angle } = greatCircle(from.p, to.p);
82
+ const turn = about(axis, angle * ease);
83
+ const along = [from.p[0] / r0, from.p[1] / r0, from.p[2] / r0];
84
+ const c = Math.cos(angle * ease), s = Math.sin(angle * ease), k = dot(axis, along) * (1 - c), side = cross(axis, along);
85
+ const u = [along[0] * c + side[0] * s + axis[0] * k, along[1] * c + side[1] * s + axis[1] * k, along[2] * c + side[2] * s + axis[2] * k];
86
+ const floor = 1 + Math.max(0, floorKm) / EARTH_KM;
87
+ const lift = Math.max(0, floor - Math.min(r0, r1)) * Math.sin(Math.PI * Math.min(1, Math.max(0, ease)));
88
+ const r = r0 + (r1 - r0) * ease + lift;
89
+ // the second look, as it would be at the first place (turned back along the circle), then the way between the two looks, turned on to where the camera is
90
+ const back = [-axis[0] * Math.sin(angle / 2), -axis[1] * Math.sin(angle / 2), -axis[2] * Math.sin(angle / 2), Math.cos(angle / 2)];
91
+ const q = mul(turn, slerp(from.q, mul(back, to.q), ease));
92
+ return { p: [u[0] * r, u[1] * r, u[2] * r], q };
93
+ }
94
+ /**
95
+ * How far, in km, the camera goes in the glide from one satellite's ride to another's (`satelliteGlide`): along the great circle, with the change of height. For a glide whose length follows the distance (`rideGlideMs`).
96
+ *
97
+ * @param from - Where the glide begins, Earth radii from the Earth's centre.
98
+ * @param to - Where it ends.
99
+ * @returns The length, km.
100
+ *
101
+ * @example
102
+ * ```ts
103
+ * import { satelliteGlideKm } from "@johnmorrisdotca/chikyu-earth/space";
104
+ *
105
+ * console.log(Math.round(satelliteGlideKm([1.07, 0, 0], [0, 1.07, 0])));
106
+ * ```
107
+ */
108
+ export function satelliteGlideKm(from, to) {
109
+ const r0 = norm(from), r1 = norm(to);
110
+ const { angle } = greatCircle(from, to);
111
+ return Math.hypot(angle * (r0 + r1) / 2, r1 - r0) * EARTH_KM;
112
+ }
@@ -243,7 +243,10 @@ export interface SpaceModel {
243
243
  ride: RideState | null;
244
244
  /** Set at each draw: the target of the ride could not be placed (a satellite whose elements are too old, or that is gone), so the ordinary camera was used. */
245
245
  rideLost: boolean;
246
- /** A camera move in progress from where the last draw left it: when it began (ms of the page's clock), how long it takes. */
246
+ /**
247
+ * A camera move in progress from where the last draw left it: when it began (ms of the page's clock), how long it takes. `round`: a ride that went from one satellite to another, which glides along the great circle
248
+ * round the Earth's centre (`satelliteGlide`); every other move is a straight line.
249
+ */
247
250
  transition: {
248
251
  start: number;
249
252
  duration: number;
@@ -251,6 +254,7 @@ export interface SpaceModel {
251
254
  minMs: number;
252
255
  maxMs: number;
253
256
  };
257
+ round?: boolean;
254
258
  from: {
255
259
  p: Vec3;
256
260
  q: [number, number, number, number];
@@ -7,6 +7,7 @@ import { createTileSet } from "../realistic/tile-set.js";
7
7
  import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
8
8
  import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
9
9
  import { faceOffset, outsidePose, rideGlideMs, ridePose } from "./ride.js";
10
+ import { satelliteGlide, satelliteGlideKm } from "./ride-glide.js";
10
11
  import { stripLights } from "./model-lights.js";
11
12
  import { cloudFade, CLOUD_FADE_DEFAULT, CLOUD_WIDTH } from "../realistic/cloud-fade.js";
12
13
  import { newLightFade, stepLightFade } from "../realistic/light-fade.js";
@@ -32,6 +33,8 @@ import { subsolarPoint, unitVector } from "../realistic/sun.js";
32
33
  const MAX_MARKED = 80;
33
34
  const RAD = Math.PI / 180;
34
35
  const FOV = 35;
36
+ /** The nearest a camera comes to the Earth's centre, in Earth radii: 1 km above the ground. A ride (or a glide into or out of one) that would put the camera lower, or under the ground, puts it here instead (`clearGround`). */
37
+ const GROUND_CLEAR = 1 + 1 / 6371;
35
38
  const newEase = () => ({ cur: Number.NaN, from: Number.NaN, to: Number.NaN, start: 0 });
36
39
  /** Moves an ease towards `to`: at once when it is new or `ms` is 0 (reduced motion), else over `ms` milliseconds with a smooth step. True while it is still on its way. */
37
40
  function stepEase(e, to, now, ms, fresh) {
@@ -163,6 +166,32 @@ const unit = (v) => {
163
166
  const l = Math.hypot(v[0], v[1], v[2]) || 1;
164
167
  return [v[0] / l, v[1] / l, v[2] / l];
165
168
  };
169
+ /**
170
+ * Keep a camera at least `GROUND_CLEAR` from the Earth's centre. One looking at a point above the ground (`at`) is brought towards it along its line of sight, to where that line comes out of the ground, so the point stays where it is in the
171
+ * picture; any other is moved out along its line from the centre. Changes `camera` in place, and brings the near plane in to half its height when it moves it.
172
+ */
173
+ function clearGround(camera, at) {
174
+ const p = camera.position;
175
+ const from = p.length();
176
+ if (from >= GROUND_CLEAR)
177
+ return;
178
+ const atFrom = at ? Math.hypot(at[0], at[1], at[2]) : 0;
179
+ if (at && atFrom > GROUND_CLEAR) {
180
+ // the first point from `at` towards the camera where the line is GROUND_CLEAR from the centre
181
+ const d = [p.x - at[0], p.y - at[1], p.z - at[2]];
182
+ const a = d[0] * d[0] + d[1] * d[1] + d[2] * d[2];
183
+ const b = 2 * (at[0] * d[0] + at[1] * d[1] + at[2] * d[2]);
184
+ const c = atFrom * atFrom - GROUND_CLEAR * GROUND_CLEAR;
185
+ const t = (-b - Math.sqrt(Math.max(0, b * b - 4 * a * c))) / (2 * a);
186
+ p.set(at[0] + d[0] * t, at[1] + d[1] * t, at[2] + d[2] * t);
187
+ }
188
+ else {
189
+ if (from < 1e-9)
190
+ p.set(0, 0, 1);
191
+ p.multiplyScalar(GROUND_CLEAR / p.length());
192
+ }
193
+ camera.near = Math.min(camera.near, (GROUND_CLEAR - 1) * 0.5);
194
+ }
166
195
  /** A square facing +z, 2 x 2, with uvs 0 to 1. */
167
196
  function quad(three) {
168
197
  const g = new three.BufferGeometry();
@@ -710,11 +739,17 @@ export function createSpaceItem(model, deps) {
710
739
  // north up (the view above a satellite only): the picture is turned so north is at the top, less near a pole; a drag turns it from there
711
740
  const north = ride.view === "above" && ride.up === "north" ? northUpYaw(followed.place, followed.velocity) : null;
712
741
  const up = aboveAxes(followed.place, followed.velocity, base.yaw + (north ? north.yaw * north.weight : 0) + model.view.yaw * RAD, base.tilt + Math.max(-80, Math.min(80, model.view.tilt)) * RAD);
742
+ // a facing along the ground (ahead, behind, left, right) looks along the top `aboveAxes` gives, so that top would be the line of sight itself and the camera's turn would come from rounding, a different one each draw:
743
+ // the top of the picture is the sky there (straight away from the Earth, square to the line of sight)
744
+ const sky = unit(followed.place);
745
+ const skyward = sky[0] * up.offset[0] + sky[1] * up.offset[1] + sky[2] * up.offset[2];
746
+ const top = Math.abs(Math.sin(base.tilt)) > 0.5 ? unit([sky[0] - skyward * up.offset[0], sky[1] - skyward * up.offset[1], sky[2] - skyward * up.offset[2]]) : up.up;
713
747
  target.set(focusPos[0], focusPos[1], focusPos[2]);
714
748
  camera.position.set(target.x + up.offset[0] * distance, target.y + up.offset[1] * distance, target.z + up.offset[2] * distance);
715
- camera.up.set(up.up[0], up.up[1], up.up[2]);
716
- camera.lookAt(target);
717
749
  camera.near = Math.max(1e-4, distance * 0.02);
750
+ clearGround(camera, focusPos);
751
+ camera.up.set(top[0], top[1], top[2]);
752
+ camera.lookAt(target);
718
753
  camera.far = Math.max(2000, distance * 4 + (mode === "true" ? 40 * 23_481 : 400));
719
754
  }
720
755
  else {
@@ -724,9 +759,10 @@ export function createSpaceItem(model, deps) {
724
759
  target.set(focusPos[0], focusPos[1], focusPos[2]);
725
760
  camera.position.set(target.x + aim[0] * distance, target.y + aim[1] * distance, target.z + aim[2] * distance);
726
761
  camera.up.set(0, 1, 0);
727
- camera.lookAt(target);
728
762
  // within about 130 km of the ground (a fly-to's descent) the near plane comes in to half the height, or it would cut the ground away
729
763
  camera.near = Math.min(Math.max(0.0005, distance * 0.02 - focusRadius * 0.5, focusRadius * 0.01), Math.max(1e-6, (distance - focusRadius) * 0.5));
764
+ clearGround(camera, focusPos);
765
+ camera.lookAt(target);
730
766
  camera.far = Math.max(2000, distance * 4 + (mode === "true" ? 40 * 23_481 : 400));
731
767
  }
732
768
  if (ride && (ride.view === "follow" || ride.view === "above") && typeof ride.target !== "string") {
@@ -739,20 +775,30 @@ export function createSpaceItem(model, deps) {
739
775
  if (glide) {
740
776
  // a glide that follows the distance takes its length from how far the camera has to go, at its first frame
741
777
  if (glide.scaled) {
742
- const km = Math.hypot(camera.position.x - glide.from.p[0], camera.position.y - glide.from.p[1], camera.position.z - glide.from.p[2]) * 6371;
778
+ const km = glide.round ? satelliteGlideKm(glide.from.p, [camera.position.x, camera.position.y, camera.position.z]) : Math.hypot(camera.position.x - glide.from.p[0], camera.position.y - glide.from.p[1], camera.position.z - glide.from.p[2]) * 6371;
743
779
  glide.duration = rideGlideMs(km, glide.scaled.minMs, glide.scaled.maxMs);
744
780
  delete glide.scaled;
745
781
  }
746
782
  const k = Math.min(1, (performance.now() - glide.start) / glide.duration);
747
783
  const ease = k * k * (3 - 2 * k);
748
- desiredQ.copy(camera.quaternion);
749
- camera.position.set(glide.from.p[0] + (camera.position.x - glide.from.p[0]) * ease, glide.from.p[1] + (camera.position.y - glide.from.p[1]) * ease, glide.from.p[2] + (camera.position.z - glide.from.p[2]) * ease);
750
- fromQ.set(glide.from.q[0], glide.from.q[1], glide.from.q[2], glide.from.q[3]);
751
- camera.quaternion.copy(fromQ.slerp(desiredQ, ease));
784
+ if (glide.round) {
785
+ // from one satellite to another: round the Earth along the great circle, the look carried with it, so it never goes through the Earth and a facing stays level
786
+ const at = satelliteGlide(glide.from, { p: [camera.position.x, camera.position.y, camera.position.z], q: [camera.quaternion.x, camera.quaternion.y, camera.quaternion.z, camera.quaternion.w] }, ease);
787
+ camera.position.set(at.p[0], at.p[1], at.p[2]);
788
+ camera.quaternion.set(at.q[0], at.q[1], at.q[2], at.q[3]);
789
+ }
790
+ else {
791
+ desiredQ.copy(camera.quaternion);
792
+ camera.position.set(glide.from.p[0] + (camera.position.x - glide.from.p[0]) * ease, glide.from.p[1] + (camera.position.y - glide.from.p[1]) * ease, glide.from.p[2] + (camera.position.z - glide.from.p[2]) * ease);
793
+ fromQ.set(glide.from.q[0], glide.from.q[1], glide.from.q[2], glide.from.q[3]);
794
+ camera.quaternion.copy(fromQ.slerp(desiredQ, ease));
795
+ }
752
796
  fovNow = glide.from.fov + (fovNow - glide.from.fov) * ease;
753
797
  if (k >= 1)
754
798
  model.transition = null;
755
799
  }
800
+ // never under the ground: a ride from a satellite that has come down, or a glide whose straight line runs through the Earth, is held 1 km above it, on its line from the centre
801
+ clearGround(camera, null);
756
802
  camera.fov = fovNow;
757
803
  camera.aspect = size.width / Math.max(1, size.height);
758
804
  // the ground the picture spans straight below a ridden satellite, in kilometres: the height above the ground over the vertical field of view (flat-ground, to compare with a tile level's size)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/chikyu-earth",
3
- "version": "0.62.0",
3
+ "version": "0.64.0",
4
4
  "description": "Chikyu Earth 地球 — A line-drawn globe for the web: country outlines that turn at the Earth's own rate, centred on the place you give it, with an optional realistic Earth from space (three.js), the Sun, Moon and planets, satellites on their orbits, and markers for any place. A web component and an SVG string.",
5
5
  "keywords": [
6
6
  "earth",