@johnmorrisdotca/wakusei-planets 0.47.0 → 0.48.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 +4 -0
- package/README.md +4 -3
- package/dist/element.d.ts +38 -0
- package/dist/element.js +49 -5
- package/dist/scene/textures.d.ts +2 -2
- package/dist/space/element.d.ts +47 -1
- package/dist/space/element.js +101 -1
- package/dist/space/face.d.ts +132 -0
- package/dist/space/face.js +156 -0
- package/dist/space/index.d.ts +1 -0
- package/dist/space/index.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.48.0] - 2026-11-13
|
|
6
|
+
|
|
7
|
+
- **Which face of the body the view looks at** (MODULES-1330). `<wakusei-space>` has `subCameraPoint()`, the longitude (east) and latitude (north), in the centred body's own fixed frame at the moment shown, of the point under the camera (`null` while riding along), and `faceTo({ lon, lat }, { smooth })`, which turns the view round the body to bring a point there (the glide of `goToPlace`); `stats.camera.sub` says the same point as of the last draw. Beside a moon (`ride(moon, { view: "beside" })`, the way a moon is visited) `subCameraPoint()` is the point under the line from the moon's centre to the camera, and `faceTo` stands the camera as near that side as the view allows. `<wakusei-body>` has the same pair for its picture (the date's or the portrait's pose, the view's turn, tilt and roll counted in). The pure functions `subCameraPoint` and `faceView` are exported from `/space`, with `besideFace`, `facingPoint` and `surfaceDirection`. For a card picture that follows the main view, and the reverse. Guide: `docs/guides/which-face.md` and its Japanese twin.
|
|
8
|
+
|
|
5
9
|
## [0.47.0] - 2026-11-13
|
|
6
10
|
|
|
7
11
|
- **Things at the Apollo 17 site, at their published places** (MODULES-1308). The descent stage of the lunar module, the flag, the ALSEP central station, the surface electrical properties transmitter and the rover stand at the coordinates of Haase et al. (2019, doi 10.1029/2018EA000408; two small files read by byte range from the PDS archive of its map, NOTICE.md), drawn by this package as plain shapes with flat colours (an octagonal gold body on four splayed legs with braces, pads and the ladder; a frame on four wheels with fenders, seats, console, dish and camera masts) and cast shadows, and the rover's nine traverses as a faint pair of tracks along the published line. Each has a small pressable button (`choose(id)`, `objects`, the `wakusei-surface-object` event, `objects="off"`) that goes to it and says it was placed by this package; the rover's place is the end of its last traverse line and its heading a reading of it, both labelled ours. The made craters and rocks keep away from them.
|
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ Wakusei Planets runs in the browser of a phone, a tablet or a computer: nothing
|
|
|
19
19
|
|
|
20
20
|
<p align="center"><img alt="The demo on a desk: Saturn in the painted look, turning in the big view, with the page's links to the portrait builder, the colouring sheets, the space view, the star page and the size line-up above it, and the choice of body and its moons below" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-desk.webp" width="620"> <img alt="The same page on a phone: the same links in rows, and Saturn in the painted look below them" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-phone.webp" width="200"></p>
|
|
21
21
|
|
|
22
|
-
<p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.
|
|
22
|
+
<p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.48.0/docs/images/lineup-desk.png" width="640"></p>
|
|
23
23
|
|
|
24
24
|
## Who it is for
|
|
25
25
|
|
|
@@ -388,7 +388,7 @@ The tiles of every body share one 48 MB budget, six loads at a time for a source
|
|
|
388
388
|
|
|
389
389
|
## The portrait builder
|
|
390
390
|
|
|
391
|
-
<p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.
|
|
391
|
+
<p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.48.0/docs/images/portrait-family.png" width="640"></p>
|
|
392
392
|
|
|
393
393
|
[The portrait builder](https://johnmorrisdotca.github.io/wakusei-planets/portrait.html) puts any bodies in one picture: drag them, size them, turn them, order them front to back, arrange them in a row, an arc, a grid or at true orbit distance (true or readable sizes, a planet's moons round it in orbit order), light them from one direction, and take the code, a PNG or an SVG. The scene is kept in the address, and every body is drawn in one WebGL scene, so the page holds one WebGL context. [The portrait builder](docs/guides/portrait-builder.md) is its guide.
|
|
394
394
|
|
|
@@ -494,6 +494,7 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
|
|
|
494
494
|
| [Starman and the Tesla Roadster](docs/guides/roadster.md) | where the car launched on the first Falcon Heavy is on any date from 2018 to the start of 2036, its distances, speeds, orbit and key moments |
|
|
495
495
|
| [Comets](docs/guides/comets.md) | 34 well-known comets with orbits from JPL: where each is on any date, its distances, orbit line, last and next perihelion, meteor showers, and a door to add a new comet |
|
|
496
496
|
| [Places on the Moon, Mars and 31 more bodies](docs/guides/places.md) | every landing, rover, crash, impact and atmospheric-entry site and the named features of 33 bodies, with positions, dates and sources, the famous ones marked, and the Sun's point, the terminator and the local solar time on any body |
|
|
497
|
+
| [Which face of a body the view looks at](docs/guides/which-face.md) | `subCameraPoint()` and `faceTo()` on the space view and on a body's picture: the longitude and latitude under the camera, and a turn to a point, for a card picture that follows the view |
|
|
497
498
|
| [Data files](docs/guides/data-files.md) | CSV and Parquet tables of the bodies, orbits and spacecraft, for Python, R and Rust |
|
|
498
499
|
| [Serve it yourself](docs/guides/serve-it-yourself.md) | A small Node server over the package, that you host |
|
|
499
500
|
| [The Sun and Moon from a place](docs/guides/suncalc.md) | Position, sunrise and sunset, Moon rise, set and phase; a drop-in for suncalc |
|
|
@@ -535,7 +536,7 @@ BODIES.pluto.kind; // "dwarf-planet"
|
|
|
535
536
|
|
|
536
537
|
If this package helps a paper, a talk or a class, please cite it as software. GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA; in plain text:
|
|
537
538
|
|
|
538
|
-
> Morris, J. (2026). *Wakusei Planets* (version 0.
|
|
539
|
+
> Morris, J. (2026). *Wakusei Planets* (version 0.48.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
|
|
539
540
|
|
|
540
541
|
Cite the version you used (`npm ls @johnmorrisdotca/wakusei-planets`), and cite the sources of the numbers you use as well: [NOTICE.md](NOTICE.md) names each one, with the paper or the page it was read from (the IAU working group's report for sizes and poles, VSOP87B, ELP2000-82B, L1.2 and TASS1.7 for positions, and NASA's JPL Horizons for the fits and the spacecraft).
|
|
541
542
|
|
package/dist/element.d.ts
CHANGED
|
@@ -109,6 +109,44 @@ export declare class WakuseiBody extends HTMLElement {
|
|
|
109
109
|
x: number;
|
|
110
110
|
y: number;
|
|
111
111
|
}[];
|
|
112
|
+
/**
|
|
113
|
+
* Which point of the body is in the middle of the picture, as a longitude (east) and latitude (north) in the body's own fixed frame: what the camera looks straight down on, with the view's turn, tilt
|
|
114
|
+
* and roll and the pose of the date (or the portrait) counted in. `faceTo` is the other way round. `undefined` for a star.
|
|
115
|
+
*
|
|
116
|
+
* @returns The point, or `undefined`.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts no-run
|
|
120
|
+
* import type { WakuseiBody } from "@johnmorrisdotca/wakusei-planets/element";
|
|
121
|
+
*
|
|
122
|
+
* const body = document.querySelector<WakuseiBody>("wakusei-body")!;
|
|
123
|
+
* console.log(body.subCameraPoint());
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
subCameraPoint(): {
|
|
127
|
+
lon: number;
|
|
128
|
+
lat: number;
|
|
129
|
+
} | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* Turn the body so a point of it (east longitude, north latitude, degrees) is in the middle of the disc: the turn `goToPlace` makes, for a point instead of a named place (at once for a still, for a reader who
|
|
132
|
+
* prefers reduced motion, or with `smooth: false`); the zoom stays.
|
|
133
|
+
*
|
|
134
|
+
* @param point - The longitude and latitude to bring to the middle.
|
|
135
|
+
* @param options - `smooth` (true by default).
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts no-run
|
|
139
|
+
* import type { WakuseiBody } from "@johnmorrisdotca/wakusei-planets/element";
|
|
140
|
+
*
|
|
141
|
+
* document.querySelector<WakuseiBody>("wakusei-body")!.faceTo({ lon: 139.7, lat: 35.7 }, { smooth: false });
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
faceTo(point: {
|
|
145
|
+
lon: number;
|
|
146
|
+
lat: number;
|
|
147
|
+
}, options?: {
|
|
148
|
+
smooth?: boolean;
|
|
149
|
+
}): void;
|
|
112
150
|
/**
|
|
113
151
|
* Turn the body so a place is in the middle of the disc, at a pace you can follow while the picture is live (at once for a still, for a reader who prefers reduced motion, or with `smooth: false`); the zoom stays. The place is an id (`moon/apollo-11-lunar-module`),
|
|
114
152
|
* or an English or Japanese name. A body that turns by itself carries the place on from there (`turn="0"` keeps it). Resolves the place, or `undefined` when the body has no place by that name.
|
package/dist/element.js
CHANGED
|
@@ -21,7 +21,7 @@ import { createBodyItem } from "./scene/body.js";
|
|
|
21
21
|
import { NAME_LABEL_ATTRIBUTES, nameLabelKey, nameLabelText, readNameLabel } from "./scene/name-label.js";
|
|
22
22
|
import { delegates, onRegister } from "./scene/store.js";
|
|
23
23
|
import { setThreeLoader, takeRenderer } from "./scene/shared.js";
|
|
24
|
-
import { turn as turnVec } from "./vec.js";
|
|
24
|
+
import { cross, RAD, turn as turnVec } from "./vec.js";
|
|
25
25
|
import { findPlace, PLACE_BODIES } from "./places.js";
|
|
26
26
|
import { marksToShow, readPlaceLayers, readSurfaceNames, turnToPlace } from "./place-marks.js";
|
|
27
27
|
import { createPlaceLayer, onPlacesLoader, placesLoader } from "./scene/place-layer.js";
|
|
@@ -291,6 +291,46 @@ export class WakuseiBody extends HTMLElement {
|
|
|
291
291
|
get placesShown() {
|
|
292
292
|
return this.#placeLayer?.shown ?? [];
|
|
293
293
|
}
|
|
294
|
+
/**
|
|
295
|
+
* Which point of the body is in the middle of the picture, as a longitude (east) and latitude (north) in the body's own fixed frame: what the camera looks straight down on, with the view's turn, tilt
|
|
296
|
+
* and roll and the pose of the date (or the portrait) counted in. `faceTo` is the other way round. `undefined` for a star.
|
|
297
|
+
*
|
|
298
|
+
* @returns The point, or `undefined`.
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```ts no-run
|
|
302
|
+
* import type { WakuseiBody } from "@johnmorrisdotca/wakusei-planets/element";
|
|
303
|
+
*
|
|
304
|
+
* const body = document.querySelector<WakuseiBody>("wakusei-body")!;
|
|
305
|
+
* console.log(body.subCameraPoint());
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
308
|
+
subCameraPoint() {
|
|
309
|
+
if (this.hasAttribute("star"))
|
|
310
|
+
return undefined;
|
|
311
|
+
const { pose } = this.#sceneOf(this.#frameNow());
|
|
312
|
+
const east = cross(pose.pole, pose.meridian);
|
|
313
|
+
return { lon: Math.atan2(east[2], pose.meridian[2]) / RAD, lat: Math.asin(Math.max(-1, Math.min(1, pose.pole[2]))) / RAD };
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Turn the body so a point of it (east longitude, north latitude, degrees) is in the middle of the disc: the turn `goToPlace` makes, for a point instead of a named place (at once for a still, for a reader who
|
|
317
|
+
* prefers reduced motion, or with `smooth: false`); the zoom stays.
|
|
318
|
+
*
|
|
319
|
+
* @param point - The longitude and latitude to bring to the middle.
|
|
320
|
+
* @param options - `smooth` (true by default).
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```ts no-run
|
|
324
|
+
* import type { WakuseiBody } from "@johnmorrisdotca/wakusei-planets/element";
|
|
325
|
+
*
|
|
326
|
+
* document.querySelector<WakuseiBody>("wakusei-body")!.faceTo({ lon: 139.7, lat: 35.7 }, { smooth: false });
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
faceTo(point, options = {}) {
|
|
330
|
+
if (this.hasAttribute("star") || !Number.isFinite(point.lon) || !Number.isFinite(point.lat))
|
|
331
|
+
return;
|
|
332
|
+
this.#turnTo(point.lat, point.lon, options.smooth);
|
|
333
|
+
}
|
|
294
334
|
/**
|
|
295
335
|
* Turn the body so a place is in the middle of the disc, at a pace you can follow while the picture is live (at once for a still, for a reader who prefers reduced motion, or with `smooth: false`); the zoom stays. The place is an id (`moon/apollo-11-lunar-module`),
|
|
296
336
|
* or an English or Japanese name. A body that turns by itself carries the place on from there (`turn="0"` keeps it). Resolves the place, or `undefined` when the body has no place by that name.
|
|
@@ -304,8 +344,13 @@ export class WakuseiBody extends HTMLElement {
|
|
|
304
344
|
const place = list === undefined ? undefined : findPlace(list, text);
|
|
305
345
|
if (place === undefined)
|
|
306
346
|
return undefined;
|
|
347
|
+
this.#turnTo(place.lat, place.lon, options.smooth);
|
|
348
|
+
return place;
|
|
349
|
+
}
|
|
350
|
+
/** Turn the body so a point of it (latitude, east longitude, degrees) is in the middle of the disc: the glide of `goToPlace` and `faceTo`. */
|
|
351
|
+
#turnTo(lat, lon, smooth) {
|
|
307
352
|
const frame = this.#frameNow();
|
|
308
|
-
const aim = turnToPlace(frame.pose.pole, frame.pose.meridian,
|
|
353
|
+
const aim = turnToPlace(frame.pose.pole, frame.pose.meridian, lat, lon);
|
|
309
354
|
const to = { yaw: aim.yaw, tilt: this.#pitchDelta - aim.tilt };
|
|
310
355
|
const from = { yaw: this.#yaw, tilt: this.#tilt };
|
|
311
356
|
// the shorter way round
|
|
@@ -319,9 +364,9 @@ export class WakuseiBody extends HTMLElement {
|
|
|
319
364
|
};
|
|
320
365
|
const glide = (this.#placeGlide += 1);
|
|
321
366
|
// a still (not live) is made again for every change of view: it goes there at once
|
|
322
|
-
if (
|
|
367
|
+
if (smooth === false || this.#reduce || this.#view?.live !== true || typeof requestAnimationFrame !== "function") {
|
|
323
368
|
apply(to.yaw, to.tilt, true);
|
|
324
|
-
return
|
|
369
|
+
return;
|
|
325
370
|
}
|
|
326
371
|
const start = performance.now();
|
|
327
372
|
const step = () => {
|
|
@@ -334,7 +379,6 @@ export class WakuseiBody extends HTMLElement {
|
|
|
334
379
|
requestAnimationFrame(step);
|
|
335
380
|
};
|
|
336
381
|
requestAnimationFrame(step);
|
|
337
|
-
return place;
|
|
338
382
|
}
|
|
339
383
|
/** The body's list of places, loaded the first time it is asked for; `undefined` for a body that has none. */
|
|
340
384
|
async #loadPlaces() {
|
package/dist/scene/textures.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { type BodyMapSource } from "../door/map.ts";
|
|
|
11
11
|
* console.log(TEXTURE_BASE);
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
|
-
export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.
|
|
14
|
+
export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.48.0/dist/textures/";
|
|
15
15
|
/**
|
|
16
16
|
* Where the sharpest surface pictures are: the files of this exact version in the repository, on jsDelivr's GitHub address. The npm package holds only the two smaller widths, so a page that
|
|
17
17
|
* never zooms in never fetches them. Set `texture-far-base` on an element to serve them yourself.
|
|
@@ -23,7 +23,7 @@ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdot
|
|
|
23
23
|
* console.log(TEXTURE_FAR_BASE);
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
|
-
export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.
|
|
26
|
+
export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.48.0/textures/";
|
|
27
27
|
/**
|
|
28
28
|
* Where the finer map tiles are by default: the demo site's `tiles/` folder (GitHub Pages sends `access-control-allow-origin: *`). The tiles are made by `scripts/make-body-tiles.py` and are in no package and no repository:
|
|
29
29
|
* a page that serves its own gives the folder in the `tiles` attribute, and `tiles="off"` turns them off. A page that sets `texture-base` (it serves its own pictures) has none unless it says where they are.
|
package/dist/space/element.d.ts
CHANGED
|
@@ -245,6 +245,48 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
245
245
|
smooth?: boolean;
|
|
246
246
|
zoom?: number;
|
|
247
247
|
}): Promise<Place | undefined>;
|
|
248
|
+
/**
|
|
249
|
+
* Which point of the body in the middle of the view is under the camera, as a longitude (east) and latitude (north) in the body's own fixed frame at the moment shown: the camera looks along the line
|
|
250
|
+
* from that point through the body's centre. It carries the body's spin and, for the Moon, the way its pole and prime meridian are set; a camera held in the stars sees the body turn under it, so the same
|
|
251
|
+
* view names another point as the clock runs. Beside a moon (`ride(moon, { view: "beside" })`, the way a moon is visited) it is the point under the line from the moon's centre to the camera. `null` while the camera is riding along with anything else. `faceTo` is the other way round.
|
|
252
|
+
*
|
|
253
|
+
* @returns The point, or `null`.
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* ```ts no-run
|
|
257
|
+
* import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
258
|
+
*
|
|
259
|
+
* const space = document.querySelector<WakuseiSpace>("wakusei-space")!;
|
|
260
|
+
* space.goTo("moon");
|
|
261
|
+
* console.log(space.subCameraPoint());
|
|
262
|
+
* ```
|
|
263
|
+
*/
|
|
264
|
+
subCameraPoint(): {
|
|
265
|
+
lon: number;
|
|
266
|
+
lat: number;
|
|
267
|
+
} | null;
|
|
268
|
+
/**
|
|
269
|
+
* Turn the view round the body in the middle so that a point of its surface (east longitude, north latitude, degrees) is under the camera: a glide the way `goToPlace` goes (at once with `smooth: false`
|
|
270
|
+
* or for a reader who prefers reduced motion); the zoom stays. The turn is the shorter way round and never through the body. Beside a moon it stands the camera as near the side the point is on as the view allows (the camera keeps beyond the moon, off the line to its planet). Returns false while the camera is riding along with anything else.
|
|
271
|
+
*
|
|
272
|
+
* @param point - The longitude and latitude to bring to the middle.
|
|
273
|
+
* @param options - `smooth` (true by default).
|
|
274
|
+
* @returns Whether the turn was made.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts no-run
|
|
278
|
+
* import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
279
|
+
*
|
|
280
|
+
* const space = document.querySelector<WakuseiSpace>("wakusei-space")!;
|
|
281
|
+
* space.faceTo({ lon: 30.8, lat: 20.2 }, { smooth: false });
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
faceTo(point: {
|
|
285
|
+
lon: number;
|
|
286
|
+
lat: number;
|
|
287
|
+
}, options?: {
|
|
288
|
+
smooth?: boolean;
|
|
289
|
+
}): boolean;
|
|
248
290
|
/**
|
|
249
291
|
* The name written on each body's globe (`{ look: "painted", strength: 0.5, repeat: "once", latitude: 0, facing: false, font: "Michroma", fallbackFont: "" }`), or `null` for none. Set, it takes the place of the
|
|
250
292
|
* `body-label` attributes; set to `undefined` the attributes are read again. The text is each body's own name in the element's `lang` (capitals in English). A body too small on the screen (24 CSS pixels of radius by default) carries none.
|
|
@@ -565,7 +607,11 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
565
607
|
position: [number, number, number];
|
|
566
608
|
fov: number;
|
|
567
609
|
up: [number, number, number];
|
|
568
|
-
forward: [number, number, number];
|
|
610
|
+
forward: [number, number, number]; /** The point of the body in the middle that is under the camera (`subCameraPoint`), or `null` while riding. */
|
|
611
|
+
sub: {
|
|
612
|
+
lon: number;
|
|
613
|
+
lat: number;
|
|
614
|
+
} | null;
|
|
569
615
|
};
|
|
570
616
|
/** What the painter has made at the last draw: the bodies with a drawing, the moons shown round a planet that is near, and the moons made and not yet let go. */
|
|
571
617
|
bodies: {
|
package/dist/space/element.js
CHANGED
|
@@ -19,6 +19,7 @@ import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, frameAt, SPACE_DWARFS, SPACE_MINORS
|
|
|
19
19
|
import { moonOffset, orientation } from "../scene/orient.js";
|
|
20
20
|
import { moonDistance, placeBodies, radiusIn, readMoonSize } from "./scale.js";
|
|
21
21
|
import { groundDirection } from "./aim.js";
|
|
22
|
+
import { besideFace, faceView, facingPoint, subCameraPoint } from "./face.js";
|
|
22
23
|
import { besideMoon } from "./beside.js";
|
|
23
24
|
import { SUN_REGIONS } from "./regions.js";
|
|
24
25
|
import { travelArrival } from "./travel.js";
|
|
@@ -549,6 +550,105 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
549
550
|
requestAnimationFrame(step);
|
|
550
551
|
return place;
|
|
551
552
|
}
|
|
553
|
+
/**
|
|
554
|
+
* Which point of the body in the middle of the view is under the camera, as a longitude (east) and latitude (north) in the body's own fixed frame at the moment shown: the camera looks along the line
|
|
555
|
+
* from that point through the body's centre. It carries the body's spin and, for the Moon, the way its pole and prime meridian are set; a camera held in the stars sees the body turn under it, so the same
|
|
556
|
+
* view names another point as the clock runs. Beside a moon (`ride(moon, { view: "beside" })`, the way a moon is visited) it is the point under the line from the moon's centre to the camera. `null` while the camera is riding along with anything else. `faceTo` is the other way round.
|
|
557
|
+
*
|
|
558
|
+
* @returns The point, or `null`.
|
|
559
|
+
*
|
|
560
|
+
* @example
|
|
561
|
+
* ```ts no-run
|
|
562
|
+
* import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
563
|
+
*
|
|
564
|
+
* const space = document.querySelector<WakuseiSpace>("wakusei-space")!;
|
|
565
|
+
* space.goTo("moon");
|
|
566
|
+
* console.log(space.subCameraPoint());
|
|
567
|
+
* ```
|
|
568
|
+
*/
|
|
569
|
+
subCameraPoint() {
|
|
570
|
+
const model = this.#model;
|
|
571
|
+
const ride = model.ride;
|
|
572
|
+
if (ride !== null) {
|
|
573
|
+
// beside a moon (the way a moon is visited): the camera stands outside it, so the point is the one under the line from the moon's centre to the camera as the last draw left it
|
|
574
|
+
if (ride.view !== "beside" || typeof ride.target !== "string")
|
|
575
|
+
return null;
|
|
576
|
+
// worked out from the view as it is now (the camera `besideMoon` gives for it), not from the last draw, so a turn just made is already counted
|
|
577
|
+
const moon = ride.target;
|
|
578
|
+
const camera = besideMoon({ ...this.#besideInput(moon), zoom: model.view.zoom, yaw: model.view.yaw, tilt: model.view.tilt });
|
|
579
|
+
const here = this.#site(moon).at;
|
|
580
|
+
const away = [camera.position[0] - here[0], camera.position[1] - here[1], camera.position[2] - here[2]];
|
|
581
|
+
return length(away) < 1e-12 ? null : facingPoint(moon, away, model.time);
|
|
582
|
+
}
|
|
583
|
+
return subCameraPoint(model.focus, model.view, model.centre, model.anchor ?? model.time, model.time);
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Turn the view round the body in the middle so that a point of its surface (east longitude, north latitude, degrees) is under the camera: a glide the way `goToPlace` goes (at once with `smooth: false`
|
|
587
|
+
* or for a reader who prefers reduced motion); the zoom stays. The turn is the shorter way round and never through the body. Beside a moon it stands the camera as near the side the point is on as the view allows (the camera keeps beyond the moon, off the line to its planet). Returns false while the camera is riding along with anything else.
|
|
588
|
+
*
|
|
589
|
+
* @param point - The longitude and latitude to bring to the middle.
|
|
590
|
+
* @param options - `smooth` (true by default).
|
|
591
|
+
* @returns Whether the turn was made.
|
|
592
|
+
*
|
|
593
|
+
* @example
|
|
594
|
+
* ```ts no-run
|
|
595
|
+
* import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
596
|
+
*
|
|
597
|
+
* const space = document.querySelector<WakuseiSpace>("wakusei-space")!;
|
|
598
|
+
* space.faceTo({ lon: 30.8, lat: 20.2 }, { smooth: false });
|
|
599
|
+
* ```
|
|
600
|
+
*/
|
|
601
|
+
faceTo(point, options = {}) {
|
|
602
|
+
const model = this.#model;
|
|
603
|
+
if (!Number.isFinite(point.lon) || !Number.isFinite(point.lat))
|
|
604
|
+
return false;
|
|
605
|
+
const ride = model.ride;
|
|
606
|
+
if (ride !== null && (ride.view !== "beside" || typeof ride.target !== "string"))
|
|
607
|
+
return false;
|
|
608
|
+
model.anchor ??= model.time;
|
|
609
|
+
const from = { ...model.view };
|
|
610
|
+
let to;
|
|
611
|
+
if (ride !== null) {
|
|
612
|
+
// beside a moon: the pair of the ride's yaw and tilt that stands the camera nearest the side of the moon the point is on (the view keeps the camera beyond the moon, so some sides are only approached)
|
|
613
|
+
const moon = ride.target;
|
|
614
|
+
const { moon: at, moonRadius, host, hostRadius, sun, north, aspect } = this.#besideInput(moon);
|
|
615
|
+
const found = besideFace({ moon: at, moonRadius, host, hostRadius, sun, north, aspect, zoom: from.zoom }, moon, point, model.time);
|
|
616
|
+
to = { yaw: from.yaw + ((((found.yaw - from.yaw + 180) % 360) + 360) % 360) - 180, tilt: found.tilt };
|
|
617
|
+
}
|
|
618
|
+
else
|
|
619
|
+
to = faceView(model.focus, point, model.centre, model.anchor, model.time, from.yaw);
|
|
620
|
+
const apply = (yaw, tilt, final) => {
|
|
621
|
+
if (this.#hands !== undefined && !this.hasAttribute("data-kazoku-bar"))
|
|
622
|
+
this.#hands.controller.set({ yaw, tilt, zoom: from.zoom }, final, "place");
|
|
623
|
+
else
|
|
624
|
+
this.setView({ yaw, tilt, zoom: from.zoom, roll: from.roll, panX: from.panX, panY: from.panY }, final);
|
|
625
|
+
};
|
|
626
|
+
const glide = (this.#placeGlide += 1);
|
|
627
|
+
const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
628
|
+
if (options.smooth === false || reduced || typeof requestAnimationFrame !== "function") {
|
|
629
|
+
apply(to.yaw, to.tilt, true);
|
|
630
|
+
return true;
|
|
631
|
+
}
|
|
632
|
+
const start = performance.now();
|
|
633
|
+
const step = () => {
|
|
634
|
+
if (glide !== this.#placeGlide || !this.isConnected)
|
|
635
|
+
return;
|
|
636
|
+
const k = Math.min(1, (performance.now() - start) / 900);
|
|
637
|
+
const ease = k * k * (3 - 2 * k);
|
|
638
|
+
apply(from.yaw + (to.yaw - from.yaw) * ease, from.tilt + (to.tilt - from.tilt) * ease, k >= 1);
|
|
639
|
+
if (k < 1)
|
|
640
|
+
requestAnimationFrame(step);
|
|
641
|
+
};
|
|
642
|
+
requestAnimationFrame(step);
|
|
643
|
+
return true;
|
|
644
|
+
}
|
|
645
|
+
/** What `besideMoon` is given for a moon, without the view's zoom, yaw and tilt: the places and sizes the scene draws with, worked out the same way. */
|
|
646
|
+
#besideInput(moon) {
|
|
647
|
+
const host = (hostOf(moon) ?? "earth");
|
|
648
|
+
const m = this.#site(moon), h = this.#site(host);
|
|
649
|
+
const aspect = this.clientWidth > 0 && this.clientHeight > 0 ? this.clientWidth / this.clientHeight : 16 / 9;
|
|
650
|
+
return { moon: m.at, moonRadius: m.radius, host: h.at, hostRadius: h.radius, sun: this.#site("sun").at, north: orientation(host, this.#model.time).pole, aspect };
|
|
651
|
+
}
|
|
552
652
|
#readEarthPlaces() {
|
|
553
653
|
const text = this.getAttribute("earth-places");
|
|
554
654
|
const using = earthPlacesLayout();
|
|
@@ -1771,7 +1871,7 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1771
1871
|
assets: { entries: stats?.assets.entries ?? 0, refs: stats?.assets.refs ?? 0 },
|
|
1772
1872
|
time: this.time,
|
|
1773
1873
|
lookups: this.#model.lookups,
|
|
1774
|
-
camera: { position: [...this.#model.camera.position], fov: this.#model.camera.fov, up: [...this.#model.camera.up], forward: [...this.#model.camera.forward] },
|
|
1874
|
+
camera: { position: [...this.#model.camera.position], fov: this.#model.camera.fov, up: [...this.#model.camera.up], forward: [...this.#model.camera.forward], sub: this.subCameraPoint() },
|
|
1775
1875
|
bodies: { look: this.#model.look, painted: this.#model.painted.bodies, moons: this.#model.painted.moons, held: this.#model.painted.held },
|
|
1776
1876
|
tiles: { ...this.#model.tiles },
|
|
1777
1877
|
door: { points: this.#model.door.points, belts: this.#model.door.belts, draws: this.#model.door.draws, sources: this.#door.book.stats() },
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { BodyId } from "../facts.ts";
|
|
2
|
+
import { type Vec3 } from "../vec.ts";
|
|
3
|
+
import { type BesideInput } from "./beside.ts";
|
|
4
|
+
/**
|
|
5
|
+
* A place on a body's surface: east longitude and north latitude in the body's own fixed frame, degrees.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts no-run
|
|
9
|
+
* import type { Face } from "@johnmorrisdotca/wakusei-planets/space";
|
|
10
|
+
*
|
|
11
|
+
* const tranquility: Face = { lon: 23.47, lat: 0.67 };
|
|
12
|
+
* console.log(tranquility.lat);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export interface Face {
|
|
16
|
+
lon: number;
|
|
17
|
+
lat: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The camera's turn: the view's yaw and tilt, degrees (the view's `center` is given beside it, and the aim is counted from that).
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts no-run
|
|
24
|
+
* import type { FaceView } from "@johnmorrisdotca/wakusei-planets/space";
|
|
25
|
+
*
|
|
26
|
+
* const view: FaceView = { yaw: 30, tilt: -10 };
|
|
27
|
+
* console.log(view.yaw);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export interface FaceView {
|
|
31
|
+
yaw: number;
|
|
32
|
+
tilt: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The longitude and latitude, on the body in the middle of the space view, of the point under the camera: the camera looks along the line from that point through the body's centre. It is the camera's
|
|
36
|
+
* direction (the Earth's ground direction of `center` less the yaw and tilt, as the stars saw it at `anchor`) put into the body's own frame (its pole and prime meridian at `time`, which carry its spin
|
|
37
|
+
* and, for the Moon, its libration). A body that turns with the clock moves under a camera held in the stars, so the same view names another face a minute later.
|
|
38
|
+
*
|
|
39
|
+
* @param body - The body in the middle of the view.
|
|
40
|
+
* @param view - The view's yaw and tilt, degrees.
|
|
41
|
+
* @param centre - The view's `center` (longitude and latitude, degrees).
|
|
42
|
+
* @param anchor - The moment the camera was last pointed, in milliseconds since the Unix epoch.
|
|
43
|
+
* @param time - The moment shown.
|
|
44
|
+
* @returns The point under the camera, longitude from -180 to 180 and latitude from -90 to 90.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* import { subCameraPoint } from "@johnmorrisdotca/wakusei-planets/space";
|
|
49
|
+
*
|
|
50
|
+
* const at = subCameraPoint("moon", { yaw: 0, tilt: 0 }, { lon: 0, lat: 0 }, Date.UTC(2026, 10, 2), Date.UTC(2026, 10, 2));
|
|
51
|
+
* console.log(at.lon.toFixed(0), at.lat.toFixed(0));
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function subCameraPoint(body: BodyId, view: FaceView, centre: Face, anchor: number, time: number): Face;
|
|
55
|
+
/**
|
|
56
|
+
* The yaw and tilt that put a point of the body under the camera: the other way round from {@link subCameraPoint}, for the same centre, anchor and moment. The yaw is the shorter way round from `from`.
|
|
57
|
+
*
|
|
58
|
+
* @param body - The body in the middle of the view.
|
|
59
|
+
* @param face - The point to bring to the middle.
|
|
60
|
+
* @param centre - The view's `center`.
|
|
61
|
+
* @param anchor - The moment the camera was last pointed.
|
|
62
|
+
* @param time - The moment shown.
|
|
63
|
+
* @param from - The yaw the view has now, so that the turn is the shorter way (0 when left out).
|
|
64
|
+
* @returns The yaw and tilt to give the view.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { faceView, subCameraPoint } from "@johnmorrisdotca/wakusei-planets/space";
|
|
69
|
+
*
|
|
70
|
+
* const ms = Date.UTC(2026, 10, 2);
|
|
71
|
+
* const turn = faceView("mars", { lon: 100, lat: 20 }, { lon: 0, lat: 0 }, ms, ms);
|
|
72
|
+
* console.log(subCameraPoint("mars", turn, { lon: 0, lat: 0 }, ms, ms));
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export declare function faceView(body: BodyId, face: Face, centre: Face, anchor: number, time: number, from?: number): FaceView;
|
|
76
|
+
/**
|
|
77
|
+
* The longitude and latitude on a body of a direction from its centre in the scene's axes: what a camera standing along that direction has under it. The body's pole and prime meridian are those at `time`.
|
|
78
|
+
*
|
|
79
|
+
* @param body - The body.
|
|
80
|
+
* @param direction - A direction from the body's centre (any length).
|
|
81
|
+
* @param time - The moment, in milliseconds since the Unix epoch.
|
|
82
|
+
* @returns The point on the body under that direction.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* import { facingPoint } from "@johnmorrisdotca/wakusei-planets/space";
|
|
87
|
+
*
|
|
88
|
+
* const ms = Date.UTC(2026, 10, 2);
|
|
89
|
+
* console.log(facingPoint("moon", [0, 1, 0], ms));
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export declare function facingPoint(body: BodyId, direction: Vec3, time: number): Face;
|
|
93
|
+
/**
|
|
94
|
+
* The direction from a body's centre, in the scene's axes, of a point on its surface at a moment: the unit vector the other way from {@link facingPoint}.
|
|
95
|
+
*
|
|
96
|
+
* @param body - The body.
|
|
97
|
+
* @param face - The point on its surface.
|
|
98
|
+
* @param time - The moment, in milliseconds since the Unix epoch.
|
|
99
|
+
* @returns The unit direction.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { surfaceDirection } from "@johnmorrisdotca/wakusei-planets/space";
|
|
104
|
+
*
|
|
105
|
+
* console.log(surfaceDirection("moon", { lon: 0, lat: 0 }, Date.UTC(2026, 10, 2)).map((n) => n.toFixed(2)));
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare function surfaceDirection(body: BodyId, face: Face, time: number): Vec3;
|
|
109
|
+
/**
|
|
110
|
+
* The yaw and tilt of a camera beside a moon (the view `ride(moon, { view: "beside" })` gives) that put it on the side of the moon the point is on: the camera stands along the direction from the moon's
|
|
111
|
+
* centre through the point. The camera there is placed by `besideMoon` (beyond the moon, off the line to its planet), so not every point can be reached: the pair returned brings the camera as near as
|
|
112
|
+
* the view goes, and `error` says by how many degrees it is still off.
|
|
113
|
+
*
|
|
114
|
+
* @param input - What `besideMoon` is given, without the yaw and tilt.
|
|
115
|
+
* @param body - The moon.
|
|
116
|
+
* @param face - The point to bring under the camera.
|
|
117
|
+
* @param time - The moment shown.
|
|
118
|
+
* @returns The yaw and tilt, and the angle in degrees between the camera's direction and the wanted one.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* import { besideFace } from "@johnmorrisdotca/wakusei-planets/space";
|
|
123
|
+
*
|
|
124
|
+
* const input = { moon: [60, 0, 0], moonRadius: 0.273, host: [0, 0, 0], hostRadius: 1, sun: [-23000, 0, 0], aspect: 1.6, zoom: 1 } as const;
|
|
125
|
+
* console.log(besideFace(input, "moon", { lon: 180, lat: 0 }, Date.UTC(2026, 10, 2)).error < 90);
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export declare function besideFace(input: Omit<BesideInput, "yaw" | "tilt">, body: BodyId, face: Face, time: number): {
|
|
129
|
+
yaw: number;
|
|
130
|
+
tilt: number;
|
|
131
|
+
error: number;
|
|
132
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Which face of the centred body the space view looks at, and the turn that brings a face to the middle: the camera's direction in the body's own fixed frame. Pure.
|
|
2
|
+
import { orientation } from "../scene/orient.js";
|
|
3
|
+
import { cross, dot, RAD, unit } from "../vec.js";
|
|
4
|
+
import { groundDirection } from "./aim.js";
|
|
5
|
+
import { besideMoon } from "./beside.js";
|
|
6
|
+
const wrap = (deg) => ((((deg + 180) % 360) + 360) % 360) - 180;
|
|
7
|
+
/**
|
|
8
|
+
* The longitude and latitude, on the body in the middle of the space view, of the point under the camera: the camera looks along the line from that point through the body's centre. It is the camera's
|
|
9
|
+
* direction (the Earth's ground direction of `center` less the yaw and tilt, as the stars saw it at `anchor`) put into the body's own frame (its pole and prime meridian at `time`, which carry its spin
|
|
10
|
+
* and, for the Moon, its libration). A body that turns with the clock moves under a camera held in the stars, so the same view names another face a minute later.
|
|
11
|
+
*
|
|
12
|
+
* @param body - The body in the middle of the view.
|
|
13
|
+
* @param view - The view's yaw and tilt, degrees.
|
|
14
|
+
* @param centre - The view's `center` (longitude and latitude, degrees).
|
|
15
|
+
* @param anchor - The moment the camera was last pointed, in milliseconds since the Unix epoch.
|
|
16
|
+
* @param time - The moment shown.
|
|
17
|
+
* @returns The point under the camera, longitude from -180 to 180 and latitude from -90 to 90.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { subCameraPoint } from "@johnmorrisdotca/wakusei-planets/space";
|
|
22
|
+
*
|
|
23
|
+
* const at = subCameraPoint("moon", { yaw: 0, tilt: 0 }, { lon: 0, lat: 0 }, Date.UTC(2026, 10, 2), Date.UTC(2026, 10, 2));
|
|
24
|
+
* console.log(at.lon.toFixed(0), at.lat.toFixed(0));
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function subCameraPoint(body, view, centre, anchor, time) {
|
|
28
|
+
const d = groundDirection(centre.lon - view.yaw, Math.max(-90, Math.min(90, centre.lat - view.tilt)), anchor);
|
|
29
|
+
const { pole, meridian } = orientation(body, time);
|
|
30
|
+
const east = cross(pole, meridian);
|
|
31
|
+
return { lon: Math.atan2(dot(d, east), dot(d, meridian)) / RAD, lat: Math.asin(Math.max(-1, Math.min(1, dot(d, pole)))) / RAD };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The yaw and tilt that put a point of the body under the camera: the other way round from {@link subCameraPoint}, for the same centre, anchor and moment. The yaw is the shorter way round from `from`.
|
|
35
|
+
*
|
|
36
|
+
* @param body - The body in the middle of the view.
|
|
37
|
+
* @param face - The point to bring to the middle.
|
|
38
|
+
* @param centre - The view's `center`.
|
|
39
|
+
* @param anchor - The moment the camera was last pointed.
|
|
40
|
+
* @param time - The moment shown.
|
|
41
|
+
* @param from - The yaw the view has now, so that the turn is the shorter way (0 when left out).
|
|
42
|
+
* @returns The yaw and tilt to give the view.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { faceView, subCameraPoint } from "@johnmorrisdotca/wakusei-planets/space";
|
|
47
|
+
*
|
|
48
|
+
* const ms = Date.UTC(2026, 10, 2);
|
|
49
|
+
* const turn = faceView("mars", { lon: 100, lat: 20 }, { lon: 0, lat: 0 }, ms, ms);
|
|
50
|
+
* console.log(subCameraPoint("mars", turn, { lon: 0, lat: 0 }, ms, ms));
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export function faceView(body, face, centre, anchor, time, from = 0) {
|
|
54
|
+
const { pole, meridian } = orientation(body, time);
|
|
55
|
+
const east = cross(pole, meridian);
|
|
56
|
+
const c = Math.cos(face.lat * RAD);
|
|
57
|
+
const d = [0, 1, 2].map((i) => c * Math.cos(face.lon * RAD) * meridian[i] + c * Math.sin(face.lon * RAD) * east[i] + Math.sin(face.lat * RAD) * pole[i]);
|
|
58
|
+
const earth = orientation("earth", anchor);
|
|
59
|
+
const lat = Math.asin(Math.max(-1, Math.min(1, dot(d, earth.pole)))) / RAD;
|
|
60
|
+
const lon = Math.atan2(dot(d, cross(earth.pole, earth.meridian)), dot(d, earth.meridian)) / RAD;
|
|
61
|
+
const yaw = centre.lon - lon;
|
|
62
|
+
return { yaw: from + wrap(yaw - from), tilt: centre.lat - lat };
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The longitude and latitude on a body of a direction from its centre in the scene's axes: what a camera standing along that direction has under it. The body's pole and prime meridian are those at `time`.
|
|
66
|
+
*
|
|
67
|
+
* @param body - The body.
|
|
68
|
+
* @param direction - A direction from the body's centre (any length).
|
|
69
|
+
* @param time - The moment, in milliseconds since the Unix epoch.
|
|
70
|
+
* @returns The point on the body under that direction.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { facingPoint } from "@johnmorrisdotca/wakusei-planets/space";
|
|
75
|
+
*
|
|
76
|
+
* const ms = Date.UTC(2026, 10, 2);
|
|
77
|
+
* console.log(facingPoint("moon", [0, 1, 0], ms));
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export function facingPoint(body, direction, time) {
|
|
81
|
+
const d = unit(direction);
|
|
82
|
+
const { pole, meridian } = orientation(body, time);
|
|
83
|
+
const east = cross(pole, meridian);
|
|
84
|
+
return { lon: Math.atan2(dot(d, east), dot(d, meridian)) / RAD, lat: Math.asin(Math.max(-1, Math.min(1, dot(d, pole)))) / RAD };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The direction from a body's centre, in the scene's axes, of a point on its surface at a moment: the unit vector the other way from {@link facingPoint}.
|
|
88
|
+
*
|
|
89
|
+
* @param body - The body.
|
|
90
|
+
* @param face - The point on its surface.
|
|
91
|
+
* @param time - The moment, in milliseconds since the Unix epoch.
|
|
92
|
+
* @returns The unit direction.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { surfaceDirection } from "@johnmorrisdotca/wakusei-planets/space";
|
|
97
|
+
*
|
|
98
|
+
* console.log(surfaceDirection("moon", { lon: 0, lat: 0 }, Date.UTC(2026, 10, 2)).map((n) => n.toFixed(2)));
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export function surfaceDirection(body, face, time) {
|
|
102
|
+
const { pole, meridian } = orientation(body, time);
|
|
103
|
+
const east = cross(pole, meridian);
|
|
104
|
+
const c = Math.cos(face.lat * RAD);
|
|
105
|
+
return [0, 1, 2].map((i) => c * Math.cos(face.lon * RAD) * meridian[i] + c * Math.sin(face.lon * RAD) * east[i] + Math.sin(face.lat * RAD) * pole[i]);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The yaw and tilt of a camera beside a moon (the view `ride(moon, { view: "beside" })` gives) that put it on the side of the moon the point is on: the camera stands along the direction from the moon's
|
|
109
|
+
* centre through the point. The camera there is placed by `besideMoon` (beyond the moon, off the line to its planet), so not every point can be reached: the pair returned brings the camera as near as
|
|
110
|
+
* the view goes, and `error` says by how many degrees it is still off.
|
|
111
|
+
*
|
|
112
|
+
* @param input - What `besideMoon` is given, without the yaw and tilt.
|
|
113
|
+
* @param body - The moon.
|
|
114
|
+
* @param face - The point to bring under the camera.
|
|
115
|
+
* @param time - The moment shown.
|
|
116
|
+
* @returns The yaw and tilt, and the angle in degrees between the camera's direction and the wanted one.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { besideFace } from "@johnmorrisdotca/wakusei-planets/space";
|
|
121
|
+
*
|
|
122
|
+
* const input = { moon: [60, 0, 0], moonRadius: 0.273, host: [0, 0, 0], hostRadius: 1, sun: [-23000, 0, 0], aspect: 1.6, zoom: 1 } as const;
|
|
123
|
+
* console.log(besideFace(input, "moon", { lon: 180, lat: 0 }, Date.UTC(2026, 10, 2)).error < 90);
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export function besideFace(input, body, face, time) {
|
|
127
|
+
const wanted = unit(surfaceDirection(body, face, time));
|
|
128
|
+
const at = (yaw, tilt) => {
|
|
129
|
+
const camera = besideMoon({ ...input, yaw, tilt });
|
|
130
|
+
const away = unit([camera.position[0] - input.moon[0], camera.position[1] - input.moon[1], camera.position[2] - input.moon[2]]);
|
|
131
|
+
return Math.acos(Math.max(-1, Math.min(1, dot(away, wanted)))) / RAD;
|
|
132
|
+
};
|
|
133
|
+
let best = { yaw: 0, tilt: 0, error: Infinity };
|
|
134
|
+
for (let yaw = -180; yaw < 180; yaw += 15) {
|
|
135
|
+
for (let tilt = -60; tilt <= 80; tilt += 10) {
|
|
136
|
+
const error = at(yaw, tilt);
|
|
137
|
+
if (error < best.error)
|
|
138
|
+
best = { yaw, tilt, error };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
for (let step = 8; step > 0.01; step *= 0.6) {
|
|
142
|
+
for (let round = 0; round < 6; round += 1) {
|
|
143
|
+
let moved = false;
|
|
144
|
+
for (const [dy, dt] of [[step, 0], [-step, 0], [0, step], [0, -step]]) {
|
|
145
|
+
const error = at(best.yaw + dy, best.tilt + dt);
|
|
146
|
+
if (error < best.error) {
|
|
147
|
+
best = { yaw: best.yaw + dy, tilt: best.tilt + dt, error };
|
|
148
|
+
moved = true;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (!moved)
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { yaw: wrap(best.yaw), tilt: best.tilt, error: best.error };
|
|
156
|
+
}
|
package/dist/space/index.d.ts
CHANGED
|
@@ -11,3 +11,4 @@ export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy, type CoverArrow,
|
|
|
11
11
|
export { TRAVEL_CLEARANCE, arrivalSide, travelArrival, travelPlan, travelPose, type ArrivalCompanion, type TravelBody, type TravelInput, type TravelKind, type TravelPlan, type TravelSample, type TravelSight, type TravelView } from "./travel.ts";
|
|
12
12
|
export { regionOrbits, regionView, SUN_REGIONS, type SunRegion } from "./regions.ts";
|
|
13
13
|
export { SIGHT_STEP_PX, sightChanged, sightOf, type Sight, type SightEdge, type SightInput } from "./sight.ts";
|
|
14
|
+
export { besideFace, facingPoint, faceView, subCameraPoint, surfaceDirection, type Face, type FaceView } from "./face.ts";
|
package/dist/space/index.js
CHANGED
|
@@ -12,3 +12,4 @@ export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy } from "./covered
|
|
|
12
12
|
export { TRAVEL_CLEARANCE, arrivalSide, travelArrival, travelPlan, travelPose } from "./travel.js";
|
|
13
13
|
export { regionOrbits, regionView, SUN_REGIONS } from "./regions.js";
|
|
14
14
|
export { SIGHT_STEP_PX, sightChanged, sightOf } from "./sight.js";
|
|
15
|
+
export { besideFace, facingPoint, faceView, subCameraPoint, surfaceDirection } from "./face.js";
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.48.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.48.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/wakusei-planets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.0",
|
|
4
4
|
"description": "Wakusei Planets 惑星 — The Sun, planets and moons for the web: each as a clean line drawing, a shaded realistic drawing or a painted surface map, with real sizes, axial tilt and rotation as data, and positions of the moons for any date and time. SVG for the lines, three.js (optional) for the rest.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"planets",
|