@johnmorrisdotca/wakusei-planets 0.30.0 → 0.32.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 +16 -0
- package/NOTICE.md +5 -0
- package/README.md +98 -12
- package/dist/data-door.d.ts +357 -0
- package/dist/data-door.js +393 -0
- package/dist/door/book.d.ts +133 -0
- package/dist/door/book.js +256 -0
- package/dist/door/host.d.ts +30 -0
- package/dist/door/host.js +44 -0
- package/dist/door/index.d.ts +6 -0
- package/dist/door/index.js +10 -0
- package/dist/door/map.d.ts +152 -0
- package/dist/door/map.js +162 -0
- package/dist/door/own.d.ts +36 -0
- package/dist/door/own.js +86 -0
- package/dist/door/points.d.ts +61 -0
- package/dist/door/points.js +175 -0
- package/dist/door/small-bodies.d.ts +157 -0
- package/dist/door/small-bodies.js +148 -0
- package/dist/element.d.ts +21 -0
- package/dist/element.js +74 -4
- package/dist/scene/body.d.ts +5 -2
- package/dist/scene/body.js +2 -1
- package/dist/scene/detail.d.ts +29 -12
- package/dist/scene/detail.js +217 -135
- package/dist/scene/painter.d.ts +5 -0
- package/dist/scene/painter.js +8 -5
- package/dist/scene/textures.d.ts +9 -2
- package/dist/scene/textures.js +17 -0
- package/dist/space/arrows.d.ts +87 -0
- package/dist/space/arrows.js +117 -0
- package/dist/space/beside.d.ts +74 -0
- package/dist/space/beside.js +76 -0
- package/dist/space/bodies.d.ts +83 -0
- package/dist/space/bodies.js +93 -0
- package/dist/space/element.d.ts +114 -14
- package/dist/space/element.js +344 -28
- package/dist/space/frame.d.ts +45 -2
- package/dist/space/frame.js +56 -4
- package/dist/space/index.d.ts +6 -1
- package/dist/space/index.js +6 -1
- package/dist/space/labels.d.ts +52 -0
- package/dist/space/labels.js +40 -0
- package/dist/space/scale.d.ts +5 -5
- package/dist/space/scale.js +10 -4
- package/dist/space/scene.d.ts +49 -9
- package/dist/space/scene.js +325 -34
- package/dist/space/spin.d.ts +37 -0
- package/dist/space/spin.js +29 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -1
package/dist/space/scene.js
CHANGED
|
@@ -1,24 +1,44 @@
|
|
|
1
|
-
import { BODIES } from "../facts.js";
|
|
1
|
+
import { BODIES, MOONS_OF } from "../facts.js";
|
|
2
|
+
import { createSmallBodyPoints } from "../door/points.js";
|
|
3
|
+
import { toTerrestrialTime } from "../clock.js";
|
|
2
4
|
import { moonOffset } from "../scene/orient.js";
|
|
3
5
|
import {} from "../scene/painter.js";
|
|
4
6
|
import "../bodies/all.js";
|
|
5
7
|
import { groundDirection } from "./aim.js";
|
|
6
|
-
import {
|
|
8
|
+
import { hostOf } from "./bodies.js";
|
|
9
|
+
import { arrowSites, ARROWS_PER_ORBIT, chevron, spinArrow } from "./arrows.js";
|
|
10
|
+
import { besideMoon } from "./beside.js";
|
|
11
|
+
import { spinAxis } from "./spin.js";
|
|
12
|
+
import { createTrack, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_PLANETS } from "./frame.js";
|
|
7
13
|
import { ridePose } from "./ride.js";
|
|
8
|
-
import { moonDistance, orbitLine, placeBodies, radiusIn } from "./scale.js";
|
|
14
|
+
import { moonDistance, orbitLine, placeBodies, placeMoon, radiusIn } from "./scale.js";
|
|
9
15
|
const RAD = Math.PI / 180;
|
|
10
16
|
/** The camera's distance, in radii of the body it looks at, at which that body fills the view at zoom 1. */
|
|
11
|
-
export const FIT_DISTANCE =
|
|
17
|
+
export const FIT_DISTANCE = 4.1;
|
|
12
18
|
const FOV = 35;
|
|
13
19
|
const ORBIT_POINTS = 96;
|
|
14
|
-
const ORBIT_BODIES = ["earth", ...SPACE_PLANETS];
|
|
20
|
+
const ORBIT_BODIES = ["earth", ...SPACE_PLANETS, ...SPACE_DWARFS, "moon"];
|
|
21
|
+
/** A dwarf planet is drawn once it is this many CSS pixels across its radius, or when it is the body looked at: Sedna at true scale is never anything but a speck, and its picture is not made for it. */
|
|
22
|
+
const DWARF_MIN_PX = 0.4;
|
|
23
|
+
/** A colour as three numbers from 0 to 1, from `#rrggbb`. */
|
|
24
|
+
const rgb = (hex) => [parseInt(hex.slice(1, 3), 16) / 255, parseInt(hex.slice(3, 5), 16) / 255, parseInt(hex.slice(5, 7), 16) / 255];
|
|
25
|
+
/** How long each arrowhead on an orbit line is, in CSS pixels: small, so it reads at every zoom and never hides a body. */
|
|
26
|
+
const ARROW_PX = 9;
|
|
27
|
+
/** A body whose disc is this many CSS pixels across its radius is "close": the orbit lines that are not its own are hidden. */
|
|
28
|
+
const CLOSE_UP_PX = 30;
|
|
29
|
+
/** How long the Moon's ring is kept before it is worked out again from the Moon's place, in milliseconds: its path changes by a couple of hundred kilometres in that time. */
|
|
30
|
+
const MOON_RING_KEEP_MS = 5 * 86_400_000;
|
|
31
|
+
/** How many radii across the picture of a body is at zoom 1 when it has more than its globe: Saturn's rings (to 2.27 radii) are inside the view, not cut by it. */
|
|
32
|
+
const FRAMED = { saturn: 2.3 };
|
|
15
33
|
/** The moons of a planet are shown once the planet is this many CSS pixels across its radius, and each is drawn at least this many pixels across its radius. */
|
|
16
34
|
const MOON_MIN_PLANET_PX = 4;
|
|
17
35
|
const MOON_MIN_PX = 2.2;
|
|
36
|
+
/** ...or a planet's moons are shown when the planet is smaller than that but its farthest moon is this many CSS pixels from it. */
|
|
37
|
+
const MOON_MIN_SYSTEM_PX = 30;
|
|
18
38
|
/** A moon that has been out of sight this long is let go (its pictures too). */
|
|
19
39
|
const MOON_KEEP_MS = 4000;
|
|
20
40
|
/**
|
|
21
|
-
* The
|
|
41
|
+
* The nineteen bodies the space view places, names and lets a reader choose: the Earth, the Sun, the Moon, the seven other planets, Pluto and the eight other dwarf planets. The moons of the planets and of the dwarf planets are placed round their hosts.
|
|
22
42
|
*
|
|
23
43
|
* @example
|
|
24
44
|
* ```ts no-run
|
|
@@ -27,10 +47,10 @@ const MOON_KEEP_MS = 4000;
|
|
|
27
47
|
* console.log(SPACE_BODIES.join(", "));
|
|
28
48
|
* ```
|
|
29
49
|
*/
|
|
30
|
-
export const SPACE_BODIES = ["earth", "sun", "moon", ...SPACE_PLANETS];
|
|
50
|
+
export const SPACE_BODIES = ["earth", "sun", "moon", ...SPACE_PLANETS, ...SPACE_DWARFS];
|
|
31
51
|
export const newSpaceModel = () => ({
|
|
32
52
|
time: Date.now(),
|
|
33
|
-
mode: "
|
|
53
|
+
mode: "true",
|
|
34
54
|
view: { yaw: 0, tilt: 0, zoom: 1, roll: 0, panX: 0, panY: 0 },
|
|
35
55
|
centre: { lon: 0, lat: 0 },
|
|
36
56
|
anchor: null,
|
|
@@ -43,6 +63,12 @@ export const newSpaceModel = () => ({
|
|
|
43
63
|
drawn: null,
|
|
44
64
|
painted: { bodies: 0, moons: 0, held: 0 },
|
|
45
65
|
tiles: { requested: 0, loading: 0, failed: 0, shown: null },
|
|
66
|
+
rings: { drawn: [], miss: {}, hidden: [] },
|
|
67
|
+
arrows: {},
|
|
68
|
+
help: false,
|
|
69
|
+
arrowPx: 0,
|
|
70
|
+
helpDrawn: null,
|
|
71
|
+
door: { points: 0, used: {} },
|
|
46
72
|
lookups: 0,
|
|
47
73
|
motion: 0,
|
|
48
74
|
drawnView: null,
|
|
@@ -55,11 +81,26 @@ export const newSpaceModel = () => ({
|
|
|
55
81
|
rideMotion: 0,
|
|
56
82
|
ratio: () => Math.min(globalThis.devicePixelRatio || 1, 2),
|
|
57
83
|
});
|
|
84
|
+
const minus = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
85
|
+
/** How far a place is from the nearest point of a line through `points`, in the line's units. */
|
|
86
|
+
const plus = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
|
|
87
|
+
function distanceToLine(place, points) {
|
|
88
|
+
let best = Number.POSITIVE_INFINITY;
|
|
89
|
+
for (let i = 0; i + 1 < points.length; i += 1) {
|
|
90
|
+
const a = points[i];
|
|
91
|
+
const b = points[i + 1];
|
|
92
|
+
const ab = minus(b, a);
|
|
93
|
+
const am = minus(place, a);
|
|
94
|
+
const len2 = ab[0] * ab[0] + ab[1] * ab[1] + ab[2] * ab[2];
|
|
95
|
+
const t = len2 === 0 ? 0 : Math.max(0, Math.min(1, (am[0] * ab[0] + am[1] * ab[1] + am[2] * ab[2]) / len2));
|
|
96
|
+
best = Math.min(best, Math.hypot(place[0] - (a[0] + ab[0] * t), place[1] - (a[1] + ab[1] * t), place[2] - (a[2] + ab[2] * t)));
|
|
97
|
+
}
|
|
98
|
+
return best;
|
|
99
|
+
}
|
|
58
100
|
const unit = (v) => {
|
|
59
101
|
const l = Math.hypot(v[0], v[1], v[2]) || 1;
|
|
60
102
|
return [v[0] / l, v[1] / l, v[2] / l];
|
|
61
103
|
};
|
|
62
|
-
const minus = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
63
104
|
export function createSpaceItem(model, deps) {
|
|
64
105
|
return {
|
|
65
106
|
key: "wakusei-planets:space",
|
|
@@ -69,6 +110,11 @@ export function createSpaceItem(model, deps) {
|
|
|
69
110
|
const track = createTrack(model.stepMs);
|
|
70
111
|
let trackStep = model.stepMs;
|
|
71
112
|
const scene = new three.Scene();
|
|
113
|
+
// the small bodies of the record sources, in one instanced draw (a page's own subset of three needs the two instanced classes for it)
|
|
114
|
+
const points = deps.book !== undefined && typeof three.InstancedBufferGeometry === "function" ? createSmallBodyPoints(three) : undefined;
|
|
115
|
+
if (points !== undefined)
|
|
116
|
+
scene.add(points.object);
|
|
117
|
+
let pointsVersion = -1;
|
|
72
118
|
const camera = new three.PerspectiveCamera(FOV, width / Math.max(1, height), 0.05, 1000);
|
|
73
119
|
const target = new three.Vector3();
|
|
74
120
|
const projected = new three.Vector3();
|
|
@@ -89,7 +135,7 @@ export function createSpaceItem(model, deps) {
|
|
|
89
135
|
empty(slot);
|
|
90
136
|
slot.look = model.look;
|
|
91
137
|
try {
|
|
92
|
-
const made = deps.painter().make(three, id, { look: model.look, invalidate: () => deps.invalidate(), ratio: model.ratio(), maxTexture: deps.cap() });
|
|
138
|
+
const made = deps.painter().make(three, id, { look: model.look, mapped: true, invalidate: () => deps.invalidate(), ratio: model.ratio(), maxTexture: deps.cap() });
|
|
93
139
|
if (ended) {
|
|
94
140
|
made.dispose();
|
|
95
141
|
return;
|
|
@@ -108,15 +154,54 @@ export function createSpaceItem(model, deps) {
|
|
|
108
154
|
slots.set(id, (slot = { drawing: undefined, look: null, failed: false }));
|
|
109
155
|
return slot;
|
|
110
156
|
};
|
|
157
|
+
// each line has its colour and a fade (the fourth number of the colour) at every point, so that near the body looked at the part of a line that would cross it is let go
|
|
111
158
|
const orbits = new Map();
|
|
112
159
|
for (const id of ORBIT_BODIES) {
|
|
113
160
|
const positions = new Float32Array((ORBIT_POINTS + 1) * 3);
|
|
161
|
+
const colours = new Float32Array((ORBIT_POINTS + 1) * 4);
|
|
162
|
+
const base = rgb(id === "earth" ? "#6aa8ff" : id === "moon" ? "#c5cdd9" : BODIES[id].colour);
|
|
163
|
+
for (let i = 0; i <= ORBIT_POINTS; i += 1)
|
|
164
|
+
colours.set([base[0], base[1], base[2], 1], i * 4);
|
|
114
165
|
const geometry = new three.BufferGeometry();
|
|
115
166
|
geometry.setAttribute("position", new three.BufferAttribute(positions, 3));
|
|
116
|
-
|
|
167
|
+
geometry.setAttribute("color", new three.BufferAttribute(colours, 4));
|
|
168
|
+
const line = new three.Line(geometry, new three.LineBasicMaterial({ vertexColors: true, transparent: true, opacity: 0.55 }));
|
|
117
169
|
line.frustumCulled = false;
|
|
118
170
|
scene.add(line);
|
|
119
|
-
orbits.set(id, { line, positions, samples: [], epoch: Number.NaN });
|
|
171
|
+
orbits.set(id, { line, positions, colours, faded: false, samples: [], epoch: Number.NaN });
|
|
172
|
+
}
|
|
173
|
+
// the arrowheads of every orbit line: two strokes each, in the colour of the line, in one object; and the help mode's axis and curved arrow in another (drawn over the body, not hidden by it)
|
|
174
|
+
const ARROW_VERTICES = ORBIT_BODIES.length * ARROWS_PER_ORBIT * 4;
|
|
175
|
+
const arrowPositions = new Float32Array(ARROW_VERTICES * 3);
|
|
176
|
+
const arrowColours = new Float32Array(ARROW_VERTICES * 3);
|
|
177
|
+
const arrowGeometry = new three.BufferGeometry();
|
|
178
|
+
arrowGeometry.setAttribute("position", new three.BufferAttribute(arrowPositions, 3));
|
|
179
|
+
arrowGeometry.setAttribute("color", new three.BufferAttribute(arrowColours, 3));
|
|
180
|
+
const arrowLines = new three.LineSegments(arrowGeometry, new three.LineBasicMaterial({ vertexColors: true, transparent: true, opacity: 0.95 }));
|
|
181
|
+
arrowLines.frustumCulled = false;
|
|
182
|
+
scene.add(arrowLines);
|
|
183
|
+
ORBIT_BODIES.forEach((id, k) => {
|
|
184
|
+
const c = rgb(id === "earth" ? "#6aa8ff" : id === "moon" ? "#c5cdd9" : BODIES[id].colour);
|
|
185
|
+
for (let v = 0; v < ARROWS_PER_ORBIT * 4; v += 1)
|
|
186
|
+
arrowColours.set(c, (k * ARROWS_PER_ORBIT * 4 + v) * 3);
|
|
187
|
+
});
|
|
188
|
+
const HELP_SEGMENTS = 28;
|
|
189
|
+
const HELP_VERTICES = (1 + HELP_SEGMENTS + 2) * 2;
|
|
190
|
+
const helpPositions = new Float32Array(HELP_VERTICES * 3);
|
|
191
|
+
const helpColours = new Float32Array(HELP_VERTICES * 3);
|
|
192
|
+
const helpGeometry = new three.BufferGeometry();
|
|
193
|
+
helpGeometry.setAttribute("position", new three.BufferAttribute(helpPositions, 3));
|
|
194
|
+
helpGeometry.setAttribute("color", new three.BufferAttribute(helpColours, 3));
|
|
195
|
+
const helpLines = new three.LineSegments(helpGeometry, new three.LineBasicMaterial({ vertexColors: true, transparent: true, opacity: 0.95, depthTest: false }));
|
|
196
|
+
helpLines.frustumCulled = false;
|
|
197
|
+
helpLines.renderOrder = 10;
|
|
198
|
+
helpLines.visible = false;
|
|
199
|
+
scene.add(helpLines);
|
|
200
|
+
const AXIS_COLOUR = rgb("#9fd0ff");
|
|
201
|
+
const SPIN_COLOUR = rgb("#ffd24a");
|
|
202
|
+
for (let v = 0; v < HELP_VERTICES; v += 1) {
|
|
203
|
+
const c = v < 2 ? AXIS_COLOUR : SPIN_COLOUR;
|
|
204
|
+
helpColours.set(c, v * 3);
|
|
120
205
|
}
|
|
121
206
|
const moonSlots = new Map();
|
|
122
207
|
let releaseTimer;
|
|
@@ -139,9 +224,7 @@ export function createSpaceItem(model, deps) {
|
|
|
139
224
|
}
|
|
140
225
|
const mode = model.mode;
|
|
141
226
|
const pos = placeBodies(mode, frame);
|
|
142
|
-
const sunPos = pos.sun;
|
|
143
227
|
const radiusOf = (id) => radiusIn(id, mode);
|
|
144
|
-
const placeAll = (at) => placeBodies(mode, at);
|
|
145
228
|
// where a moon is round its planet, as the view draws it: in the planet's radii, drawn nearer in a compressed view where the real distance would cross the next planet's orbit
|
|
146
229
|
const moonSite = (id, at, host) => {
|
|
147
230
|
const real = moonOffset(id, at);
|
|
@@ -149,15 +232,50 @@ export function createSpaceItem(model, deps) {
|
|
|
149
232
|
const k = d === 0 ? 1 : moonDistance(mode, host, d) / d;
|
|
150
233
|
return [real[0] * k, real[1] * k, real[2] * k];
|
|
151
234
|
};
|
|
152
|
-
|
|
235
|
+
// The places are in Earth radii from the Earth's centre, which at a dwarf planet is millions: a body a few hundredths of a radius across (Phobos, Eris seen close) would be lost to the GPU's single-precision
|
|
236
|
+
// numbers, which the bodies' shaders use for world positions. So the whole scene is moved to put the body looked at (or the target of a ride) at the origin: every place below is relative to it, and the
|
|
237
|
+
// camera's place that is reported, and kept for a glide, has it added back.
|
|
238
|
+
const absoluteSite = (id) => {
|
|
239
|
+
if (SPACE_BODIES.includes(id))
|
|
240
|
+
return pos[id];
|
|
241
|
+
const host = (hostOf(id) ?? "earth");
|
|
242
|
+
const offset = moonSite(id, model.time, host);
|
|
243
|
+
const hostRadius = radiusOf(host);
|
|
244
|
+
return [pos[host][0] + offset[0] * hostRadius, pos[host][1] + offset[1] * hostRadius, pos[host][2] + offset[2] * hostRadius];
|
|
245
|
+
};
|
|
246
|
+
const held = model.ride;
|
|
247
|
+
const origin = absoluteSite(held ? (typeof held.target === "string" ? held.target : held.around) : model.focus);
|
|
248
|
+
for (const id of Object.keys(pos))
|
|
249
|
+
pos[id] = minus(pos[id], origin);
|
|
250
|
+
const sunPos = pos.sun;
|
|
251
|
+
const placeAll = (at) => {
|
|
252
|
+
const placed = placeBodies(mode, at);
|
|
253
|
+
for (const id of Object.keys(placed))
|
|
254
|
+
placed[id] = minus(placed[id], origin);
|
|
255
|
+
return placed;
|
|
256
|
+
};
|
|
257
|
+
const toSunOf = (id) => unit(minus(frame.sun, id === "earth" ? [0, 0, 0] : id === "moon" ? frame.moon : id === "sun" ? [0, 0, 0] : SPACE_DWARFS.includes(id) ? frame.dwarfs[id] : frame.planets[id]));
|
|
153
258
|
// riding along: the camera sits at a moving point and looks at the body it goes round (a moon over its planet, a point over any body). The point's place and way of going are in radii of
|
|
154
259
|
// that body, from its centre; the body is drawn at `centre` with the radius `unitWorld`, so the same numbers place the camera in the scene.
|
|
155
260
|
model.rideLost = false;
|
|
156
261
|
model.rideMotion = 0;
|
|
157
262
|
let focus = model.focus;
|
|
158
|
-
let focusPos
|
|
159
|
-
let focusRadius
|
|
263
|
+
let focusPos;
|
|
264
|
+
let focusRadius;
|
|
265
|
+
if (SPACE_BODIES.includes(focus)) {
|
|
266
|
+
focusPos = pos[focus];
|
|
267
|
+
focusRadius = radiusOf(focus);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
// a moon of a planet: its place round the planet, in the planet's radii as the view draws them
|
|
271
|
+
const host = (hostOf(focus) ?? "earth");
|
|
272
|
+
const offset = moonSite(focus, model.time, host);
|
|
273
|
+
const hostRadius = radiusOf(host);
|
|
274
|
+
focusPos = [pos[host][0] + offset[0] * hostRadius, pos[host][1] + offset[1] * hostRadius, pos[host][2] + offset[2] * hostRadius];
|
|
275
|
+
focusRadius = Math.max(1e-9, (BODIES[focus].radiusKm / BODIES[host].radiusKm) * hostRadius);
|
|
276
|
+
}
|
|
160
277
|
let aimWay = 1;
|
|
278
|
+
let besideIn = null;
|
|
161
279
|
let rideFrom = null;
|
|
162
280
|
const ride = model.ride;
|
|
163
281
|
if (ride) {
|
|
@@ -172,7 +290,15 @@ export function createSpaceItem(model, deps) {
|
|
|
172
290
|
let hiddenMoon = null;
|
|
173
291
|
if (typeof t === "string" && SPACE_BODIES.includes(t)) {
|
|
174
292
|
const id = t;
|
|
175
|
-
if (ride.view === "
|
|
293
|
+
if (ride.view === "beside") {
|
|
294
|
+
// beyond the Moon and off the line to the Earth, the Earth in view behind it
|
|
295
|
+
if (id === "moon")
|
|
296
|
+
besideIn = { moon: pos.moon, moonRadius: radiusOf("moon"), host: pos.earth, hostRadius: radiusOf("earth"), sun: pos.sun };
|
|
297
|
+
focus = id;
|
|
298
|
+
focusPos = pos[id];
|
|
299
|
+
focusRadius = radiusOf(id);
|
|
300
|
+
}
|
|
301
|
+
else if (ride.view === "follow") {
|
|
176
302
|
focus = id;
|
|
177
303
|
focusPos = pos[id];
|
|
178
304
|
focusRadius = radiusOf(id);
|
|
@@ -181,7 +307,8 @@ export function createSpaceItem(model, deps) {
|
|
|
181
307
|
const ends = track.ends();
|
|
182
308
|
const was = ends ? placeAll(ends[0])[id] : pos[id];
|
|
183
309
|
const will = ends ? placeAll(ends[1])[id] : pos[id];
|
|
184
|
-
|
|
310
|
+
// from the centre of the body it goes round (the places are relative to the origin the scene was moved to)
|
|
311
|
+
position = minus(pos[id], centre);
|
|
185
312
|
velocity = minus(will, was);
|
|
186
313
|
perSecond = ends ? Math.max(1e-3, (ends[1].ms - ends[0].ms) / 1000) : 1;
|
|
187
314
|
hiddenBody = id;
|
|
@@ -191,7 +318,15 @@ export function createSpaceItem(model, deps) {
|
|
|
191
318
|
const id = t;
|
|
192
319
|
const offset = moonSite(id, model.time, around);
|
|
193
320
|
const later = moonSite(id, model.time + 1000, around);
|
|
194
|
-
if (ride.view === "
|
|
321
|
+
if (ride.view === "beside") {
|
|
322
|
+
const there = [centre[0] + offset[0] * unitWorld, centre[1] + offset[1] * unitWorld, centre[2] + offset[2] * unitWorld];
|
|
323
|
+
const radius = Math.max(1e-6, (BODIES[id].radiusKm / BODIES[around].radiusKm) * unitWorld);
|
|
324
|
+
besideIn = { moon: there, moonRadius: radius, host: centre, hostRadius: unitWorld, sun: pos.sun };
|
|
325
|
+
focus = id;
|
|
326
|
+
focusPos = there;
|
|
327
|
+
focusRadius = radius;
|
|
328
|
+
}
|
|
329
|
+
else if (ride.view === "follow") {
|
|
195
330
|
focusPos = [centre[0] + offset[0] * unitWorld, centre[1] + offset[1] * unitWorld, centre[2] + offset[2] * unitWorld];
|
|
196
331
|
focusRadius = Math.max(1e-6, (BODIES[id].radiusKm / BODIES[around].radiusKm) * unitWorld);
|
|
197
332
|
}
|
|
@@ -224,7 +359,17 @@ export function createSpaceItem(model, deps) {
|
|
|
224
359
|
}
|
|
225
360
|
let fovNow = FOV;
|
|
226
361
|
let distance = 0;
|
|
227
|
-
if (
|
|
362
|
+
if (besideIn) {
|
|
363
|
+
const view = besideMoon({ ...besideIn, aspect: size.width / Math.max(1, size.height), zoom: model.view.zoom, yaw: model.view.yaw, tilt: model.view.tilt });
|
|
364
|
+
camera.position.set(view.position[0], view.position[1], view.position[2]);
|
|
365
|
+
camera.up.set(view.up[0], view.up[1], view.up[2]);
|
|
366
|
+
camera.lookAt(view.position[0] + view.forward[0], view.position[1] + view.forward[1], view.position[2] + view.forward[2]);
|
|
367
|
+
fovNow = view.fov;
|
|
368
|
+
distance = view.distance;
|
|
369
|
+
camera.near = Math.max(1e-4, (view.distance - besideIn.moonRadius) * 0.1);
|
|
370
|
+
camera.far = Math.max(2000, 400 + (mode === "true" ? 40 * 23_481 : 0));
|
|
371
|
+
}
|
|
372
|
+
else if (rideFrom) {
|
|
228
373
|
const pose = ridePose({ position: rideFrom.position, velocity: rideFrom.velocity, radius: 1, look: ride.look, yaw: model.view.yaw, tilt: model.view.tilt, zoom: model.view.zoom });
|
|
229
374
|
const { centre, unitWorld } = rideFrom;
|
|
230
375
|
camera.position.set(centre[0] + pose.position[0] * unitWorld, centre[1] + pose.position[1] * unitWorld, centre[2] + pose.position[2] * unitWorld);
|
|
@@ -246,7 +391,9 @@ export function createSpaceItem(model, deps) {
|
|
|
246
391
|
const lon = model.centre.lon - aimWay * model.view.yaw;
|
|
247
392
|
const lat = Math.max(-90, Math.min(90, model.centre.lat - aimWay * model.view.tilt));
|
|
248
393
|
const aim = groundDirection(lon, lat, model.anchor);
|
|
249
|
-
|
|
394
|
+
// at zoom 1 the whole picture of the body fits the shorter side of the view, in any shape: a tall view is as far again as it is taller than wide, and a ringed body is framed with its rings
|
|
395
|
+
const across = focusRadius * (FRAMED[focus] ?? 1) * Math.max(1, size.height / Math.max(1, size.width));
|
|
396
|
+
distance = Math.max(1.05 * focusRadius, (FIT_DISTANCE * across) / Math.max(1e-9, model.view.zoom));
|
|
250
397
|
target.set(focusPos[0], focusPos[1], focusPos[2]);
|
|
251
398
|
camera.position.set(target.x + aim[0] * distance, target.y + aim[1] * distance, target.z + aim[2] * distance);
|
|
252
399
|
camera.up.set(0, 1, 0);
|
|
@@ -260,7 +407,9 @@ export function createSpaceItem(model, deps) {
|
|
|
260
407
|
const k = Math.min(1, (performance.now() - glide.start) / glide.duration);
|
|
261
408
|
const ease = k * k * (3 - 2 * k);
|
|
262
409
|
desiredQ.copy(camera.quaternion);
|
|
263
|
-
|
|
410
|
+
// the pose the last draw left is absolute (from the Earth's centre); the scene is now relative to the new origin
|
|
411
|
+
const [fx, fy, fz] = [glide.from.p[0] - origin[0], glide.from.p[1] - origin[1], glide.from.p[2] - origin[2]];
|
|
412
|
+
camera.position.set(fx + (camera.position.x - fx) * ease, fy + (camera.position.y - fy) * ease, fz + (camera.position.z - fz) * ease);
|
|
264
413
|
fromQ.set(glide.from.q[0], glide.from.q[1], glide.from.q[2], glide.from.q[3]);
|
|
265
414
|
camera.quaternion.copy(fromQ.slerp(desiredQ, ease));
|
|
266
415
|
fovNow = glide.from.fov + (fovNow - glide.from.fov) * ease;
|
|
@@ -280,8 +429,8 @@ export function createSpaceItem(model, deps) {
|
|
|
280
429
|
camera.updateMatrixWorld();
|
|
281
430
|
const hiddenBody = rideFrom?.hiddenBody ?? null;
|
|
282
431
|
const hiddenMoon = rideFrom?.hiddenMoon ?? null;
|
|
283
|
-
model.camera = { position: [camera.position.x, camera.position.y, camera.position.z], fov: fovNow };
|
|
284
|
-
model.pose = { p: [camera.position.x, camera.position.y, camera.position.z], q: [camera.quaternion.x, camera.quaternion.y, camera.quaternion.z, camera.quaternion.w], fov: fovNow, valid: true };
|
|
432
|
+
model.camera = { position: [camera.position.x + origin[0], camera.position.y + origin[1], camera.position.z + origin[2]], fov: fovNow };
|
|
433
|
+
model.pose = { p: [camera.position.x + origin[0], camera.position.y + origin[1], camera.position.z + origin[2]], q: [camera.quaternion.x, camera.quaternion.y, camera.quaternion.z, camera.quaternion.w], fov: fovNow, valid: true };
|
|
285
434
|
model.drawnView = { yaw: model.view.yaw, tilt: model.view.tilt, zoom: model.view.zoom, roll: model.view.roll, panX: model.view.panX, panY: model.view.panY };
|
|
286
435
|
model.heightPx = size.height;
|
|
287
436
|
// how many pixels across each body is: for the pictures it needs and for what is chosen
|
|
@@ -303,6 +452,13 @@ export function createSpaceItem(model, deps) {
|
|
|
303
452
|
let paintedBodies = 0;
|
|
304
453
|
for (const id of SPACE_BODIES) {
|
|
305
454
|
const slot = slotOf(id);
|
|
455
|
+
// a dwarf planet too small to see is not made, and one that was made but has shrunk away is hidden
|
|
456
|
+
const unseen = SPACE_DWARFS.includes(id) && px[id] < DWARF_MIN_PX && focus !== id && model.focus !== id && hostOf(model.focus) !== id;
|
|
457
|
+
if (unseen) {
|
|
458
|
+
if (slot.drawing)
|
|
459
|
+
slot.drawing.object.visible = false;
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
306
462
|
fill(id, slot);
|
|
307
463
|
const drawing = slot.drawing;
|
|
308
464
|
if (!drawing)
|
|
@@ -318,40 +474,157 @@ export function createSpaceItem(model, deps) {
|
|
|
318
474
|
drawing.update({ toSun, ms: model.time, radiusPx: px[id], view: { camera, width: size.width, height: size.height } });
|
|
319
475
|
}
|
|
320
476
|
model.painted.bodies = paintedBodies;
|
|
477
|
+
if (points !== undefined && deps.book !== undefined) {
|
|
478
|
+
if (pointsVersion !== deps.book.version) {
|
|
479
|
+
pointsVersion = deps.book.version;
|
|
480
|
+
points.set(deps.book.smallBodies());
|
|
481
|
+
}
|
|
482
|
+
const ratio = model.ratio();
|
|
483
|
+
points.update({ jd: toTerrestrialTime(model.time) / 86_400_000 + 2_440_587.5, mode, sun: sunPos, width: size.width * ratio, height: size.height * ratio, ratio });
|
|
484
|
+
model.door.points = points.count;
|
|
485
|
+
}
|
|
321
486
|
// the orbits round the Sun, placed by the same mapping as the bodies
|
|
487
|
+
const drawnRings = [];
|
|
488
|
+
const hiddenRings = [];
|
|
489
|
+
const miss = {};
|
|
490
|
+
// Close to a body (its disc is a few dozen pixels across) the other orbit lines are seen edge-on, long straight scratches across it: only the lines of its own system are kept, and of those the part near it fades
|
|
491
|
+
const nearId = (rideFrom ? rideFrom.around : SPACE_BODIES.includes(focus) ? focus : (hostOf(focus) ?? "earth"));
|
|
492
|
+
const closeUp = px[nearId] >= CLOSE_UP_PX;
|
|
493
|
+
const ownLine = (id) => id === nearId || (id === "moon" && (nearId === "earth" || nearId === "moon"));
|
|
494
|
+
const nearRadius = radiusOf(nearId);
|
|
322
495
|
for (const id of ORBIT_BODIES) {
|
|
323
496
|
const o = orbits.get(id);
|
|
324
|
-
|
|
497
|
+
const hide = closeUp && !ownLine(id);
|
|
498
|
+
o.line.visible = model.orbits && !hide;
|
|
325
499
|
if (!model.orbits)
|
|
326
500
|
continue;
|
|
327
|
-
|
|
328
|
-
|
|
501
|
+
const keep = id === "moon" ? MOON_RING_KEEP_MS : 365 * 86_400_000;
|
|
502
|
+
if (!Number.isFinite(o.epoch) || Math.abs(model.time - o.epoch) > keep) {
|
|
503
|
+
o.samples = id === "moon" ? moonOrbit(model.time, ORBIT_POINTS) : planetOrbit(id, model.time, ORBIT_POINTS);
|
|
329
504
|
o.epoch = model.time;
|
|
330
505
|
}
|
|
331
|
-
|
|
506
|
+
// the Moon's ring is round the Earth, which is the middle of the view; the others are round the Sun
|
|
507
|
+
const line = id === "moon" ? o.samples.map((p) => plus(placeMoon(mode, p), pos.earth)) : orbitLine(mode, sunPos, o.samples);
|
|
332
508
|
for (let i = 0; i <= ORBIT_POINTS; i += 1) {
|
|
333
509
|
o.positions[i * 3] = line[i][0];
|
|
334
510
|
o.positions[i * 3 + 1] = line[i][1];
|
|
335
511
|
o.positions[i * 3 + 2] = line[i][2];
|
|
336
512
|
}
|
|
337
513
|
o.line.geometry.getAttribute("position").needsUpdate = true;
|
|
514
|
+
// the part of its own line near the body is let go, from 3 radii out to 12 (a close view sees a few radii across): never a line across the disc
|
|
515
|
+
const fade = closeUp && ownLine(id);
|
|
516
|
+
if (fade || o.faded) {
|
|
517
|
+
for (let i = 0; i <= ORBIT_POINTS; i += 1) {
|
|
518
|
+
const away = Math.hypot(line[i][0] - pos[nearId][0], line[i][1] - pos[nearId][1], line[i][2] - pos[nearId][2]) / nearRadius;
|
|
519
|
+
const t = Math.max(0, Math.min(1, (away - 3) / 9));
|
|
520
|
+
o.colours[i * 4 + 3] = fade ? t * t * (3 - 2 * t) : 1;
|
|
521
|
+
}
|
|
522
|
+
o.line.geometry.getAttribute("color").needsUpdate = true;
|
|
523
|
+
o.faded = fade;
|
|
524
|
+
}
|
|
525
|
+
if (hide)
|
|
526
|
+
hiddenRings.push(id);
|
|
527
|
+
// how far the body is from its own line, against the line's size: the check that it sits on it
|
|
528
|
+
const centre = id === "moon" ? pos.earth : sunPos;
|
|
529
|
+
const radius = Math.hypot(...minus(line[0], centre)) || 1;
|
|
530
|
+
drawnRings.push(id);
|
|
531
|
+
miss[id] = distanceToLine(pos[id], line) / radius;
|
|
532
|
+
}
|
|
533
|
+
model.rings = { drawn: drawnRings, miss, hidden: hiddenRings };
|
|
534
|
+
// the arrowheads on the lines: small in screen pixels at the place, pointing the way the body goes (the lines run from the body once round in the order it goes, whichever way the clock runs)
|
|
535
|
+
const e = camera.matrixWorld.elements;
|
|
536
|
+
const camRight = [e[0], e[1], e[2]];
|
|
537
|
+
const camUp = [e[4], e[5], e[6]];
|
|
538
|
+
const camForward = [-e[8], -e[9], -e[10]];
|
|
539
|
+
const pixel = (at) => {
|
|
540
|
+
const d = (at[0] - camera.position.x) * camForward[0] + (at[1] - camera.position.y) * camForward[1] + (at[2] - camera.position.z) * camForward[2];
|
|
541
|
+
return d <= 0 ? 0 : (d * 2 * half) / Math.max(1, size.height);
|
|
542
|
+
};
|
|
543
|
+
const arrowsNow = {};
|
|
544
|
+
let measured = 0;
|
|
545
|
+
arrowPositions.fill(0);
|
|
546
|
+
ORBIT_BODIES.forEach((id, k) => {
|
|
547
|
+
const o = orbits.get(id);
|
|
548
|
+
if (!model.orbits || !drawnRings.includes(id) || hiddenRings.includes(id))
|
|
549
|
+
return;
|
|
550
|
+
const line = [];
|
|
551
|
+
for (let i = 0; i <= ORBIT_POINTS; i += 1)
|
|
552
|
+
line.push([o.positions[i * 3], o.positions[i * 3 + 1], o.positions[i * 3 + 2]]);
|
|
553
|
+
const sites = arrowSites(line);
|
|
554
|
+
arrowsNow[id] = sites;
|
|
555
|
+
sites.forEach((site, j) => {
|
|
556
|
+
// an arrow on the faded part of a line goes with it
|
|
557
|
+
if (closeUp && Math.hypot(site.position[0] - pos[nearId][0], site.position[1] - pos[nearId][1], site.position[2] - pos[nearId][2]) < 12 * nearRadius)
|
|
558
|
+
return;
|
|
559
|
+
const head = chevron(site.position, site.direction, camRight, camUp, ARROW_PX * pixel(site.position));
|
|
560
|
+
if (!head)
|
|
561
|
+
return;
|
|
562
|
+
const base = (k * ARROWS_PER_ORBIT + j) * 4 * 3;
|
|
563
|
+
arrowPositions.set([...head[0], ...head[1], ...head[0], ...head[2]], base);
|
|
564
|
+
if (measured === 0) {
|
|
565
|
+
const tip = labelFor(head[0]);
|
|
566
|
+
const wing = labelFor(head[1]);
|
|
567
|
+
if (tip && wing)
|
|
568
|
+
measured = Math.hypot(tip.x - wing.x, tip.y - wing.y);
|
|
569
|
+
}
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
model.arrows = arrowsNow;
|
|
573
|
+
model.arrowPx = measured;
|
|
574
|
+
arrowLines.visible = model.orbits;
|
|
575
|
+
arrowGeometry.getAttribute("position").needsUpdate = true;
|
|
576
|
+
arrowGeometry.getAttribute("color").needsUpdate = true;
|
|
577
|
+
// help mode: on the body looked at, the line of its axis and a curved arrow round it the way it turns
|
|
578
|
+
helpLines.visible = model.help;
|
|
579
|
+
model.helpDrawn = null;
|
|
580
|
+
if (model.help) {
|
|
581
|
+
const turn = spinAxis(focus, model.time);
|
|
582
|
+
const spin = spinArrow(focusPos, turn.axis, 1.3 * focusRadius, 0.4 * focusRadius, HELP_SEGMENTS);
|
|
583
|
+
const reach = 1.8 * focusRadius;
|
|
584
|
+
const segments = [
|
|
585
|
+
[focusPos[0] - turn.pole[0] * reach, focusPos[1] - turn.pole[1] * reach, focusPos[2] - turn.pole[2] * reach],
|
|
586
|
+
[focusPos[0] + turn.pole[0] * reach, focusPos[1] + turn.pole[1] * reach, focusPos[2] + turn.pole[2] * reach],
|
|
587
|
+
];
|
|
588
|
+
for (let i = 0; i < HELP_SEGMENTS; i += 1)
|
|
589
|
+
segments.push(spin.arc[i], spin.arc[i + 1]);
|
|
590
|
+
const tip = spin.arc[HELP_SEGMENTS];
|
|
591
|
+
segments.push(tip, spin.head[0], tip, spin.head[1]);
|
|
592
|
+
segments.forEach((p, i) => helpPositions.set(p, i * 3));
|
|
593
|
+
helpGeometry.getAttribute("position").needsUpdate = true;
|
|
594
|
+
// the axis the drawn arc turns about, measured from its own points, round the middle of its circle
|
|
595
|
+
const middle = [focusPos[0] + turn.axis[0] * 0.4 * focusRadius, focusPos[1] + turn.axis[1] * 0.4 * focusRadius, focusPos[2] + turn.axis[2] * 0.4 * focusRadius];
|
|
596
|
+
let sum = [0, 0, 0];
|
|
597
|
+
for (let i = 0; i < HELP_SEGMENTS; i += 1) {
|
|
598
|
+
const a = minus(spin.arc[i], middle);
|
|
599
|
+
const b = minus(spin.arc[i + 1], middle);
|
|
600
|
+
sum = [sum[0] + a[1] * b[2] - a[2] * b[1], sum[1] + a[2] * b[0] - a[0] * b[2], sum[2] + a[0] * b[1] - a[1] * b[0]];
|
|
601
|
+
}
|
|
602
|
+
model.helpDrawn = { body: focus, axis: turn.axis, pole: turn.pole, retrograde: turn.retrograde, arcTurn: unit(sum) };
|
|
338
603
|
}
|
|
339
604
|
// the moons of a planet, once it is big enough on the screen to show them
|
|
340
605
|
const now = performance.now();
|
|
341
606
|
const seen = new Set();
|
|
342
|
-
|
|
607
|
+
const moonPlaces = {};
|
|
608
|
+
for (const id of [...SPACE_PLANETS, ...SPACE_DWARFS]) {
|
|
343
609
|
const planet = slotOf(id).drawing;
|
|
344
|
-
if (!planet
|
|
610
|
+
if (!planet)
|
|
611
|
+
continue;
|
|
612
|
+
const sites = (MOONS_OF[id] ?? []).map((moon) => ({ name: moon, offset: moonOffset(moon, model.time), radius: BODIES[moon].radiusKm / BODIES[id].radiusKm }));
|
|
613
|
+
// the moons are shown once the planet is a few pixels across, or the system round it is wide enough on the screen to tell its moons from the planet, or one of its moons is the body looked at
|
|
614
|
+
let spread = 1;
|
|
615
|
+
for (const site of sites)
|
|
616
|
+
spread = Math.max(spread, moonDistance(mode, id, Math.hypot(site.offset[0], site.offset[1], site.offset[2])));
|
|
617
|
+
if (px[id] < MOON_MIN_PLANET_PX && px[id] * spread < MOON_MIN_SYSTEM_PX && hostOf(model.focus) !== id)
|
|
345
618
|
continue;
|
|
346
619
|
const radius = radiusOf(id);
|
|
347
|
-
for (const site of
|
|
620
|
+
for (const site of sites) {
|
|
348
621
|
const reach = Math.hypot(site.offset[0], site.offset[1], site.offset[2]);
|
|
349
622
|
const k = reach === 0 ? 1 : moonDistance(mode, id, reach) / reach;
|
|
350
623
|
const at = [pos[id][0] + site.offset[0] * k * radius, pos[id][1] + site.offset[1] * k * radius, pos[id][2] + site.offset[2] * k * radius];
|
|
351
624
|
projected.set(at[0], at[1], at[2]).project(camera);
|
|
352
625
|
if (projected.z > 1 || Math.abs(projected.x) > 1.25 || Math.abs(projected.y) > 1.25)
|
|
353
626
|
continue;
|
|
354
|
-
const key = site.name
|
|
627
|
+
const key = site.name;
|
|
355
628
|
if (key === hiddenMoon)
|
|
356
629
|
continue;
|
|
357
630
|
let held = moonSlots.get(key);
|
|
@@ -370,6 +643,9 @@ export function createSpaceItem(model, deps) {
|
|
|
370
643
|
drawing.object.scale.setScalar(drawn);
|
|
371
644
|
const moonPx = away <= drawn * 1.001 ? 1e5 : ((size.height / 2) * (drawn / Math.sqrt(away * away - drawn * drawn))) / half;
|
|
372
645
|
drawing.update({ toSun: model.light === "lit" ? unit([camera.position.x - at[0], camera.position.y - at[1], camera.position.z - at[2]]) : toSunOf(id), ms: model.time, radiusPx: moonPx, view: { camera, width: size.width, height: size.height } });
|
|
646
|
+
const spot = labelFor(at);
|
|
647
|
+
if (spot)
|
|
648
|
+
moonPlaces[key] = { x: spot.x, y: spot.y, r: moonPx };
|
|
373
649
|
}
|
|
374
650
|
}
|
|
375
651
|
let soonest = Number.POSITIVE_INFINITY;
|
|
@@ -407,8 +683,18 @@ export function createSpaceItem(model, deps) {
|
|
|
407
683
|
tiles.shown = Math.max(tiles.shown ?? 0, stats.shown);
|
|
408
684
|
}
|
|
409
685
|
model.tiles = tiles;
|
|
686
|
+
const used = {};
|
|
687
|
+
for (const painting of [...[...slots.values()].map((slot) => slot.drawing), ...[...moonSlots.values()].map((held) => held.slot.drawing)]) {
|
|
688
|
+
const shown = painting?.tiles;
|
|
689
|
+
if (shown?.source !== undefined)
|
|
690
|
+
used[shown.source.id] = (used[shown.source.id] ?? 0) + shown.used;
|
|
691
|
+
}
|
|
692
|
+
if (points !== undefined && deps.book !== undefined && points.count > 0)
|
|
693
|
+
for (const [id, read] of deps.book.recordReads())
|
|
694
|
+
used[id] = read.records.length;
|
|
695
|
+
model.door.used = used;
|
|
410
696
|
if (deps.onLabels && model.labels) {
|
|
411
|
-
const places = {};
|
|
697
|
+
const places = { ...moonPlaces };
|
|
412
698
|
for (const id of SPACE_BODIES) {
|
|
413
699
|
const at = id === hiddenBody || (rideFrom && id === rideFrom.around) ? null : labelFor(pos[id]);
|
|
414
700
|
places[id] = at ? { x: at.x, y: at.y, r: px[id] } : null;
|
|
@@ -425,6 +711,7 @@ export function createSpaceItem(model, deps) {
|
|
|
425
711
|
size = { width: w, height: h };
|
|
426
712
|
},
|
|
427
713
|
dispose() {
|
|
714
|
+
points?.dispose();
|
|
428
715
|
if (releaseTimer !== undefined)
|
|
429
716
|
clearTimeout(releaseTimer);
|
|
430
717
|
ended = true;
|
|
@@ -438,6 +725,10 @@ export function createSpaceItem(model, deps) {
|
|
|
438
725
|
o.line.geometry.dispose();
|
|
439
726
|
o.line.material.dispose();
|
|
440
727
|
}
|
|
728
|
+
for (const lines of [arrowLines, helpLines]) {
|
|
729
|
+
lines.geometry.dispose();
|
|
730
|
+
lines.material.dispose();
|
|
731
|
+
}
|
|
441
732
|
},
|
|
442
733
|
};
|
|
443
734
|
},
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { BodyId } from "../facts.ts";
|
|
2
|
+
import { type Vec3 } from "../vec.ts";
|
|
3
|
+
/**
|
|
4
|
+
* How a body turns at one moment: `axis`, the unit vector it turns about by the right-hand rule (the fingers of the right hand curl the way the body turns when the thumb points along it, so it points to the north
|
|
5
|
+
* pole of a body that turns the usual way and to the south pole of one that turns backwards, Venus and Uranus), and `pole`, the unit vector to its north pole as the IAU defines it.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import type { SpinAxis } from "@johnmorrisdotca/wakusei-planets/space";
|
|
10
|
+
*
|
|
11
|
+
* const earth: SpinAxis = { axis: [0, 1, 0], pole: [0, 1, 0], retrograde: false };
|
|
12
|
+
* console.log(earth.retrograde);
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export interface SpinAxis {
|
|
16
|
+
axis: Vec3;
|
|
17
|
+
pole: Vec3;
|
|
18
|
+
/** True when it turns the other way from most bodies: the axis points away from the north pole. */
|
|
19
|
+
retrograde: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The axis a body spins about at `ms`, in the scene's axes (J2000 equatorial, y north), from how its prime meridian moves over ten minutes, so it is right for a body that turns backwards (Venus, Uranus, Pluto), one
|
|
23
|
+
* that is tipped on its side (Uranus) and a moon that keeps one face to its planet (it turns once an orbit, the way it goes round).
|
|
24
|
+
*
|
|
25
|
+
* @param id - The body's name.
|
|
26
|
+
* @param ms - The moment, in milliseconds since the Unix epoch.
|
|
27
|
+
* @returns The spin axis and the north pole.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { spinAxis } from "@johnmorrisdotca/wakusei-planets/space";
|
|
32
|
+
*
|
|
33
|
+
* const venus = spinAxis("venus", Date.UTC(2026, 10, 2));
|
|
34
|
+
* console.log(venus.retrograde, venus.axis.map((n) => n.toFixed(2)).join(", "));
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function spinAxis(id: BodyId, ms: number): SpinAxis;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Which way a body spins, as the space view's help mode shows it: the axis it turns about (by the right-hand rule, so the fingers curl the way it turns) and the line of its poles. Pure.
|
|
2
|
+
import { orientation } from "../scene/orient.js";
|
|
3
|
+
import { cross, length, unit } from "../vec.js";
|
|
4
|
+
/**
|
|
5
|
+
* The axis a body spins about at `ms`, in the scene's axes (J2000 equatorial, y north), from how its prime meridian moves over ten minutes, so it is right for a body that turns backwards (Venus, Uranus, Pluto), one
|
|
6
|
+
* that is tipped on its side (Uranus) and a moon that keeps one face to its planet (it turns once an orbit, the way it goes round).
|
|
7
|
+
*
|
|
8
|
+
* @param id - The body's name.
|
|
9
|
+
* @param ms - The moment, in milliseconds since the Unix epoch.
|
|
10
|
+
* @returns The spin axis and the north pole.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { spinAxis } from "@johnmorrisdotca/wakusei-planets/space";
|
|
15
|
+
*
|
|
16
|
+
* const venus = spinAxis("venus", Date.UTC(2026, 10, 2));
|
|
17
|
+
* console.log(venus.retrograde, venus.axis.map((n) => n.toFixed(2)).join(", "));
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function spinAxis(id, ms) {
|
|
21
|
+
const now = orientation(id, ms);
|
|
22
|
+
const later = orientation(id, ms + 600_000);
|
|
23
|
+
const turn = cross(now.meridian, later.meridian);
|
|
24
|
+
const pole = unit(now.pole);
|
|
25
|
+
// a body that turns by less than a rounding error in ten minutes (none here) would have no axis: fall back to the pole
|
|
26
|
+
const axis = length(turn) < 1e-12 ? pole : unit(turn);
|
|
27
|
+
const along = axis[0] * pole[0] + axis[1] * pole[1] + axis[2] * pole[2];
|
|
28
|
+
return { axis, pole, retrograde: along < 0 };
|
|
29
|
+
}
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.32.0";
|