@johnmorrisdotca/wakusei-planets 0.20.0 → 0.21.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 +13 -0
- package/NOTICE.md +9 -0
- package/README.md +34 -4
- package/dist/bodies/earth.js +13 -5
- package/dist/calendar.js +7 -6
- package/dist/clock.js +5 -6
- package/dist/coordinates.d.ts +7 -12
- package/dist/coordinates.js +19 -18
- package/dist/craft/cassini.d.ts +1 -0
- package/dist/craft/cassini.js +1131 -0
- package/dist/craft/galileo.d.ts +1 -0
- package/dist/craft/galileo.js +224 -0
- package/dist/craft/juno.d.ts +1 -0
- package/dist/craft/juno.js +640 -0
- package/dist/craft/newhorizons.d.ts +1 -0
- package/dist/craft/newhorizons.js +18 -0
- package/dist/craft/parker.d.ts +1 -0
- package/dist/craft/parker.js +221 -0
- package/dist/craft/pioneer10.d.ts +1 -0
- package/dist/craft/pioneer10.js +24 -0
- package/dist/craft/pioneer11.d.ts +1 -0
- package/dist/craft/pioneer11.js +34 -0
- package/dist/craft/voyager1.d.ts +1 -0
- package/dist/craft/voyager1.js +28 -0
- package/dist/craft/voyager2.d.ts +1 -0
- package/dist/craft/voyager2.js +43 -0
- package/dist/craft/webb.d.ts +1 -0
- package/dist/craft/webb.js +28 -0
- package/dist/data/craft.d.ts +23 -0
- package/dist/data/craft.js +53 -0
- package/dist/data/stars.d.ts +4 -0
- package/dist/data/stars.js +5088 -0
- package/dist/element.d.ts +1 -23
- package/dist/element.js +74 -110
- package/dist/ephemeris.d.ts +20 -0
- package/dist/ephemeris.js +51 -20
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/portrait/element.d.ts +1 -0
- package/dist/portrait/element.js +27 -39
- package/dist/scene/basis.d.ts +3 -0
- package/dist/scene/basis.js +4 -0
- package/dist/scene/body.d.ts +2 -4
- package/dist/scene/body.js +55 -67
- package/dist/scene/fallback.d.ts +4 -0
- package/dist/scene/fallback.js +5 -0
- package/dist/scene/painter.js +10 -23
- package/dist/scene/store.d.ts +2 -2
- package/dist/scene/textures.d.ts +30 -0
- package/dist/scene/textures.js +47 -0
- package/dist/sidereal.d.ts +4 -0
- package/dist/sidereal.js +15 -9
- package/dist/sky/engine.d.ts +6 -15
- package/dist/sky/engine.js +9 -38
- package/dist/sky/frames.d.ts +3 -0
- package/dist/sky/frames.js +26 -0
- package/dist/sky/types.d.ts +20 -0
- package/dist/sky/types.js +1 -0
- package/dist/space/aim.d.ts +18 -0
- package/dist/space/aim.js +28 -0
- package/dist/space/element.d.ts +212 -0
- package/dist/space/element.js +524 -0
- package/dist/space/frame.d.ts +152 -0
- package/dist/space/frame.js +169 -0
- package/dist/space/index.d.ts +4 -0
- package/dist/space/index.js +5 -0
- package/dist/space/ride.d.ts +89 -0
- package/dist/space/ride.js +58 -0
- package/dist/space/scale.d.ts +126 -0
- package/dist/space/scale.js +139 -0
- package/dist/space/scene.d.ts +189 -0
- package/dist/space/scene.js +422 -0
- package/dist/spacecraft-facts.d.ts +114 -0
- package/dist/spacecraft-facts.js +215 -0
- package/dist/spacecraft.d.ts +134 -0
- package/dist/spacecraft.js +198 -0
- package/dist/stars.d.ts +160 -0
- package/dist/stars.js +193 -0
- package/dist/suncalc.js +4 -10
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/when.js +6 -11
- package/package.json +53 -4
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// Where the Sun, the Moon and the planets are, as seen from the centre of the Earth, for any date, from this package's own models (VSOP87B planets, the Pluto table, ELP2000 Moon).
|
|
2
|
+
// Positions are geometric (no aberration or nutation, about 20 arc-seconds), in the painter's axes: J2000 equatorial, x to the vernal equinox, y north. Pure: no DOM, no three.js.
|
|
3
|
+
import { heliocentric, moonGeocentric } from "../ephemeris.js";
|
|
4
|
+
import { OBLIQUITY, RAD } from "../vec.js";
|
|
5
|
+
import { earthPosition } from "../theory.js";
|
|
6
|
+
import { DAY_MS } from "../clock.js";
|
|
7
|
+
/** Kilometres in one astronomical unit. */
|
|
8
|
+
const AU_KM = 149_597_870.7;
|
|
9
|
+
/**
|
|
10
|
+
* The Earth's equatorial radius in kilometres (IAU), the unit of the scene's distances.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { EARTH_RADIUS_KM } from "@johnmorrisdotca/wakusei-planets/space";
|
|
15
|
+
*
|
|
16
|
+
* console.log(EARTH_RADIUS_KM);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const EARTH_RADIUS_KM = 6378.137;
|
|
20
|
+
/**
|
|
21
|
+
* Earth radii in one astronomical unit.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { AU_IN_EARTH_RADII } from "@johnmorrisdotca/wakusei-planets/space";
|
|
26
|
+
*
|
|
27
|
+
* console.log(Math.round(AU_IN_EARTH_RADII));
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export const AU_IN_EARTH_RADII = AU_KM / EARTH_RADIUS_KM;
|
|
31
|
+
/**
|
|
32
|
+
* The planets the space view places, nearest the Sun first (the Earth is the middle of the view).
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { SPACE_PLANETS } from "@johnmorrisdotca/wakusei-planets/space";
|
|
37
|
+
*
|
|
38
|
+
* console.log(SPACE_PLANETS.join(", "));
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export const SPACE_PLANETS = ["mercury", "venus", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto"];
|
|
42
|
+
/** An ecliptic J2000 vector in the scene's axes (equatorial J2000, y north). */
|
|
43
|
+
const scene = (v) => {
|
|
44
|
+
const c = Math.cos(OBLIQUITY * RAD);
|
|
45
|
+
const s = Math.sin(OBLIQUITY * RAD);
|
|
46
|
+
return [v[0], v[1] * s + v[2] * c, -(v[1] * c - v[2] * s)];
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The state of the sky at `ms`: the Sun, the Moon and eight planets as seen from the Earth's centre, worked out by this package's own models in a fraction of a millisecond.
|
|
50
|
+
*
|
|
51
|
+
* @param ms - A moment, in milliseconds since the Unix epoch.
|
|
52
|
+
* @returns The Sun, the Moon and the planets in astronomical units from the Earth's centre.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { frameAt } from "@johnmorrisdotca/wakusei-planets/space";
|
|
57
|
+
*
|
|
58
|
+
* const frame = frameAt(Date.UTC(2026, 10, 2, 12));
|
|
59
|
+
* console.log(frame.moon.map((n) => n.toFixed(4)));
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export function frameAt(ms) {
|
|
63
|
+
const earth = earthPosition(ms);
|
|
64
|
+
const planets = {};
|
|
65
|
+
for (const id of SPACE_PLANETS) {
|
|
66
|
+
const h = heliocentric(id, ms);
|
|
67
|
+
planets[id] = scene([h[0] - earth[0], h[1] - earth[1], h[2] - earth[2]]);
|
|
68
|
+
}
|
|
69
|
+
const moon = moonGeocentric(ms);
|
|
70
|
+
return { ms, sun: scene([-earth[0], -earth[1], -earth[2]]), moon: scene([moon[0] / AU_KM, moon[1] / AU_KM, moon[2] / AU_KM]), planets };
|
|
71
|
+
}
|
|
72
|
+
const lerp3 = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
|
|
73
|
+
/**
|
|
74
|
+
* A frame between two others, `t` from 0 to 1.
|
|
75
|
+
*
|
|
76
|
+
* @param a - The earlier frame.
|
|
77
|
+
* @param b - The later frame.
|
|
78
|
+
* @param t - How far from `a` to `b`, from 0 to 1.
|
|
79
|
+
* @returns The frame at that fraction.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { blend, frameAt } from "@johnmorrisdotca/wakusei-planets/space";
|
|
84
|
+
*
|
|
85
|
+
* const start = Date.UTC(2026, 10, 2);
|
|
86
|
+
* const middle = blend(frameAt(start), frameAt(start + 1000), 0.5);
|
|
87
|
+
* console.log(middle.ms - start);
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export function blend(a, b, t) {
|
|
91
|
+
const planets = {};
|
|
92
|
+
for (const id of SPACE_PLANETS)
|
|
93
|
+
planets[id] = lerp3(a.planets[id], b.planets[id], t);
|
|
94
|
+
return { ms: a.ms + (b.ms - a.ms) * t, sun: lerp3(a.sun, b.sun, t), moon: lerp3(a.moon, b.moon, t), planets };
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Answers for any moment from two real ones: `at(ms)` works out a frame only when `ms` leaves the span the last two answers cover, and then looks `stepMs` ahead, so playing
|
|
98
|
+
* time at a steady rate costs one pair of lookups every `stepMs` and every draw in between is arithmetic.
|
|
99
|
+
*
|
|
100
|
+
* @param initialStepMs - How far ahead the second answer looks, in milliseconds.
|
|
101
|
+
* @returns A track: `at(ms)` for a frame, `lookups` for how many frames were worked out, `ends()` for the two answers it is between (undefined before the first `at`), `reset()` and `setStep(ms)`.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { createTrack } from "@johnmorrisdotca/wakusei-planets/space";
|
|
106
|
+
*
|
|
107
|
+
* const track = createTrack(1000);
|
|
108
|
+
* const start = Date.UTC(2026, 10, 2);
|
|
109
|
+
* for (let step = 0; step < 10; step += 1) track.at(start + step * 50);
|
|
110
|
+
* console.log(track.lookups);
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export function createTrack(initialStepMs = 1000) {
|
|
114
|
+
let stepMs = initialStepMs;
|
|
115
|
+
let a;
|
|
116
|
+
let b;
|
|
117
|
+
let lookups = 0;
|
|
118
|
+
return {
|
|
119
|
+
at(ms) {
|
|
120
|
+
if (!a || !b || ms < a.ms || ms > b.ms) {
|
|
121
|
+
a = frameAt(ms);
|
|
122
|
+
b = frameAt(ms + stepMs);
|
|
123
|
+
lookups += 2;
|
|
124
|
+
}
|
|
125
|
+
return blend(a, b, (ms - a.ms) / (b.ms - a.ms));
|
|
126
|
+
},
|
|
127
|
+
/** The two answers the track is between now (undefined before the first). */
|
|
128
|
+
ends() {
|
|
129
|
+
return a && b ? [a, b] : undefined;
|
|
130
|
+
},
|
|
131
|
+
/** How many frames have been worked out. */
|
|
132
|
+
get lookups() {
|
|
133
|
+
return lookups;
|
|
134
|
+
},
|
|
135
|
+
reset() {
|
|
136
|
+
a = undefined;
|
|
137
|
+
b = undefined;
|
|
138
|
+
},
|
|
139
|
+
/** Look further ahead (a faster game clock): the next lookup uses it. */
|
|
140
|
+
setStep(ms) {
|
|
141
|
+
stepMs = Math.max(1, ms);
|
|
142
|
+
a = undefined;
|
|
143
|
+
b = undefined;
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
const PERIOD_DAYS = { mercury: 87.97, venus: 224.7, mars: 686.98, jupiter: 4332.6, saturn: 10_759, uranus: 30_688, neptune: 60_182, pluto: 90_560 };
|
|
148
|
+
/**
|
|
149
|
+
* The path a planet takes round the Sun, as `count + 1` points round one trip from where the planet is at `ms`, from the Sun, in astronomical units and the scene's axes.
|
|
150
|
+
*
|
|
151
|
+
* @param id - The planet.
|
|
152
|
+
* @param ms - The moment the path starts at, in milliseconds since the Unix epoch.
|
|
153
|
+
* @param count - How many segments to cut the trip into.
|
|
154
|
+
* @returns `count + 1` points; the last is near the first.
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```ts
|
|
158
|
+
* import { planetOrbit } from "@johnmorrisdotca/wakusei-planets/space";
|
|
159
|
+
*
|
|
160
|
+
* const points = planetOrbit("jupiter", Date.UTC(2026, 10, 2), 12);
|
|
161
|
+
* console.log(points.length);
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
export function planetOrbit(id, ms, count = 96) {
|
|
165
|
+
const points = [];
|
|
166
|
+
for (let i = 0; i <= count; i += 1)
|
|
167
|
+
points.push(scene(heliocentric(id, ms + (i / count) * PERIOD_DAYS[id] * DAY_MS)));
|
|
168
|
+
return points;
|
|
169
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, planetOrbit, SPACE_PLANETS, type SpaceFrame, type SpacePlanet, type SpaceVec3 } from "./frame.ts";
|
|
2
|
+
export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
|
|
3
|
+
export { groundDirection } from "./aim.ts";
|
|
4
|
+
export { RIDE_FOV, ridePose, type RideInput, type RideLook, type RidePose } from "./ride.ts";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// The space view's pure parts: where the bodies are (this package's own models), the two scales and, for riding along, where a camera looks. They import on a server. The element is `@johnmorrisdotca/wakusei-planets/space/element`.
|
|
2
|
+
export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, planetOrbit, SPACE_PLANETS } from "./frame.js";
|
|
3
|
+
export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, radiusIn, SUN_COMPRESSED, truePosition } from "./scale.js";
|
|
4
|
+
export { groundDirection } from "./aim.js";
|
|
5
|
+
export { RIDE_FOV, ridePose } from "./ride.js";
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type Vec3 } from "../vec.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The field of view, in degrees, of a camera riding along at zoom 1.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { RIDE_FOV } from "@johnmorrisdotca/wakusei-planets/space";
|
|
8
|
+
*
|
|
9
|
+
* console.log(RIDE_FOV);
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export declare const RIDE_FOV = 60;
|
|
13
|
+
/**
|
|
14
|
+
* Where a riding camera looks: `down` straight at the centre of the body it goes round (the ground goes by under the camera), or `horizon` tipped forward along the way it is going until the horizon
|
|
15
|
+
* is a little above the middle of the view.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import type { RideLook } from "@johnmorrisdotca/wakusei-planets/space";
|
|
20
|
+
*
|
|
21
|
+
* const looks: RideLook[] = ["down", "horizon"];
|
|
22
|
+
* console.log(looks.join(" or "));
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export type RideLook = "down" | "horizon";
|
|
26
|
+
/**
|
|
27
|
+
* What `ridePose` is asked: the camera's place from the centre of the body it goes round and its way of travel (any length), that body's radius in the unit of the place, where it looks,
|
|
28
|
+
* and the shared controls' yaw, tilt and zoom.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* import type { RideInput } from "@johnmorrisdotca/wakusei-planets/space";
|
|
33
|
+
*
|
|
34
|
+
* const input: RideInput = { position: [1.066, 0, 0], velocity: [0, 0, -7.66], radius: 1, look: "down", yaw: 0, tilt: 0, zoom: 1 };
|
|
35
|
+
* console.log(input.look);
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export interface RideInput {
|
|
39
|
+
/** The camera's place from the centre of the body it goes round, in any unit, in the scene's axes. */
|
|
40
|
+
position: Vec3;
|
|
41
|
+
/** Its direction of travel, in any unit: only the direction is used. */
|
|
42
|
+
velocity: Vec3;
|
|
43
|
+
/** The radius of the body it goes round, in the unit of `position` (1 when the place is in radii of that body). */
|
|
44
|
+
radius: number;
|
|
45
|
+
look: RideLook;
|
|
46
|
+
/** The shared controls' yaw in degrees (a drag across the view is 180): turns the camera to look along its picture's left, so the ground moves right. 0 has the way it is going at the top of the picture. */
|
|
47
|
+
yaw: number;
|
|
48
|
+
/** The shared controls' tilt in degrees (a drag down the view is 60): tips the camera to look towards the bottom of its picture, so the ground moves up. */
|
|
49
|
+
tilt: number;
|
|
50
|
+
/** 1 is the natural view; more narrows the field of view. */
|
|
51
|
+
zoom: number;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The camera `ridePose` works out: where it is, which way it looks, which way is up in the picture, its field of view in degrees, and how big the body looks from there (its angular radius in degrees).
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import type { RidePose } from "@johnmorrisdotca/wakusei-planets/space";
|
|
59
|
+
*
|
|
60
|
+
* const describe = (pose: RidePose): string => `looking ${pose.forward.map((n) => n.toFixed(2)).join(",")} with a ${pose.fov} degree view`;
|
|
61
|
+
* console.log(typeof describe);
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export interface RidePose {
|
|
65
|
+
position: Vec3;
|
|
66
|
+
forward: Vec3;
|
|
67
|
+
up: Vec3;
|
|
68
|
+
fov: number;
|
|
69
|
+
/** The angular radius of the body it goes round, in degrees: 90 when the camera is on or inside it. */
|
|
70
|
+
bodyRadiusDegrees: number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The camera of a body-borne view: at `position`, looking at the body it goes round (a Moon over the Earth, a moon over Jupiter, a spacecraft over Mars: any centre, by `radius`), with the way
|
|
74
|
+
* it is going at the top of the picture. `look: "horizon"` tips it forward until the horizon is a little above the middle. A drag looks about from there, as a head on a pivot does: `yaw` turns the
|
|
75
|
+
* camera to its left and `tilt` tips it towards the bottom of its picture, so the ground follows the pointer (right for a drag right, up for a drag up); the angle for each pixel of the drag is the
|
|
76
|
+
* field of view's, so the pace is the same at any zoom. `zoom` narrows the field of view.
|
|
77
|
+
*
|
|
78
|
+
* @param input - The camera's place, its way of travel, the radius of what it goes round, the look, and the shared controls' yaw, tilt and zoom.
|
|
79
|
+
* @returns The camera's place, forward and up directions (unit vectors), its field of view, and the body's angular radius from there.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { ridePose } from "@johnmorrisdotca/wakusei-planets/space";
|
|
84
|
+
*
|
|
85
|
+
* const pose = ridePose({ position: [1.066, 0, 0], velocity: [0, 0, -7.66], radius: 1, look: "down", yaw: 0, tilt: 0, zoom: 1 });
|
|
86
|
+
* console.log(pose.forward.map((n) => n.toFixed(2)).join(","), pose.bodyRadiusDegrees.toFixed(0));
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function ridePose(input: RideInput): RidePose;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Riding along: the camera sits at a moving point (a moon, a planet, a satellite someone else tracks) and looks at the body it goes round. This file is the maths of where it looks, pure,
|
|
2
|
+
// so a page or a test can ask the same question the space view does. It knows no satellites: any point with a place and a way of going will do, and any central body, by its radius.
|
|
3
|
+
import { cross, dot, length, RAD, scale, unit, add } from "../vec.js";
|
|
4
|
+
/** How far the ground moves in the picture for each pixel of a drag at the middle of it: the same pace as the line globe and the Earth from space (about one and a half). */
|
|
5
|
+
const GRAB = 1.5;
|
|
6
|
+
/**
|
|
7
|
+
* The field of view, in degrees, of a camera riding along at zoom 1.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { RIDE_FOV } from "@johnmorrisdotca/wakusei-planets/space";
|
|
12
|
+
*
|
|
13
|
+
* console.log(RIDE_FOV);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export const RIDE_FOV = 60;
|
|
17
|
+
/**
|
|
18
|
+
* The camera of a body-borne view: at `position`, looking at the body it goes round (a Moon over the Earth, a moon over Jupiter, a spacecraft over Mars: any centre, by `radius`), with the way
|
|
19
|
+
* it is going at the top of the picture. `look: "horizon"` tips it forward until the horizon is a little above the middle. A drag looks about from there, as a head on a pivot does: `yaw` turns the
|
|
20
|
+
* camera to its left and `tilt` tips it towards the bottom of its picture, so the ground follows the pointer (right for a drag right, up for a drag up); the angle for each pixel of the drag is the
|
|
21
|
+
* field of view's, so the pace is the same at any zoom. `zoom` narrows the field of view.
|
|
22
|
+
*
|
|
23
|
+
* @param input - The camera's place, its way of travel, the radius of what it goes round, the look, and the shared controls' yaw, tilt and zoom.
|
|
24
|
+
* @returns The camera's place, forward and up directions (unit vectors), its field of view, and the body's angular radius from there.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { ridePose } from "@johnmorrisdotca/wakusei-planets/space";
|
|
29
|
+
*
|
|
30
|
+
* const pose = ridePose({ position: [1.066, 0, 0], velocity: [0, 0, -7.66], radius: 1, look: "down", yaw: 0, tilt: 0, zoom: 1 });
|
|
31
|
+
* console.log(pose.forward.map((n) => n.toFixed(2)).join(","), pose.bodyRadiusDegrees.toFixed(0));
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function ridePose(input) {
|
|
35
|
+
const radius = Math.max(1e-12, input.radius);
|
|
36
|
+
const distance = Math.max(1e-9 * radius, length(input.position));
|
|
37
|
+
const nadir = scale(input.position, -1 / distance);
|
|
38
|
+
let ahead = add(input.velocity, scale(nadir, -dot(input.velocity, nadir)));
|
|
39
|
+
if (length(ahead) < 1e-12 * Math.max(1, length(input.velocity))) {
|
|
40
|
+
// no way of travel to go by (or it is straight at the body): north, or east where north is straight down
|
|
41
|
+
const north = [0, 1, 0];
|
|
42
|
+
ahead = add(north, scale(nadir, -dot(north, nadir)));
|
|
43
|
+
if (length(ahead) < 1e-9)
|
|
44
|
+
ahead = cross([1, 0, 0], nadir);
|
|
45
|
+
}
|
|
46
|
+
ahead = unit(ahead);
|
|
47
|
+
const bodyRadiusDegrees = distance <= radius ? 90 : Math.asin(radius / distance) / RAD;
|
|
48
|
+
const base = input.look === "horizon" ? Math.max(0, bodyRadiusDegrees - 12) * RAD : 0;
|
|
49
|
+
const forward0 = add(scale(nadir, Math.cos(base)), scale(ahead, Math.sin(base)));
|
|
50
|
+
const up0 = add(scale(ahead, Math.cos(base)), scale(nadir, -Math.sin(base)));
|
|
51
|
+
const fov = Math.min(100, Math.max(5, RIDE_FOV / Math.max(0.05, input.zoom)));
|
|
52
|
+
const turn = input.yaw * ((GRAB * fov) / 180) * RAD;
|
|
53
|
+
const lift = input.tilt * ((GRAB * fov) / 60) * RAD;
|
|
54
|
+
const turned = add(scale(forward0, Math.cos(turn)), scale(cross(up0, forward0), Math.sin(turn)));
|
|
55
|
+
const forward = add(scale(turned, Math.cos(lift)), scale(up0, -Math.sin(lift)));
|
|
56
|
+
const up = add(scale(up0, Math.cos(lift)), scale(turned, Math.sin(lift)));
|
|
57
|
+
return { position: [input.position[0], input.position[1], input.position[2]], forward, up, fov, bodyRadiusDegrees };
|
|
58
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { Vec3 } from "../vec.ts";
|
|
2
|
+
import { type SpacePlanet } from "./frame.ts";
|
|
3
|
+
/**
|
|
4
|
+
* The scale the space view is drawn in: `compressed` squeezes the distances so the Moon, the Sun and Neptune fit one view, and `true` keeps the real ones.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { placeMoon, type ScaleMode } from "@johnmorrisdotca/wakusei-planets/space";
|
|
9
|
+
*
|
|
10
|
+
* const mode: ScaleMode = "compressed";
|
|
11
|
+
* console.log(placeMoon(mode, [0.00257, 0, 0]));
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export type ScaleMode = "compressed" | "true";
|
|
15
|
+
/**
|
|
16
|
+
* The Moon's distance in a compressed view, in Earth radii (the true one is about 60).
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { MOON_COMPRESSED } from "@johnmorrisdotca/wakusei-planets/space";
|
|
21
|
+
*
|
|
22
|
+
* console.log(MOON_COMPRESSED);
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare const MOON_COMPRESSED = 10;
|
|
26
|
+
/**
|
|
27
|
+
* The Sun's distance from the Earth in a compressed view, in Earth radii (the true one is about 23,500). One astronomical unit is this long there.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { SUN_COMPRESSED } from "@johnmorrisdotca/wakusei-planets/space";
|
|
32
|
+
*
|
|
33
|
+
* console.log(SUN_COMPRESSED);
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const SUN_COMPRESSED = 44;
|
|
37
|
+
/**
|
|
38
|
+
* A place in astronomical units from the Earth's centre, at true distance, in Earth radii.
|
|
39
|
+
*
|
|
40
|
+
* @param v - The place, in astronomical units.
|
|
41
|
+
* @returns The same direction, in Earth radii.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { truePosition } from "@johnmorrisdotca/wakusei-planets/space";
|
|
46
|
+
*
|
|
47
|
+
* console.log(truePosition([0.00257, 0, 0]).map(Math.round));
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare const truePosition: (v: Vec3) => Vec3;
|
|
51
|
+
/**
|
|
52
|
+
* The same direction at a compressed distance from the Earth: the Moon is 10 Earth radii away, and a body k times further than the Moon is k^0.25 times as far here.
|
|
53
|
+
*
|
|
54
|
+
* @param v - The place, in astronomical units from the Earth's centre.
|
|
55
|
+
* @returns The place in Earth radii, compressed; the centre stays at the centre.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { compress } from "@johnmorrisdotca/wakusei-planets/space";
|
|
60
|
+
*
|
|
61
|
+
* console.log(compress([0.00257, 0, 0]), compress([0, 0, 0]));
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function compress(v: Vec3): Vec3;
|
|
65
|
+
/**
|
|
66
|
+
* The Moon, from the Earth's centre.
|
|
67
|
+
*
|
|
68
|
+
* @param mode - The scale.
|
|
69
|
+
* @param geo - The Moon's place in astronomical units from the Earth's centre.
|
|
70
|
+
* @returns Where to draw it, in Earth radii.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { placeMoon } from "@johnmorrisdotca/wakusei-planets/space";
|
|
75
|
+
*
|
|
76
|
+
* console.log(placeMoon("true", [0.00257, 0, 0]).map(Math.round));
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare const placeMoon: (mode: ScaleMode, geo: Vec3) => Vec3;
|
|
80
|
+
/**
|
|
81
|
+
* The Sun, from the Earth's centre: in a compressed view always 44 Earth radii away, in its real direction.
|
|
82
|
+
*
|
|
83
|
+
* @param mode - The scale.
|
|
84
|
+
* @param geo - The Sun's place in astronomical units from the Earth's centre.
|
|
85
|
+
* @returns Where to draw it, in Earth radii.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* import { placeSun } from "@johnmorrisdotca/wakusei-planets/space";
|
|
90
|
+
*
|
|
91
|
+
* console.log(placeSun("compressed", [1, 0, 0]));
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export declare function placeSun(mode: ScaleMode, geo: Vec3): Vec3;
|
|
95
|
+
/**
|
|
96
|
+
* A place `helio` astronomical units from the Sun (a planet, or a point on its orbit), round the Sun at `sun`. True: as it is. Compressed: the same direction from
|
|
97
|
+
* the Sun, at 44 Earth radii times its distance in astronomical units to the power 0.45, so the Earth's own orbit is the 44 and Neptune's is about 200 (30 times as far, really).
|
|
98
|
+
*
|
|
99
|
+
* @param mode - The scale.
|
|
100
|
+
* @param sun - Where the Sun is drawn, in Earth radii.
|
|
101
|
+
* @param helio - The place in astronomical units from the Sun.
|
|
102
|
+
* @returns Where to draw the place, in Earth radii from the Earth's centre.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```ts
|
|
106
|
+
* import { placeAround } from "@johnmorrisdotca/wakusei-planets/space";
|
|
107
|
+
*
|
|
108
|
+
* console.log(placeAround("compressed", [44, 0, 0], [1, 0, 0]));
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export declare function placeAround(mode: ScaleMode, sun: Vec3, helio: Vec3): Vec3;
|
|
112
|
+
/**
|
|
113
|
+
* A body's radius in Earth radii: the real one, or one large enough to see in a compressed view.
|
|
114
|
+
*
|
|
115
|
+
* @param id - The Sun, the Earth, the Moon or a planet.
|
|
116
|
+
* @param mode - The scale.
|
|
117
|
+
* @returns The radius to draw it at, in Earth radii.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { radiusIn } from "@johnmorrisdotca/wakusei-planets/space";
|
|
122
|
+
*
|
|
123
|
+
* console.log(radiusIn("moon", "true").toFixed(3), radiusIn("moon", "compressed"));
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare function radiusIn(id: "sun" | "earth" | "moon" | SpacePlanet, mode: ScaleMode): number;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
// The two scales the space view can show. The true one is the Earth's radius for a unit and the real distances in it; the compressed one keeps every direction but squeezes the
|
|
2
|
+
// distances so that the Moon, the Sun and Neptune fit one view. Pure.
|
|
3
|
+
import { BODIES } from "../facts.js";
|
|
4
|
+
import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM } from "./frame.js";
|
|
5
|
+
const MOON_AU = 0.00257;
|
|
6
|
+
/**
|
|
7
|
+
* The Moon's distance in a compressed view, in Earth radii (the true one is about 60).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { MOON_COMPRESSED } from "@johnmorrisdotca/wakusei-planets/space";
|
|
12
|
+
*
|
|
13
|
+
* console.log(MOON_COMPRESSED);
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export const MOON_COMPRESSED = 10;
|
|
17
|
+
/**
|
|
18
|
+
* The Sun's distance from the Earth in a compressed view, in Earth radii (the true one is about 23,500). One astronomical unit is this long there.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { SUN_COMPRESSED } from "@johnmorrisdotca/wakusei-planets/space";
|
|
23
|
+
*
|
|
24
|
+
* console.log(SUN_COMPRESSED);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export const SUN_COMPRESSED = 44;
|
|
28
|
+
const length = (v) => Math.hypot(v[0], v[1], v[2]);
|
|
29
|
+
const scaled = (v, k) => [v[0] * k, v[1] * k, v[2] * k];
|
|
30
|
+
/**
|
|
31
|
+
* A place in astronomical units from the Earth's centre, at true distance, in Earth radii.
|
|
32
|
+
*
|
|
33
|
+
* @param v - The place, in astronomical units.
|
|
34
|
+
* @returns The same direction, in Earth radii.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { truePosition } from "@johnmorrisdotca/wakusei-planets/space";
|
|
39
|
+
*
|
|
40
|
+
* console.log(truePosition([0.00257, 0, 0]).map(Math.round));
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export const truePosition = (v) => scaled(v, AU_IN_EARTH_RADII);
|
|
44
|
+
/**
|
|
45
|
+
* The same direction at a compressed distance from the Earth: the Moon is 10 Earth radii away, and a body k times further than the Moon is k^0.25 times as far here.
|
|
46
|
+
*
|
|
47
|
+
* @param v - The place, in astronomical units from the Earth's centre.
|
|
48
|
+
* @returns The place in Earth radii, compressed; the centre stays at the centre.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* import { compress } from "@johnmorrisdotca/wakusei-planets/space";
|
|
53
|
+
*
|
|
54
|
+
* console.log(compress([0.00257, 0, 0]), compress([0, 0, 0]));
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export function compress(v) {
|
|
58
|
+
const l = length(v);
|
|
59
|
+
return l === 0 ? [0, 0, 0] : scaled(v, (MOON_COMPRESSED * (l / MOON_AU) ** 0.25) / l);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The Moon, from the Earth's centre.
|
|
63
|
+
*
|
|
64
|
+
* @param mode - The scale.
|
|
65
|
+
* @param geo - The Moon's place in astronomical units from the Earth's centre.
|
|
66
|
+
* @returns Where to draw it, in Earth radii.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* import { placeMoon } from "@johnmorrisdotca/wakusei-planets/space";
|
|
71
|
+
*
|
|
72
|
+
* console.log(placeMoon("true", [0.00257, 0, 0]).map(Math.round));
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export const placeMoon = (mode, geo) => (mode === "true" ? truePosition(geo) : compress(geo));
|
|
76
|
+
/**
|
|
77
|
+
* The Sun, from the Earth's centre: in a compressed view always 44 Earth radii away, in its real direction.
|
|
78
|
+
*
|
|
79
|
+
* @param mode - The scale.
|
|
80
|
+
* @param geo - The Sun's place in astronomical units from the Earth's centre.
|
|
81
|
+
* @returns Where to draw it, in Earth radii.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```ts
|
|
85
|
+
* import { placeSun } from "@johnmorrisdotca/wakusei-planets/space";
|
|
86
|
+
*
|
|
87
|
+
* console.log(placeSun("compressed", [1, 0, 0]));
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export function placeSun(mode, geo) {
|
|
91
|
+
if (mode === "true")
|
|
92
|
+
return truePosition(geo);
|
|
93
|
+
const l = length(geo);
|
|
94
|
+
return l === 0 ? [0, 0, 0] : scaled(geo, SUN_COMPRESSED / l);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* A place `helio` astronomical units from the Sun (a planet, or a point on its orbit), round the Sun at `sun`. True: as it is. Compressed: the same direction from
|
|
98
|
+
* the Sun, at 44 Earth radii times its distance in astronomical units to the power 0.45, so the Earth's own orbit is the 44 and Neptune's is about 200 (30 times as far, really).
|
|
99
|
+
*
|
|
100
|
+
* @param mode - The scale.
|
|
101
|
+
* @param sun - Where the Sun is drawn, in Earth radii.
|
|
102
|
+
* @param helio - The place in astronomical units from the Sun.
|
|
103
|
+
* @returns Where to draw the place, in Earth radii from the Earth's centre.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* import { placeAround } from "@johnmorrisdotca/wakusei-planets/space";
|
|
108
|
+
*
|
|
109
|
+
* console.log(placeAround("compressed", [44, 0, 0], [1, 0, 0]));
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export function placeAround(mode, sun, helio) {
|
|
113
|
+
if (mode === "true")
|
|
114
|
+
return [sun[0] + helio[0] * AU_IN_EARTH_RADII, sun[1] + helio[1] * AU_IN_EARTH_RADII, sun[2] + helio[2] * AU_IN_EARTH_RADII];
|
|
115
|
+
const l = length(helio);
|
|
116
|
+
if (l === 0)
|
|
117
|
+
return sun;
|
|
118
|
+
const d = (SUN_COMPRESSED * l ** 0.45) / l;
|
|
119
|
+
return [sun[0] + helio[0] * d, sun[1] + helio[1] * d, sun[2] + helio[2] * d];
|
|
120
|
+
}
|
|
121
|
+
/** The sizes a compressed view gives bodies large enough to see, in Earth radii. */
|
|
122
|
+
const COMPRESSED_RADIUS = { sun: 5, earth: 1, moon: 0.9, mercury: 0.5, venus: 0.8, mars: 0.6, jupiter: 1.8, saturn: 1.6, uranus: 1.0, neptune: 1.0, pluto: 0.4 };
|
|
123
|
+
/**
|
|
124
|
+
* A body's radius in Earth radii: the real one, or one large enough to see in a compressed view.
|
|
125
|
+
*
|
|
126
|
+
* @param id - The Sun, the Earth, the Moon or a planet.
|
|
127
|
+
* @param mode - The scale.
|
|
128
|
+
* @returns The radius to draw it at, in Earth radii.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* import { radiusIn } from "@johnmorrisdotca/wakusei-planets/space";
|
|
133
|
+
*
|
|
134
|
+
* console.log(radiusIn("moon", "true").toFixed(3), radiusIn("moon", "compressed"));
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export function radiusIn(id, mode) {
|
|
138
|
+
return mode === "true" ? BODIES[id].radiusKm / EARTH_RADIUS_KM : COMPRESSED_RADIUS[id];
|
|
139
|
+
}
|