@johnmorrisdotca/wakusei-planets 0.50.0 → 0.52.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 +14 -0
- package/NOTICE.md +1 -0
- package/README.md +4 -3
- package/dist/scene/textures.d.ts +2 -2
- package/dist/sky-bodies.d.ts +154 -0
- package/dist/sky-bodies.js +284 -0
- package/dist/space/element.d.ts +32 -3
- package/dist/space/element.js +80 -4
- package/dist/space/index.d.ts +1 -1
- package/dist/space/index.js +1 -1
- package/dist/space/scene.d.ts +2 -0
- package/dist/space/scene.js +9 -2
- package/dist/space/sight.d.ts +23 -0
- package/dist/space/sight.js +20 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.52.0] - 2026-11-13
|
|
6
|
+
|
|
7
|
+
- **The craft page's Play moves only its marker** (MODULES-1339). `demo/craft.html` no longer redraws the whole chart on each Play step: it moves the marker and the line and leaves the rest alone, and `e2e/craft-freeze.demo.ts` counts the craft loop's frames apart from the page's others. Demo page only: the package is unchanged.
|
|
8
|
+
|
|
9
|
+
- **Where the planets are in the sky** (MODULES-1225). `skyBodies(when, observer?)` from `@johnmorrisdotca/wakusei-planets/sky-bodies` gives, for the Sun, the Moon, the seven other planets and Pluto, plain data: right ascension and declination of date and of J2000, distance, apparent magnitude, angular diameter, phase angle and illuminated fraction, `elongationDeg` and `east` (the evening side), the Moon's phase, waxing and bright limb, and, with an observer, azimuth, altitude (geometric and with refraction, the Moon's parallax in), hour angle, parallactic angle and `aboveHorizon`. `skyBody(id, when, observer?)` gives one and `SKY_BODY_IDS` is the order. Pure: the moment is passed in, no clock is read, nothing of the DOM. It is the package's own positions (the sky engine for the Sun and the Moon, VSOP87B with light time and aberration for the planets, Pluto's table): no second model. Checked against JPL Horizons on three dates and two places: the Sun, planets and Pluto within 0.1 arcminute, the Moon within 0.02 (of date) and 0.015 (J2000), diameters within 0.1 per cent, azimuth and altitude within 0.1 arcminute, magnitudes within 0.02 to 0.06 (Mars 0.1, Pluto 0.5). A star chart takes the list as data the page passes in. Guide: `docs/guides/sky-bodies.md` and its Japanese twin, and `examples/sky-bodies/node.mjs`.
|
|
10
|
+
|
|
11
|
+
## [0.51.0] - 2026-11-13
|
|
12
|
+
|
|
13
|
+
- **What a page can ask of the view's sight** (MODULES-1220). Every entry of `sight()` and `wakusei-sight` now says `offAxis` (degrees between the camera's forward direction and the body, 0 to 180), `distance` (from the camera, in Earth radii) and `distanceKm` (in kilometres in the true scale, `null` in the compressed one), so a page can rank its edge markers by nearness; `angle` is unchanged. `turnTo(id, { smooth, margin })` turns the camera where it stands until a body is in the picture, by the least turn, and says whether it did: in the picture means the body's middle is inside the picture less `margin` of each side (0.15 of the width for the left and right and of the height for the top and bottom by default, 0 to 0.45); a body already so, the body looked at, an unknown id and a ride answer `false` and draw nothing. The camera does not move (the body becomes the one looked at, from where the camera stands). An orbiter is an entry of `sight()` with `kind: "orbiter"` and the id `orbiter` takes (`lro`, `mro`), and a press on its name sends `wakusei-orbiter-click` with `{ id, name }` as well as `wakusei-body-click`, which is unchanged. Guide: the space-view guide and its Japanese twin.
|
|
14
|
+
|
|
15
|
+
- **The spacecraft page plays on frames, and has a freeze test** (MODULES-1210). `demo/craft.html` no longer runs a timer every 0.7 s: Play drives `requestAnimationFrame` while it is on and the tab is seen, at the same pace (a ninetieth of the record in 0.7 s of the page's time), and a paused or hidden page schedules nothing. `e2e/craft-freeze.demo.ts` counts the frames the page asks for and the changes made to it on the page's own held clock: playing asks for a frame each page frame and changes the page, paused or hidden asks for none and changes nothing in two seconds, and on a phone the page has no sideways scroll, the picker, chart and events inside the screen and every button at least 40 px tall. In short, the craft page plays on frames and rests when paused or hidden. Demo page only: the package is unchanged.
|
|
16
|
+
|
|
17
|
+
- **Rates are read on the page's own clock** (test only, no change to the package): the tests of how fast things run (draws a second, game days a second, the ride's rate, the drag's frames, the date box) now install the page's clock, hold it and step it themselves (`e2e/clock.ts`), so a count is a count of the simulated seconds and does not depend on the speed of the machine; the soak runs one minute by default (`SOAK_MINUTES`) and its limit is not raised. Five repeats under CPU throttle 4 pass for each, and each has a fault that fails it, except the freeze drag test, whose new form is unproven (the fault tried did not reach it).
|
|
18
|
+
|
|
5
19
|
## [0.50.0] - 2026-11-13
|
|
6
20
|
|
|
7
21
|
- **Watch Apollo 17's powered descent** (MODULES-1333). `watch="landing"` on `<wakusei-surface>` (and `land(site, { watch: "landing" })` on `<wakusei-space>`) runs the descent at the real moment (the Sun, the Earth and the shadows of 19:42:52 to 19:54:57 UTC on 1972-12-11) from the commander's window or from the ground, with the clock, the report's moments shown as they pass, a scrubber (`landingTime`), `playLanding()`, `pauseLanding()`, `landingRate` and the `wakusei-landing-clock` event. **Real**: the times of the Apollo 17 Mission Report's table of events (ignition 110:09:53, radar lock T+3:35, throttle down T+7:26, high gate T+9:22, the first of eight redesignations, low gate T+10:58, touchdown T+12:05), the state at ignition (19.13 N, 48.75 E, 8.7 nautical miles, 5,550 ft/s, heading 276 degrees) and the altitudes it names (30,000 ft, 13,000 ft, pitchover at about 7,500 ft, manual takeover under 300 ft, dust at 60 to 70 ft, touchdown at about 3 ft/s). **Made, and said on the picture**: the altitude and speed between those moments (a smooth curve through them that covers the real distance), the ground path, the window's attitude, the plume, and the dust, thrown as a low sheet of many soft grains along the ground from the 60 to 70 ft call-out. The view starts at T+4:00 (the first minutes are beyond the ground the package has). The lunar module is drawn whole, with its plume and shadow; the ground camera stands 150 m north of the touchdown point (`watch-from`, `watch-camera`) and draws a ring with the height beside it until the stage is larger than about 6 pixels. Nothing is drawn once the descent is paused or finished.
|
package/NOTICE.md
CHANGED
|
@@ -17,6 +17,7 @@ No picture is used by the line and shaded looks: they are drawn from numbers.
|
|
|
17
17
|
- **Saturn's seven inner moons (`tables/saturn-moons`)**: the theory TASS1.7, A. Vienne and L. Duriez (1995), "TASS1.6: Ephemerides of the major Saturnian satellites", Astron. Astrophys. 297, 588, from IMCCE (https://ftp.imcce.fr/pub/ephem/satel/tass17/). The terms are read from `Src/Celbody/Satsat/tass17.dat` in Orbiter (https://github.com/orbitersim/orbiter, read 2026-11-08), the same table in one plain file, MIT licence: Copyright (c) 2000-2026 Martin Schweiger. The MIT notice of Orbiter follows. Cut to 316 terms (`scripts/make-tass17-data.py`, `src/data/tass17.ts`); `src/theories/tass17.ts` follows Orbiter's `Tass17.cpp` (a conversion of IMCCE's FORTRAN) and is checked against the values in IMCCE's `tass17.f`.
|
|
18
18
|
- **The Uranus, Mars and Neptune systems' moons** are still fitted to Horizons. IMCCE's GUST86 (Laskar and Jacobson 1987) and ESAPHO/ESADEI (Chapront-Touzé 1990) come with a notice that forbids redistributing changed files, so they are not used; nothing of them is in this package.
|
|
19
19
|
- **Sun and Moon times (`/suncalc`)**: written here from the standard methods: J. Meeus, "Astronomical Algorithms" (2nd edition, chapters 11, 12, 21, 22, 48), the IAU 1976 precession, the IAU 1980 nutation (its largest terms), Saemundsson's refraction formula, and the Naval Observatory's convention for the rise and set of the Moon and Sun. The names, arguments and results follow the public interface of suncalc (BSD-2-Clause, Copyright (c) Volodymyr Agafonkin; https://github.com/mourner/suncalc), whose code is not used. suncalc 1.9.0 and 2.1.2 and astronomy-engine (MIT) are development-time comparisons in `test/suncalc.test.ts` only and are not shipped.
|
|
20
|
+
- **Where the planets are in the sky (`/sky-bodies`)**, 2026-11-13: the positions are this package's own (the Sun and the Moon of `/suncalc`, VSOP87B for the planets, Pluto's table above). The planets' apparent magnitudes are the formulas of the Astronomical Almanac as given in A. Mallama and J. L. Hilton (2018), "Computing Apparent Planetary Magnitudes for The Astronomical Almanac", Astronomy and Computing 25, 10 (arXiv:1808.01973, read online 2026-11-13): the formulas only, typed as code (Mercury, Venus, Mars without its surface-albedo terms, Jupiter, Saturn with its rings, Uranus, Neptune after 2000); the Sun's apparent magnitude of -26.74 at one astronomical unit is the visual magnitude V(1,0) of NASA's Sun Fact Sheet (https://nssdc.gsfc.nasa.gov/planetary/factsheet/sunfact.html, read 2026-11-13), scaled by 5 log10 of the distance in astronomical units as in the JPL Horizons manual (https://ssd.jpl.nasa.gov/horizons/manual.html, read 2026-11-13); the Moon's magnitude law (-12.73 + 0.026 |phase angle| + 4e-9 phase angle to the fourth, plus 5 log10 of the distance over 384400 km) is the one the same Horizons manual gives for the Moon, after Krisciunas and Schaefer (1991), "A model of the brightness of moonlight", Publications of the Astronomical Society of the Pacific 103, 1033, cross-checked with the -12.74 of NASA's Moon Fact Sheet (https://nssdc.gsfc.nasa.gov/planetary/factsheet/moonfact.html, read 2026-11-13): the constants only, typed as code; and Pluto's H = -0.55 is from the JPL Small-Body Database (https://ssd-api.jpl.nasa.gov/sbdb.api, read 2026-11-13). The figures the tests compare with are numbers read online from JPL Horizons (https://ssd.jpl.nasa.gov/api/horizons.api, observer tables read 2026-11-13: R.A. and DEC (ICRF) and (a-appar), APmag, Illu%, Ang-diam, S-O-T, and Azi and Elev (a-app) for Tokyo, 139.69 E 35.69 N 40 m, and Ottawa, 75.70 W 45.42 N 70 m), on 2024-03-20 12:00, 2026-06-21 12:00 and 2030-12-01 00:00 UTC. Facts only: no text or file is copied.
|
|
20
21
|
- **Stars (`/stars`)**: the Yale Bright Star Catalogue, D. Hoffleit and W. H. Warren Jr. (1991), "The Bright Star Catalogue, 5th Revised Edition (Preliminary Version)", Astronomical Data Center (NASA Goddard Space Flight Center) and the Centre de Données astronomiques de Strasbourg, catalogue V/50, as NASA's HEASARC serves it (table bsc5p, https://heasarc.gsfc.nasa.gov/W3Browse/star-catalog/bsc5p.html, file heasarc_bsc5p.tdat.gz, read 2026-11-08; a US government source), the 5,080 stars to visual magnitude 6.0, written out as numbers by `scripts/make-star-data.py` into `src/data/stars.ts`. The catalogue's own documentation calls it public domain and the Astronomical Data Center asks that it and the authors be acknowledged, which this line does; there is no formal licence text, so this footing is informal. The common names are our own list after the IAU Working Group on Star Names (https://www.iau.org/science/scientific_bodies/working_groups/280/); the star colour is Ballesteros's B-V to temperature relation (F. J. Ballesteros 2012, EPL 97, 34008) and a piecewise black-body colour fit. Deliberately NOT used: the Hipparcos, Tycho and Gaia catalogues (ESA, CC BY-NC 3.0 IGO, non-commercial), and HYG, AT-HYG and OpenNGC (CC BY-SA, which would put share-alike terms on this package's data).
|
|
21
22
|
- **Mass and escape speed** (`JOURNEY_STOPS`): JPL "Planetary Satellite Physical Parameters" (https://ssd.jpl.nasa.gov/sats/phys_par/, read 2026-11-04) for the GM of the Earth, Mars through Pluto and the moons on that page; NASA's Sun, Mercury and Venus fact sheets (https://nssdc.gsfc.nasa.gov/planetary/factsheet/, read 2026-11-04) for those three GM values and the Sun's escape speed; JPL "Planetary Physical Parameters" (https://ssd.jpl.nasa.gov/planets/phys_par.html, read 2026-11-04) for the planets' escape speeds and for the masses of Ceres, Eris, Makemake and Haumea, turned into GM with the CODATA 2018 G that page names. A moon's escape speed is computed from its GM and the radius already in this package. Nereid, Orcus, Quaoar, Gonggong, Sedna, Vanth, Hiʻiaka, Namaka and Dysnomia are left blank: those pages do not print a mass.
|
|
22
23
|
|
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.52.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.52.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
|
|
|
@@ -498,6 +498,7 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
|
|
|
498
498
|
| [Data files](docs/guides/data-files.md) | CSV and Parquet tables of the bodies, orbits and spacecraft, for Python, R and Rust |
|
|
499
499
|
| [Serve it yourself](docs/guides/serve-it-yourself.md) | A small Node server over the package, that you host |
|
|
500
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 |
|
|
501
|
+
| [Where the planets are in the sky](docs/guides/sky-bodies.md) | The Sun, the Moon and the planets for a moment and a place: right ascension and declination of date and J2000, magnitude, size, phase, elongation, azimuth and altitude, as plain data |
|
|
501
502
|
| [Coordinate conversions](docs/guides/coordinates.md) | Pure spherical, ecliptic, equatorial and horizontal coordinate conversions |
|
|
502
503
|
| [TypeScript and Node](docs/guides/typescript-and-node.md) | Types and the pure side |
|
|
503
504
|
| [How it works](docs/guides/how-it-works.md) | Where the numbers come from |
|
|
@@ -536,7 +537,7 @@ BODIES.pluto.kind; // "dwarf-planet"
|
|
|
536
537
|
|
|
537
538
|
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:
|
|
538
539
|
|
|
539
|
-
> Morris, J. (2026). *Wakusei Planets* (version 0.
|
|
540
|
+
> Morris, J. (2026). *Wakusei Planets* (version 0.52.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
|
|
540
541
|
|
|
541
542
|
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).
|
|
542
543
|
|
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.52.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.52.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.
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import type { Observer } from "./sky/types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* The moments the calls accept, in milliseconds since 1970: from 1750-01-01 to 2250-01-01 UTC, the years the package's own checks hold the planet series (VSOP87B) and the rest to (the accuracy guide: the series
|
|
4
|
+
* "is good for the years 1750 to 2250 and slowly gets worse beyond"). A moment outside them throws a `RangeError` naming the range, so a number out of range is never returned as if it were good.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { SKY_RANGE } from "@johnmorrisdotca/wakusei-planets/sky-bodies";
|
|
9
|
+
*
|
|
10
|
+
* console.log(new Date(SKY_RANGE.from).getUTCFullYear(), new Date(SKY_RANGE.to).getUTCFullYear());
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare const SKY_RANGE: {
|
|
14
|
+
readonly from: number;
|
|
15
|
+
readonly to: number;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The names of the bodies `skyBodies` gives, in its order.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { SKY_BODY_IDS } from "@johnmorrisdotca/wakusei-planets/sky-bodies";
|
|
23
|
+
*
|
|
24
|
+
* console.log(SKY_BODY_IDS.length, SKY_BODY_IDS[1]);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const SKY_BODY_IDS: readonly ["sun", "moon", "mercury", "venus", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto"];
|
|
28
|
+
/**
|
|
29
|
+
* The name of a body in the sky list.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { skyBody, type SkyBodyId } from "@johnmorrisdotca/wakusei-planets/sky-bodies";
|
|
34
|
+
*
|
|
35
|
+
* const id: SkyBodyId = "venus";
|
|
36
|
+
* console.log(skyBody(id, Date.UTC(2026, 5, 21, 12)).name.en);
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export type SkyBodyId = (typeof SKY_BODY_IDS)[number];
|
|
40
|
+
/**
|
|
41
|
+
* Where a body is in the sky of a place: azimuth in degrees from north through east (0 to 360; 0 where it is not defined, at the zenith and the nadir and at a pole), altitude in degrees (geometric, parallax in, no refraction) and with the standard refraction (`apparentAltitude`),
|
|
42
|
+
* the hour angle (degrees, 0 on the meridian, positive west) and the parallactic angle.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts no-run
|
|
46
|
+
* import type { SkyHorizontal } from "@johnmorrisdotca/wakusei-planets/sky-bodies";
|
|
47
|
+
*
|
|
48
|
+
* const up = (h: SkyHorizontal): boolean => h.apparentAltitudeDeg > 0;
|
|
49
|
+
* console.log(typeof up);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export interface SkyHorizontal {
|
|
53
|
+
azimuthDeg: number;
|
|
54
|
+
altitudeDeg: number;
|
|
55
|
+
apparentAltitudeDeg: number;
|
|
56
|
+
hourAngleDeg: number;
|
|
57
|
+
parallacticAngleDeg: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* One body of the sky list. Angles are degrees, distances astronomical units (and kilometres), sizes arcseconds. `equatorialDate` is the apparent place of date (the true equator and equinox of the moment, aberration and
|
|
61
|
+
* nutation in), `equatorialJ2000` the same direction without aberration in the J2000 equatorial frame (what a chart on J2000 reads). The places are the Earth's centre's; `horizontal` is the place's.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts no-run
|
|
65
|
+
* import type { SkyBody } from "@johnmorrisdotca/wakusei-planets/sky-bodies";
|
|
66
|
+
*
|
|
67
|
+
* const bright = (list: SkyBody[]): SkyBody[] => list.filter((body) => body.magnitude < 2);
|
|
68
|
+
* console.log(typeof bright);
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export interface SkyBody {
|
|
72
|
+
id: SkyBodyId;
|
|
73
|
+
name: {
|
|
74
|
+
en: string;
|
|
75
|
+
ja: string;
|
|
76
|
+
};
|
|
77
|
+
kind: "star" | "moon" | "planet" | "dwarf";
|
|
78
|
+
/**
|
|
79
|
+
* Whether the figures hold to the stated accuracy: `true` for every body inside the range the call accepts, except Pluto outside its fitted table (1800 to 2199), where its place comes from an approximate
|
|
80
|
+
* orbit that is wrong by degrees: it is returned, with `accurate: false`, so one body does not break the list.
|
|
81
|
+
*/
|
|
82
|
+
accurate: boolean;
|
|
83
|
+
equatorialDate: {
|
|
84
|
+
rightAscensionDeg: number;
|
|
85
|
+
declinationDeg: number;
|
|
86
|
+
};
|
|
87
|
+
equatorialJ2000: {
|
|
88
|
+
rightAscensionDeg: number;
|
|
89
|
+
declinationDeg: number;
|
|
90
|
+
};
|
|
91
|
+
distanceAu: number;
|
|
92
|
+
distanceKm: number;
|
|
93
|
+
/** The apparent visual magnitude (Saturn's with its rings). */
|
|
94
|
+
magnitude: number;
|
|
95
|
+
angularDiameterArcsec: number;
|
|
96
|
+
/** The Sun-body-Earth angle in degrees (0 full, 180 new). */
|
|
97
|
+
phaseAngleDeg: number;
|
|
98
|
+
illuminatedFraction: number;
|
|
99
|
+
/** Degrees from the Sun, and which side: `east` is the evening side (the body follows the Sun): its right ascension is ahead of the Sun's by less than half a turn. Left out for the Sun. */
|
|
100
|
+
elongationDeg?: number;
|
|
101
|
+
east?: boolean;
|
|
102
|
+
/** The Moon only: the phase (0 new to 1, one cycle), waxing, and the bright limb's position angle in degrees eastward from north. */
|
|
103
|
+
moon?: {
|
|
104
|
+
phase: number;
|
|
105
|
+
waxing: boolean;
|
|
106
|
+
brightLimbAngleDeg: number;
|
|
107
|
+
};
|
|
108
|
+
/** With an observer: where the body is in that place's sky. */
|
|
109
|
+
horizontal?: SkyHorizontal;
|
|
110
|
+
/** With an observer: the body's middle is above the horizon (the apparent altitude, with refraction, is above 0). */
|
|
111
|
+
aboveHorizon?: boolean;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* One body of the sky list at a moment, for a place when one is given. See {@link skyBodies}.
|
|
115
|
+
*
|
|
116
|
+
* @param id - The body: `sun`, `moon`, `mercury` to `neptune`, or `pluto`.
|
|
117
|
+
* @param when - The moment: a `Date` or milliseconds since 1970 (UTC).
|
|
118
|
+
* @param observer - The place, if any.
|
|
119
|
+
* @returns The body.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* import { skyBody } from "@johnmorrisdotca/wakusei-planets/sky-bodies";
|
|
124
|
+
*
|
|
125
|
+
* const mars = skyBody("mars", Date.UTC(2026, 5, 21, 12), { latitude: 35.69, longitude: 139.69 });
|
|
126
|
+
* console.log(mars.name.en, mars.aboveHorizon);
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare function skyBody(id: SkyBodyId, when: Date | number, observer?: Observer): SkyBody;
|
|
130
|
+
/**
|
|
131
|
+
* Where the Sun, the Moon and the planets (and Pluto) are in the sky at a moment: right ascension and declination of date and of J2000, distance, apparent magnitude, angular diameter, phase and elongation from the Sun,
|
|
132
|
+
* and, when a place is given, azimuth and altitude (the Moon's parallax in). Pure: the moment is passed in, nothing reads a clock. The list is plain data in the order `SKY_BODY_IDS`: a star chart takes it as data the page
|
|
133
|
+
* passes in, it does not import this package. Rise, set and transit are in `/suncalc`.
|
|
134
|
+
*
|
|
135
|
+
* Every body has `accurate`: true where the figures hold to the accuracy below; Pluto outside the years its table is fitted for (1800 to 2199) is returned with `accurate: false`, because its place there is from an approximate orbit that can be wrong by degrees.
|
|
136
|
+
*
|
|
137
|
+
* Accuracy, as the tests prove it, CHECKED against JPL Horizons on three dates, 2024-03-20, 2026-06-21 and 2030-12-01 (2024 to 2030 only), and two places; the series are held to it for the years 1750 to 2250 by the package's own checks, and a moment outside those years throws a `RangeError` ({@link SKY_RANGE}). Within them: the Sun, the planets and Pluto are within 0.1 arcminute in right ascension and declination, of date and of J2000;
|
|
138
|
+
* the Moon within 0.02 arcminute of date and 0.015 of J2000; the distance-derived diameters within 0.1 per cent; the illuminated fraction within 0.02 per cent points and the elongation within 0.02 degrees; azimuth and altitude within
|
|
139
|
+
* 0.1 arcminute, the Moon's parallax in. Magnitudes: within 0.02 for the Sun, Mercury, Venus, Jupiter and Saturn, 0.03 for Uranus and Neptune, 0.06 for the Moon, 0.1 for Mars (its surface markings are not modelled) and 0.5 for Pluto
|
|
140
|
+
* (a fixed absolute magnitude, no more). Angles are degrees, distances astronomical units, sizes arcseconds.
|
|
141
|
+
*
|
|
142
|
+
* @param when - The moment: a `Date` or milliseconds since 1970 (UTC).
|
|
143
|
+
* @param observer - The place: `latitude` degrees north (from -90 to 90), `longitude` degrees east (any finite number), `heightM` metres (optional, finite); anything else throws a `RangeError`.
|
|
144
|
+
* @returns The ten bodies, the Sun first.
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* import { skyBodies } from "@johnmorrisdotca/wakusei-planets/sky-bodies";
|
|
149
|
+
*
|
|
150
|
+
* const tonight = skyBodies(Date.UTC(2026, 5, 21, 12), { latitude: 35.69, longitude: 139.69, heightM: 40 });
|
|
151
|
+
* console.log(tonight.filter((body) => body.aboveHorizon).map((body) => body.id));
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export declare function skyBodies(when: Date | number, observer?: Observer): SkyBody[];
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
// Where the Sun, the Moon and the planets are in the sky at a moment, for a star chart or a "tonight" page: right ascension and declination of date and of J2000, distance, apparent magnitude, size, phase, elongation from the Sun and,
|
|
2
|
+
// for a place, azimuth and altitude. Pure: no DOM, no clock read, no three.js; the moment is passed in. It is the package's own positions packaged: the Sun and the Moon from the sky engine (`/suncalc`'s), the planets from VSOP87B
|
|
3
|
+
// (Pluto from its table) with light time and the annual aberration, the same turn from the ecliptic of J2000 to the true equator of date, and the observer's parallax and sidereal time of the engine.
|
|
4
|
+
import { julianCenturies } from "./clock.js";
|
|
5
|
+
import { heliocentric, heliocentricModel, moonGeocentric, poleOf } from "./ephemeris.js";
|
|
6
|
+
import { BODIES } from "./facts.js";
|
|
7
|
+
import { horizontalOf, moonEquatorial, moonPhase, refraction, sunEquatorial } from "./sky/engine.js";
|
|
8
|
+
import { eclipticJ2000ToTrueEquatorialOfDate } from "./sky/frames.js";
|
|
9
|
+
import { moment } from "./sky/events.js";
|
|
10
|
+
import { meanObliquityArcseconds } from "./sidereal.js";
|
|
11
|
+
import { earthPosition } from "./theory.js";
|
|
12
|
+
const RAD = Math.PI / 180;
|
|
13
|
+
const DEG = 180 / Math.PI;
|
|
14
|
+
const AU_KM = 149597870.7;
|
|
15
|
+
const LIGHT_KM_S = 299792.458;
|
|
16
|
+
/** The days light takes to cross an astronomical unit. */
|
|
17
|
+
const LIGHT_DAYS_PER_AU = AU_KM / LIGHT_KM_S / 86400;
|
|
18
|
+
const OBLIQUITY_J2000 = (meanObliquityArcseconds(0) * Math.PI) / 648000;
|
|
19
|
+
const SUN_RADIUS_KM = 695700;
|
|
20
|
+
/** Within this many degrees of the zenith (0.36 arcseconds), and of a pole, the azimuth and the parallactic angle are 0: they are not defined there. */
|
|
21
|
+
const ZENITH_EPSILON_DEG = 1e-4;
|
|
22
|
+
const POLE_EPSILON_DEG = 1e-9;
|
|
23
|
+
const length = (v) => Math.hypot(v[0], v[1], v[2]);
|
|
24
|
+
const sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
25
|
+
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
26
|
+
const unit = (v) => {
|
|
27
|
+
const l = length(v);
|
|
28
|
+
return l === 0 ? [0, 0, 0] : [v[0] / l, v[1] / l, v[2] / l];
|
|
29
|
+
};
|
|
30
|
+
const wrap360 = (a) => ((a % 360) + 360) % 360;
|
|
31
|
+
/**
|
|
32
|
+
* The moments the calls accept, in milliseconds since 1970: from 1750-01-01 to 2250-01-01 UTC, the years the package's own checks hold the planet series (VSOP87B) and the rest to (the accuracy guide: the series
|
|
33
|
+
* "is good for the years 1750 to 2250 and slowly gets worse beyond"). A moment outside them throws a `RangeError` naming the range, so a number out of range is never returned as if it were good.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { SKY_RANGE } from "@johnmorrisdotca/wakusei-planets/sky-bodies";
|
|
38
|
+
*
|
|
39
|
+
* console.log(new Date(SKY_RANGE.from).getUTCFullYear(), new Date(SKY_RANGE.to).getUTCFullYear());
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export const SKY_RANGE = { from: Date.UTC(1750, 0, 1), to: Date.UTC(2250, 0, 1) };
|
|
43
|
+
/** The moment in milliseconds, held to {@link SKY_RANGE}. */
|
|
44
|
+
function inRange(when) {
|
|
45
|
+
const ms = moment(when);
|
|
46
|
+
if (ms < SKY_RANGE.from || ms >= SKY_RANGE.to)
|
|
47
|
+
throw new RangeError("the sky is worked out for the years 1750 to 2250 only (from 1750-01-01 to 2250-01-01 UTC), the years the planet series is held to");
|
|
48
|
+
return ms;
|
|
49
|
+
}
|
|
50
|
+
/** The place held to what it means: a latitude from -90 to 90 and a longitude and a height that are numbers, else a `RangeError` (a bad place never comes back as NaN fields). */
|
|
51
|
+
function checkObserver(observer) {
|
|
52
|
+
if (observer === undefined)
|
|
53
|
+
return;
|
|
54
|
+
if (observer === null || typeof observer !== "object")
|
|
55
|
+
throw new RangeError("the observer must be { latitude, longitude, heightM? }");
|
|
56
|
+
if (!Number.isFinite(observer.latitude) || observer.latitude < -90 || observer.latitude > 90)
|
|
57
|
+
throw new RangeError(`the latitude must be a number from -90 to 90 degrees, got ${String(observer.latitude)}`);
|
|
58
|
+
if (!Number.isFinite(observer.longitude))
|
|
59
|
+
throw new RangeError(`the longitude must be a finite number of degrees, got ${String(observer.longitude)}`);
|
|
60
|
+
if (observer.heightM !== undefined && !Number.isFinite(observer.heightM))
|
|
61
|
+
throw new RangeError(`the height must be a finite number of metres, got ${String(observer.heightM)}`);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The names of the bodies `skyBodies` gives, in its order.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { SKY_BODY_IDS } from "@johnmorrisdotca/wakusei-planets/sky-bodies";
|
|
69
|
+
*
|
|
70
|
+
* console.log(SKY_BODY_IDS.length, SKY_BODY_IDS[1]);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export const SKY_BODY_IDS = ["sun", "moon", "mercury", "venus", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto"];
|
|
74
|
+
const equatorialOf = (v) => ({ rightAscensionDeg: wrap360(Math.atan2(v[1], v[0]) * DEG), declinationDeg: Math.asin(Math.max(-1, Math.min(1, v[2] / length(v)))) * DEG });
|
|
75
|
+
/** A J2000 ecliptic vector in the J2000 equatorial frame. */
|
|
76
|
+
const j2000Equatorial = (v) => [v[0], v[1] * Math.cos(OBLIQUITY_J2000) - v[2] * Math.sin(OBLIQUITY_J2000), v[1] * Math.sin(OBLIQUITY_J2000) + v[2] * Math.cos(OBLIQUITY_J2000)];
|
|
77
|
+
/** The annual aberration: the Earth's speed over the speed of light, a vector in the J2000 ecliptic that moves the apparent direction toward where the Earth is heading. */
|
|
78
|
+
function earthBeta(ms) {
|
|
79
|
+
const earth = earthPosition(ms);
|
|
80
|
+
const later = earthPosition(ms + 60_000);
|
|
81
|
+
return [(later[0] - earth[0]) / 60 / (LIGHT_KM_S / AU_KM), (later[1] - earth[1]) / 60 / (LIGHT_KM_S / AU_KM), (later[2] - earth[2]) / 60 / (LIGHT_KM_S / AU_KM)];
|
|
82
|
+
}
|
|
83
|
+
/** A planet as the Earth's centre sees it at `ms`: its direction in the J2000 ecliptic with light time, the same with the Earth's aberration, its distance and its distance from the Sun at the moment the light left it. */
|
|
84
|
+
function planetGeometry(id, ms) {
|
|
85
|
+
const earth = earthPosition(ms);
|
|
86
|
+
let tau = 0;
|
|
87
|
+
let helio = heliocentric(id, ms);
|
|
88
|
+
for (let k = 0; k < 4; k += 1) {
|
|
89
|
+
helio = heliocentric(id, ms - tau * 86_400_000);
|
|
90
|
+
tau = length(sub(helio, earth)) * LIGHT_DAYS_PER_AU;
|
|
91
|
+
}
|
|
92
|
+
const geo = sub(helio, earth);
|
|
93
|
+
const distanceAu = length(geo);
|
|
94
|
+
const beta = earthBeta(ms);
|
|
95
|
+
const direction = unit(geo);
|
|
96
|
+
return { geo, aberrated: [direction[0] + beta[0], direction[1] + beta[1], direction[2] + beta[2]], distanceAu, sunAu: length(helio), helio };
|
|
97
|
+
}
|
|
98
|
+
/** The planetocentric latitude, degrees, of the direction from a planet to a point (the Earth or the Sun), north positive: how open its equator, or its rings, are to that point. */
|
|
99
|
+
const latitudeToward = (id, helio, point) => Math.asin(Math.max(-1, Math.min(1, dot(poleOf(id), unit(sub(point, helio)))))) * DEG;
|
|
100
|
+
/** The apparent visual magnitude of a planet from the Astronomical Almanac's formulas, as Mallama and Hilton (2018) give them, for the phase angle `i` in degrees; `r` and `delta` in au. */
|
|
101
|
+
function planetMagnitude(id, i, r, delta, helio, earth) {
|
|
102
|
+
const distance = 5 * Math.log10(r * delta);
|
|
103
|
+
switch (id) {
|
|
104
|
+
case "mercury":
|
|
105
|
+
return distance - 0.613 + 6.328e-2 * i - 1.6336e-3 * i ** 2 + 3.3644e-5 * i ** 3 - 3.4265e-7 * i ** 4 + 1.6893e-9 * i ** 5 - 3.0334e-12 * i ** 6;
|
|
106
|
+
case "venus":
|
|
107
|
+
return i <= 163.7 ? distance - 4.384 - 1.044e-3 * i + 3.687e-4 * i ** 2 - 2.814e-6 * i ** 3 + 8.938e-9 * i ** 4 : distance + 236.05828 - 2.81914 * i + 8.39034e-3 * i ** 2;
|
|
108
|
+
case "mars":
|
|
109
|
+
// the paper's second formula (beyond 50 degrees) is not here: the Earth never sees Mars more than about 47 degrees from full
|
|
110
|
+
return distance - 1.601 + 0.02267 * i - 0.0001302 * i ** 2;
|
|
111
|
+
case "jupiter":
|
|
112
|
+
// the paper's formula for the first 12 degrees; the Earth never sees Jupiter past 12 degrees of phase, so the formula for beyond is not here
|
|
113
|
+
return distance - 9.395 - 3.7e-4 * i + 6.16e-4 * i ** 2;
|
|
114
|
+
case "saturn": {
|
|
115
|
+
// the globe and its rings, as the Almanac gives it (Mallama 2012, the paper's Eq. 10): the rings brighten it with how open they are to the Earth and to the Sun; the angle never passes 6.5 degrees from the Earth
|
|
116
|
+
const earthLatitude = latitudeToward("saturn", helio, earth);
|
|
117
|
+
const sunLatitude = latitudeToward("saturn", helio, [0, 0, 0]);
|
|
118
|
+
const tilt = earthLatitude * sunLatitude > 0 ? Math.sqrt(earthLatitude * sunLatitude) * RAD : 0;
|
|
119
|
+
return distance - 8.914 - 1.825 * Math.sin(tilt) + 0.026 * i - 0.378 * Math.sin(tilt) * Math.exp(-2.25 * i);
|
|
120
|
+
}
|
|
121
|
+
case "uranus": {
|
|
122
|
+
// the planetographic latitudes of the Earth and of the Sun: the poles are brighter (flattening 0.0022927)
|
|
123
|
+
const graphic = (centric) => Math.atan(Math.tan(centric * RAD) / (1 - 0.0022927) ** 2) * DEG;
|
|
124
|
+
const mean = (Math.abs(graphic(latitudeToward("uranus", helio, earth))) + Math.abs(graphic(latitudeToward("uranus", helio, [0, 0, 0])))) / 2;
|
|
125
|
+
return distance - 7.11 - 8.4e-4 * mean + 6.587e-3 * i + 1.045e-4 * i ** 2;
|
|
126
|
+
}
|
|
127
|
+
case "neptune":
|
|
128
|
+
// the brightness after 2000 (the paper's Eq. 16 gives the constant for the years before as well)
|
|
129
|
+
return distance - 7.0 + 7.944e-3 * i + 9.617e-5 * i ** 2;
|
|
130
|
+
case "pluto":
|
|
131
|
+
// JPL's absolute magnitude for Pluto (H = -0.55): no phase term, the angle never passes 2 degrees
|
|
132
|
+
return distance - 0.55;
|
|
133
|
+
default:
|
|
134
|
+
return distance;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function bodyAt(id, ms, observer) {
|
|
138
|
+
const facts = BODIES[id];
|
|
139
|
+
const base = { id, name: { en: facts.name.en, ja: facts.name.ja } };
|
|
140
|
+
let equatorial;
|
|
141
|
+
let j2000;
|
|
142
|
+
let body;
|
|
143
|
+
const earth = earthPosition(ms);
|
|
144
|
+
const sunGeo = unit([-earth[0], -earth[1], -earth[2]]);
|
|
145
|
+
const T = julianCenturies(ms);
|
|
146
|
+
let geoDirection;
|
|
147
|
+
if (id === "sun") {
|
|
148
|
+
equatorial = sunEquatorial(ms);
|
|
149
|
+
geoDirection = sunGeo;
|
|
150
|
+
j2000 = j2000Equatorial(sunGeo);
|
|
151
|
+
const distanceKm = equatorial.distanceKm;
|
|
152
|
+
body = {
|
|
153
|
+
kind: "star",
|
|
154
|
+
equatorialDate: { rightAscensionDeg: equatorial.rightAscension, declinationDeg: equatorial.declination },
|
|
155
|
+
equatorialJ2000: equatorialOf(j2000),
|
|
156
|
+
distanceAu: distanceKm / AU_KM,
|
|
157
|
+
distanceKm,
|
|
158
|
+
magnitude: -26.74 + 5 * Math.log10(distanceKm / AU_KM),
|
|
159
|
+
angularDiameterArcsec: 2 * Math.asin(SUN_RADIUS_KM / distanceKm) * DEG * 3600,
|
|
160
|
+
phaseAngleDeg: 0,
|
|
161
|
+
illuminatedFraction: 1,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
else if (id === "moon") {
|
|
165
|
+
equatorial = moonEquatorial(ms);
|
|
166
|
+
const first = moonGeocentric(ms);
|
|
167
|
+
const retarded = moonGeocentric(ms - (length(first) / LIGHT_KM_S) * 1000);
|
|
168
|
+
geoDirection = unit(retarded);
|
|
169
|
+
// The Moon's series of this package gives the direction with the Earth's aberration already in it (its place of date agrees with JPL Horizons' apparent place to under an arcsecond, and with the aberration
|
|
170
|
+
// taken out its J2000 place agrees with Horizons' astrometric (ICRF) place to 0.7 arcsecond; left in, it is 1 to 13 arcseconds off, the size and the pattern of the annual aberration). So the J2000 direction,
|
|
171
|
+
// which has none, is the retarded one with the aberration taken out.
|
|
172
|
+
const beta = earthBeta(ms);
|
|
173
|
+
const direction = unit(retarded);
|
|
174
|
+
j2000 = j2000Equatorial(unit([direction[0] - beta[0], direction[1] - beta[1], direction[2] - beta[2]]));
|
|
175
|
+
const phase = moonPhase(ms);
|
|
176
|
+
const phaseAngle = Math.acos(Math.max(-1, Math.min(1, 2 * phase.fraction - 1))) * DEG;
|
|
177
|
+
const distanceKm = equatorial.distanceKm;
|
|
178
|
+
body = {
|
|
179
|
+
kind: "moon",
|
|
180
|
+
equatorialDate: { rightAscensionDeg: equatorial.rightAscension, declinationDeg: equatorial.declination },
|
|
181
|
+
equatorialJ2000: equatorialOf(j2000),
|
|
182
|
+
distanceAu: distanceKm / AU_KM,
|
|
183
|
+
distanceKm,
|
|
184
|
+
// the usual phase law of the Moon's V magnitude, at its mean distance of 384,400 km
|
|
185
|
+
magnitude: -12.73 + 0.026 * phaseAngle + 4e-9 * phaseAngle ** 4 + 5 * Math.log10(distanceKm / 384_400),
|
|
186
|
+
angularDiameterArcsec: 2 * Math.asin(facts.radiusKm / distanceKm) * DEG * 3600,
|
|
187
|
+
phaseAngleDeg: phaseAngle,
|
|
188
|
+
illuminatedFraction: phase.fraction,
|
|
189
|
+
moon: { phase: phase.phase, waxing: phase.waxing, brightLimbAngleDeg: phase.angle },
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
const g = planetGeometry(id, ms);
|
|
194
|
+
geoDirection = unit(g.geo);
|
|
195
|
+
j2000 = j2000Equatorial(g.geo);
|
|
196
|
+
const dateVector = eclipticJ2000ToTrueEquatorialOfDate(g.aberrated, T);
|
|
197
|
+
equatorial = { rightAscension: wrap360(Math.atan2(dateVector[1], dateVector[0]) * DEG), declination: Math.asin(dateVector[2] / length(dateVector)) * DEG, distanceKm: g.distanceAu * AU_KM };
|
|
198
|
+
const earthSun = length(earth);
|
|
199
|
+
const cosPhase = (g.sunAu ** 2 + g.distanceAu ** 2 - earthSun ** 2) / (2 * g.sunAu * g.distanceAu);
|
|
200
|
+
const phaseAngle = Math.acos(Math.max(-1, Math.min(1, cosPhase))) * DEG;
|
|
201
|
+
body = {
|
|
202
|
+
kind: id === "pluto" ? "dwarf" : "planet",
|
|
203
|
+
equatorialDate: { rightAscensionDeg: equatorial.rightAscension, declinationDeg: equatorial.declination },
|
|
204
|
+
equatorialJ2000: equatorialOf(j2000),
|
|
205
|
+
distanceAu: g.distanceAu,
|
|
206
|
+
distanceKm: g.distanceAu * AU_KM,
|
|
207
|
+
magnitude: planetMagnitude(id, phaseAngle, g.sunAu, g.distanceAu, g.helio, earth),
|
|
208
|
+
angularDiameterArcsec: 2 * Math.asin(facts.radiusKm / (g.distanceAu * AU_KM)) * DEG * 3600,
|
|
209
|
+
phaseAngleDeg: phaseAngle,
|
|
210
|
+
illuminatedFraction: (1 + cosPhase) / 2,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
// Pluto is from a table fitted for 1800 to 2199; outside it the package falls back on an approximate orbit that is off by degrees
|
|
214
|
+
const accurate = id !== "pluto" || heliocentricModel("pluto", ms).theory === "chebyshev";
|
|
215
|
+
const out = { ...base, ...body, accurate };
|
|
216
|
+
if (id !== "sun") {
|
|
217
|
+
out.elongationDeg = Math.acos(Math.max(-1, Math.min(1, dot(geoDirection, sunGeo)))) * DEG;
|
|
218
|
+
// the evening side: its right ascension is ahead of the Sun's by less than half a turn, so it crosses the meridian and sets after the Sun (JPL Horizons' "trailing", /T). Close to the Sun, where a planet
|
|
219
|
+
// has a large ecliptic latitude (Venus near its inferior conjunction), this is the side in the sky and not the side in ecliptic longitude.
|
|
220
|
+
out.east = wrap360(equatorial.rightAscension - sunEquatorial(ms).rightAscension) < 180;
|
|
221
|
+
}
|
|
222
|
+
if (observer !== undefined) {
|
|
223
|
+
const h = horizontalOf(equatorial, ms, observer);
|
|
224
|
+
const apparent = h.altitude + refraction(h.altitude);
|
|
225
|
+
// At the zenith (or the nadir) every direction is the same, and at a pole every direction is south (or north): the azimuth and the parallactic angle are not defined there, and the arithmetic gives
|
|
226
|
+
// 0 or 180 by rounding noise, and an azimuth that depends on the longitude at a pole. They are 0 there, always.
|
|
227
|
+
const atZenith = Math.abs(h.altitude) >= 90 - ZENITH_EPSILON_DEG;
|
|
228
|
+
const atPole = Math.abs(observer.latitude) >= 90 - POLE_EPSILON_DEG;
|
|
229
|
+
out.horizontal = { azimuthDeg: atZenith || atPole ? 0 : h.azimuth, altitudeDeg: h.altitude, apparentAltitudeDeg: apparent, hourAngleDeg: h.hourAngle, parallacticAngleDeg: atZenith || atPole ? 0 : h.parallacticAngle };
|
|
230
|
+
out.aboveHorizon = apparent > 0;
|
|
231
|
+
}
|
|
232
|
+
return out;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* One body of the sky list at a moment, for a place when one is given. See {@link skyBodies}.
|
|
236
|
+
*
|
|
237
|
+
* @param id - The body: `sun`, `moon`, `mercury` to `neptune`, or `pluto`.
|
|
238
|
+
* @param when - The moment: a `Date` or milliseconds since 1970 (UTC).
|
|
239
|
+
* @param observer - The place, if any.
|
|
240
|
+
* @returns The body.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* import { skyBody } from "@johnmorrisdotca/wakusei-planets/sky-bodies";
|
|
245
|
+
*
|
|
246
|
+
* const mars = skyBody("mars", Date.UTC(2026, 5, 21, 12), { latitude: 35.69, longitude: 139.69 });
|
|
247
|
+
* console.log(mars.name.en, mars.aboveHorizon);
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
export function skyBody(id, when, observer) {
|
|
251
|
+
if (!SKY_BODY_IDS.includes(id))
|
|
252
|
+
throw new RangeError(`unknown body: ${String(id)}`);
|
|
253
|
+
checkObserver(observer);
|
|
254
|
+
return bodyAt(id, inRange(when), observer);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Where the Sun, the Moon and the planets (and Pluto) are in the sky at a moment: right ascension and declination of date and of J2000, distance, apparent magnitude, angular diameter, phase and elongation from the Sun,
|
|
258
|
+
* and, when a place is given, azimuth and altitude (the Moon's parallax in). Pure: the moment is passed in, nothing reads a clock. The list is plain data in the order `SKY_BODY_IDS`: a star chart takes it as data the page
|
|
259
|
+
* passes in, it does not import this package. Rise, set and transit are in `/suncalc`.
|
|
260
|
+
*
|
|
261
|
+
* Every body has `accurate`: true where the figures hold to the accuracy below; Pluto outside the years its table is fitted for (1800 to 2199) is returned with `accurate: false`, because its place there is from an approximate orbit that can be wrong by degrees.
|
|
262
|
+
*
|
|
263
|
+
* Accuracy, as the tests prove it, CHECKED against JPL Horizons on three dates, 2024-03-20, 2026-06-21 and 2030-12-01 (2024 to 2030 only), and two places; the series are held to it for the years 1750 to 2250 by the package's own checks, and a moment outside those years throws a `RangeError` ({@link SKY_RANGE}). Within them: the Sun, the planets and Pluto are within 0.1 arcminute in right ascension and declination, of date and of J2000;
|
|
264
|
+
* the Moon within 0.02 arcminute of date and 0.015 of J2000; the distance-derived diameters within 0.1 per cent; the illuminated fraction within 0.02 per cent points and the elongation within 0.02 degrees; azimuth and altitude within
|
|
265
|
+
* 0.1 arcminute, the Moon's parallax in. Magnitudes: within 0.02 for the Sun, Mercury, Venus, Jupiter and Saturn, 0.03 for Uranus and Neptune, 0.06 for the Moon, 0.1 for Mars (its surface markings are not modelled) and 0.5 for Pluto
|
|
266
|
+
* (a fixed absolute magnitude, no more). Angles are degrees, distances astronomical units, sizes arcseconds.
|
|
267
|
+
*
|
|
268
|
+
* @param when - The moment: a `Date` or milliseconds since 1970 (UTC).
|
|
269
|
+
* @param observer - The place: `latitude` degrees north (from -90 to 90), `longitude` degrees east (any finite number), `heightM` metres (optional, finite); anything else throws a `RangeError`.
|
|
270
|
+
* @returns The ten bodies, the Sun first.
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* import { skyBodies } from "@johnmorrisdotca/wakusei-planets/sky-bodies";
|
|
275
|
+
*
|
|
276
|
+
* const tonight = skyBodies(Date.UTC(2026, 5, 21, 12), { latitude: 35.69, longitude: 139.69, heightM: 40 });
|
|
277
|
+
* console.log(tonight.filter((body) => body.aboveHorizon).map((body) => body.id));
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
export function skyBodies(when, observer) {
|
|
281
|
+
checkObserver(observer);
|
|
282
|
+
const ms = inRange(when);
|
|
283
|
+
return SKY_BODY_IDS.map((id) => bodyAt(id, ms, observer));
|
|
284
|
+
}
|
package/dist/space/element.d.ts
CHANGED
|
@@ -73,15 +73,21 @@ export interface BodyHover extends BodyInfo {
|
|
|
73
73
|
* ```ts no-run
|
|
74
74
|
* import type { BodySight } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
75
75
|
*
|
|
76
|
-
* const mars: BodySight = { id: "mars", kind: "planet", inView: false, behind: false, edge: "right", x: 640, y: 210, along: 210, angle: 84 };
|
|
76
|
+
* const mars: BodySight = { id: "mars", kind: "planet", inView: false, behind: false, edge: "right", x: 640, y: 210, along: 210, angle: 84, offAxis: 31, distance: 52_000, distanceKm: 3.3e8 };
|
|
77
77
|
* console.log(mars.inView ? "in view" : `beyond the ${mars.edge} edge`);
|
|
78
78
|
* ```
|
|
79
79
|
*/
|
|
80
80
|
export interface BodySight extends Sight {
|
|
81
|
-
/** A body's id,
|
|
81
|
+
/** A body's id, a craft's own id (`voyager1`, `roadster`) when `kind` is `spacecraft`, or an orbiter's id (`mro`, the one `orbiter` takes) when `kind` is `orbiter`. */
|
|
82
82
|
id: string;
|
|
83
|
-
kind: SpaceKind | "spacecraft";
|
|
83
|
+
kind: SpaceKind | "spacecraft" | "orbiter";
|
|
84
84
|
host?: BodyId;
|
|
85
|
+
/** Degrees between the camera's forward direction and the body, 0 (straight ahead) to 180 (straight behind). */
|
|
86
|
+
offAxis: number;
|
|
87
|
+
/** How far the body is from the camera, in the view's units: Earth radii. In the compressed scale these are the drawn distances, not the real ones. */
|
|
88
|
+
distance: number;
|
|
89
|
+
/** The distance in kilometres, in the true scale; `null` in the compressed one, where the drawn distances are not real. */
|
|
90
|
+
distanceKm: number | null;
|
|
85
91
|
}
|
|
86
92
|
/**
|
|
87
93
|
* What the space view is doing: `loading`, `live`, `unavailable` (no WebGL), `lost` (the GPU took the context; it comes back by itself).
|
|
@@ -496,6 +502,29 @@ export declare class WakuseiSpace extends HTMLElement {
|
|
|
496
502
|
transition?: TravelKind;
|
|
497
503
|
duration?: number;
|
|
498
504
|
}): boolean;
|
|
505
|
+
/**
|
|
506
|
+
* Turn the camera where it stands until a body is in the picture, by the least turn: no move of the camera's place, only the way it looks. A body is in the picture when its middle is inside the picture less `margin` of
|
|
507
|
+
* each side (the left and right margins are `margin` of the width, the top and bottom `margin` of the height; 0.15 by default, 0 to 0.45). One already so is left alone and the answer is `false`, as it is for an id the
|
|
508
|
+
* view does not know, the body already looked at, and a view that is riding. The body becomes the one looked at: the camera stays at its place and looks at it, from as far
|
|
509
|
+
* as it stands (the zoom is worked out from that distance, inside the controls' limits; a body so far that the zoom's limit would move the camera is not turned to). It glides the way a move does, or at once with
|
|
510
|
+
* `smooth: false` or for a reader who prefers reduced motion; nothing is drawn at rest and one draw more at most ends it.
|
|
511
|
+
*
|
|
512
|
+
* @param target - The body's id.
|
|
513
|
+
* @param options - `smooth` (true by default) and `margin`.
|
|
514
|
+
* @returns Whether the view turned.
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* ```ts no-run
|
|
518
|
+
* import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
519
|
+
*
|
|
520
|
+
* const space = document.querySelector<WakuseiSpace>("wakusei-space")!;
|
|
521
|
+
* console.log(space.turnTo("mars", { smooth: false }));
|
|
522
|
+
* ```
|
|
523
|
+
*/
|
|
524
|
+
turnTo(target: BodyId | string, options?: {
|
|
525
|
+
smooth?: boolean;
|
|
526
|
+
margin?: number;
|
|
527
|
+
}): boolean;
|
|
499
528
|
/** The next stage out from the Sun from where the view is (the first stage from a body), with the same move as `goTo`; null, and nothing done, when the view is already at the widest stage. */
|
|
500
529
|
stepOut(options?: {
|
|
501
530
|
smooth?: boolean;
|
package/dist/space/element.js
CHANGED
|
@@ -5,7 +5,7 @@ import { createGate, frameCap } from "../gate.js";
|
|
|
5
5
|
import { arrowCount } from "./arrows.js";
|
|
6
6
|
import { createGameClock } from "./clock.js";
|
|
7
7
|
import { bodyKindOf, findBody, hopFrom, hostOf, HOP_ORDER, systemOf } from "./bodies.js";
|
|
8
|
-
import { sightChanged, sightOf } from "./sight.js";
|
|
8
|
+
import { sightChanged, sightOf, withinMargin } from "./sight.js";
|
|
9
9
|
import { chooseLabels, nameSpot } from "./labels.js";
|
|
10
10
|
import { coverArrows } from "./covered.js";
|
|
11
11
|
import { createPainter, picturesPending } from "../scene/painter.js";
|
|
@@ -28,7 +28,7 @@ import { marksToShow, pointUnder, readPlaceLayers, readSurfaceNames, spotView }
|
|
|
28
28
|
import { createPlaceLayer, onPlacesLoader, placesLoader } from "../scene/place-layer.js";
|
|
29
29
|
import { createEarthPlaceLayer, EARTH_PLACE_MARKS, EARTH_PLACES_FROM_PX, earthPlacesLayout, onEarthPlacesLayout, readEarthPlaceLook } from "../scene/earth-places.js";
|
|
30
30
|
import { cross, dot, length, sub, unit } from "../vec.js";
|
|
31
|
-
import { createSpaceItem, FIT_DISTANCE, moonScaleFor, newSpaceModel, SPACE_BODIES } from "./scene.js";
|
|
31
|
+
import { createSpaceItem, FIT_DISTANCE, framedOf, moonScaleFor, newSpaceModel, SPACE_BODIES } from "./scene.js";
|
|
32
32
|
import { paintLengthOf, paintSwathOf } from "../paint/trail.js";
|
|
33
33
|
export { setPlacesLoader } from "../scene/place-layer.js";
|
|
34
34
|
export { EARTH_PLACE_LOOKS, EARTH_PLACE_MARKS } from "../scene/earth-places.js";
|
|
@@ -1346,6 +1346,78 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
1346
1346
|
this.#announceHop(zoom, side ?? undefined);
|
|
1347
1347
|
return true;
|
|
1348
1348
|
}
|
|
1349
|
+
/**
|
|
1350
|
+
* Turn the camera where it stands until a body is in the picture, by the least turn: no move of the camera's place, only the way it looks. A body is in the picture when its middle is inside the picture less `margin` of
|
|
1351
|
+
* each side (the left and right margins are `margin` of the width, the top and bottom `margin` of the height; 0.15 by default, 0 to 0.45). One already so is left alone and the answer is `false`, as it is for an id the
|
|
1352
|
+
* view does not know, the body already looked at, and a view that is riding. The body becomes the one looked at: the camera stays at its place and looks at it, from as far
|
|
1353
|
+
* as it stands (the zoom is worked out from that distance, inside the controls' limits; a body so far that the zoom's limit would move the camera is not turned to). It glides the way a move does, or at once with
|
|
1354
|
+
* `smooth: false` or for a reader who prefers reduced motion; nothing is drawn at rest and one draw more at most ends it.
|
|
1355
|
+
*
|
|
1356
|
+
* @param target - The body's id.
|
|
1357
|
+
* @param options - `smooth` (true by default) and `margin`.
|
|
1358
|
+
* @returns Whether the view turned.
|
|
1359
|
+
*
|
|
1360
|
+
* @example
|
|
1361
|
+
* ```ts no-run
|
|
1362
|
+
* import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
|
|
1363
|
+
*
|
|
1364
|
+
* const space = document.querySelector<WakuseiSpace>("wakusei-space")!;
|
|
1365
|
+
* console.log(space.turnTo("mars", { smooth: false }));
|
|
1366
|
+
* ```
|
|
1367
|
+
*/
|
|
1368
|
+
turnTo(target, options = {}) {
|
|
1369
|
+
const id = readBody(target);
|
|
1370
|
+
const model = this.#model;
|
|
1371
|
+
if (!id || model.ride !== null || !model.pose.valid || id === model.focus)
|
|
1372
|
+
return false;
|
|
1373
|
+
const margin = Number.isFinite(options.margin) ? Math.min(0.45, Math.max(0, options.margin)) : 0.15;
|
|
1374
|
+
const site = this.#site(id);
|
|
1375
|
+
const p = model.pose.p;
|
|
1376
|
+
const [qx, qy, qz, qw] = model.pose.q;
|
|
1377
|
+
// the body in the camera's axes (it looks down -z): rotate by the inverse of the camera's turn
|
|
1378
|
+
const v = [site.at[0] - p[0], site.at[1] - p[1], site.at[2] - p[2]];
|
|
1379
|
+
// v' = v + w t + q x t, with t = 2 (-q x v): the vector turned by the conjugate
|
|
1380
|
+
const tx = 2 * (-(qy * v[2] - qz * v[1])), ty = 2 * (-(qz * v[0] - qx * v[2])), tz = 2 * (-(qx * v[1] - qy * v[0]));
|
|
1381
|
+
const c = [v[0] + qw * tx + (-qy * tz - -qz * ty), v[1] + qw * ty + (-qz * tx - -qx * tz), v[2] + qw * tz + (-qx * ty - -qy * tx)];
|
|
1382
|
+
const tall = Math.tan((model.pose.fov * Math.PI) / 360);
|
|
1383
|
+
const aspect = this.clientWidth > 0 && this.clientHeight > 0 ? this.clientWidth / this.clientHeight : 1;
|
|
1384
|
+
if (c[2] < 0) {
|
|
1385
|
+
const nx = c[0] / (-c[2] * tall * aspect), ny = c[1] / (-c[2] * tall);
|
|
1386
|
+
if (withinMargin(nx, ny, margin))
|
|
1387
|
+
return false;
|
|
1388
|
+
}
|
|
1389
|
+
// the camera's place as seen from the body: the controls' yaw and tilt and the zoom that put the camera there, looking at it
|
|
1390
|
+
const away = Math.hypot(v[0], v[1], v[2]);
|
|
1391
|
+
if (away === 0)
|
|
1392
|
+
return false;
|
|
1393
|
+
const aim = [-v[0] / away, -v[1] / away, -v[2] / away];
|
|
1394
|
+
const across = site.radius * framedOf(id) * Math.max(1, (this.clientHeight || 1) / Math.max(1, this.clientWidth || 1));
|
|
1395
|
+
const zoom = (FIT_DISTANCE * across) / away;
|
|
1396
|
+
if (!(zoom >= CARRIED_LIMITS.zoomMin && zoom <= CARRIED_LIMITS.zoomMax) || away < 1.05 * site.radius)
|
|
1397
|
+
return false;
|
|
1398
|
+
model.anchor ??= model.time;
|
|
1399
|
+
const earth = orientation("earth", model.anchor);
|
|
1400
|
+
const lat = Math.asin(Math.max(-1, Math.min(1, dot(aim, earth.pole)))) / RAD;
|
|
1401
|
+
const lon = Math.atan2(dot(aim, cross(earth.pole, earth.meridian)), dot(aim, earth.meridian)) / RAD;
|
|
1402
|
+
const from = { ...model.view };
|
|
1403
|
+
const yaw = from.yaw + ((((model.centre.lon - lon - from.yaw + 180) % 360) + 360) % 360) - 180;
|
|
1404
|
+
const tilt = model.centre.lat - lat;
|
|
1405
|
+
const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
1406
|
+
const leaving = this.#leaving();
|
|
1407
|
+
this.#arrivedFrom = leaving;
|
|
1408
|
+
model.transition = options.smooth === false || reduced ? null : this.#startMove("direct", leaving, id);
|
|
1409
|
+
model.region = null;
|
|
1410
|
+
this.#showRegion();
|
|
1411
|
+
this.#selected = id;
|
|
1412
|
+
model.focus = id;
|
|
1413
|
+
if (this.#hands !== undefined && !this.hasAttribute("data-kazoku-bar"))
|
|
1414
|
+
this.#hands.controller.set({ yaw, tilt, zoom }, true, "jump");
|
|
1415
|
+
else
|
|
1416
|
+
this.setView({ yaw, tilt, zoom, roll: from.roll, panX: from.panX, panY: from.panY }, true);
|
|
1417
|
+
this.#schedule();
|
|
1418
|
+
this.#gate?.request();
|
|
1419
|
+
return true;
|
|
1420
|
+
}
|
|
1349
1421
|
/** The body the camera is at now: the target of the ride, or the body looked at. */
|
|
1350
1422
|
#leaving() {
|
|
1351
1423
|
const ride = this.#model.ride;
|
|
@@ -2138,8 +2210,9 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
2138
2210
|
const now = {};
|
|
2139
2211
|
for (const [id, input] of Object.entries(bodies)) {
|
|
2140
2212
|
const body = id;
|
|
2141
|
-
const
|
|
2142
|
-
const
|
|
2213
|
+
const orbiter = this.#model.orbiterSet !== null && this.#model.orbiterSet.ids.includes(id);
|
|
2214
|
+
const craft = orbiter || this.#model.craftIds.includes(id) || id === "roadster";
|
|
2215
|
+
const one = { id, kind: orbiter ? "orbiter" : craft ? "spacecraft" : bodyKindOf(body), ...sightOf(input, frame.width, frame.height, frame.axis), offAxis: input.offAxis ?? 0, distance: input.distance ?? 0, distanceKm: input.distanceKm ?? null };
|
|
2143
2216
|
const host = craft ? undefined : hostOf(body);
|
|
2144
2217
|
if (host !== undefined)
|
|
2145
2218
|
one.host = host;
|
|
@@ -2334,6 +2407,9 @@ export class WakuseiSpace extends HTMLElement {
|
|
|
2334
2407
|
// the Roadster and the orbiters are no bodies of the package: a press on such a name says so and goes nowhere
|
|
2335
2408
|
if (id === "roadster" || this.#model.craftIds.includes(id) || (this.#model.orbiterSet !== null && this.#model.orbiterSet.ids.includes(id))) {
|
|
2336
2409
|
this.dispatchEvent(new CustomEvent("wakusei-body-click", { detail: { id, name: this.#nameOf(id), kind: "spacecraft" }, bubbles: true, composed: true }));
|
|
2410
|
+
// an orbiter is told in an event of its own as well (`{ id, name }`, the id `orbiter` takes), the one above unchanged
|
|
2411
|
+
if (this.#model.orbiterSet !== null && this.#model.orbiterSet.ids.includes(id))
|
|
2412
|
+
this.dispatchEvent(new CustomEvent("wakusei-orbiter-click", { detail: { id, name: this.#nameOf(id) }, bubbles: true, composed: true }));
|
|
2337
2413
|
return;
|
|
2338
2414
|
}
|
|
2339
2415
|
this.dispatchEvent(new CustomEvent("wakusei-body-click", { detail: this.bodyInfo(id), bubbles: true, composed: true }));
|
package/dist/space/index.d.ts
CHANGED
|
@@ -10,5 +10,5 @@ export { spinAxis, type SpinAxis } from "./spin.ts";
|
|
|
10
10
|
export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy, type CoverArrow, type CoverEntry } from "./covered.ts";
|
|
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
|
-
export { SIGHT_STEP_PX, sightChanged, sightOf, type Sight, type SightEdge, type SightInput } from "./sight.ts";
|
|
13
|
+
export { SIGHT_STEP_PX, sightChanged, sightOf, withinMargin, type Sight, type SightEdge, type SightInput } from "./sight.ts";
|
|
14
14
|
export { besideFace, facingPoint, faceView, subCameraPoint, surfaceDirection, type Face, type FaceView } from "./face.ts";
|
package/dist/space/index.js
CHANGED
|
@@ -11,5 +11,5 @@ export { spinAxis } from "./spin.js";
|
|
|
11
11
|
export { COVER_ARROW_GAP, COVER_MIN_PX, coverArrows, coveredBy } from "./covered.js";
|
|
12
12
|
export { TRAVEL_CLEARANCE, arrivalSide, travelArrival, travelPlan, travelPose } from "./travel.js";
|
|
13
13
|
export { regionOrbits, regionView, SUN_REGIONS } from "./regions.js";
|
|
14
|
-
export { SIGHT_STEP_PX, sightChanged, sightOf } from "./sight.js";
|
|
14
|
+
export { SIGHT_STEP_PX, sightChanged, sightOf, withinMargin } from "./sight.js";
|
|
15
15
|
export { besideFace, facingPoint, faceView, subCameraPoint, surfaceDirection } from "./face.js";
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -20,6 +20,8 @@ import { type TravelInput, type TravelKind, type TravelPlan } from "./travel.ts"
|
|
|
20
20
|
export type SpaceThree = ThreeParts & Pick<typeof THREE, "PerspectiveCamera">;
|
|
21
21
|
/** The camera's distance, in radii of the body it looks at, at which that body fills the view at zoom 1. */
|
|
22
22
|
export declare const FIT_DISTANCE = 4.1;
|
|
23
|
+
/** How much of the picture's shorter side a body's disc is framed across at zoom 1, in the body's radii: 1, and more for a ringed body. */
|
|
24
|
+
export declare const framedOf: (id: string) => number;
|
|
23
25
|
/**
|
|
24
26
|
* The twenty-four bodies the space view places, names and lets a reader choose: the Earth, the Sun, the Moon, the seven other planets, Pluto, the eight other dwarf planets and the five minor bodies (Vesta, Pallas, Chiron, Pholus and Halley). The moons of the planets and of the dwarf planets are placed round their hosts.
|
|
25
27
|
*
|
package/dist/space/scene.js
CHANGED
|
@@ -13,7 +13,7 @@ import { arrowSites, ARROWS_PER_ORBIT, chevron, MAX_ARROWS_PER_ORBIT, spinArrow
|
|
|
13
13
|
import { besideMoon } from "./beside.js";
|
|
14
14
|
import { coveredBy } from "./covered.js";
|
|
15
15
|
import { spinAxis } from "./spin.js";
|
|
16
|
-
import { createTrack, eclipticToScene, frameAt, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS } from "./frame.js";
|
|
16
|
+
import { createTrack, EARTH_RADIUS_KM, eclipticToScene, frameAt, moonOrbit, planetOrbit, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS } from "./frame.js";
|
|
17
17
|
import { createPaintOverlay } from "./paint-overlay.js";
|
|
18
18
|
import { createPaintTrail, groundUnder, paintMinute } from "../paint/trail.js";
|
|
19
19
|
import { BALL_FRAGMENT, VERTEX } from "../scene/glsl.js";
|
|
@@ -39,6 +39,8 @@ const CLOSE_UP_PX = 30;
|
|
|
39
39
|
const MOON_RING_KEEP_MS = 5 * 86_400_000;
|
|
40
40
|
/** 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. */
|
|
41
41
|
const FRAMED = { saturn: 2.3 };
|
|
42
|
+
/** How much of the picture's shorter side a body's disc is framed across at zoom 1, in the body's radii: 1, and more for a ringed body. */
|
|
43
|
+
export const framedOf = (id) => FRAMED[id] ?? 1;
|
|
42
44
|
/** 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. */
|
|
43
45
|
const MOON_MIN_PLANET_PX = 4;
|
|
44
46
|
const MOON_MIN_PX = 2.2;
|
|
@@ -1262,8 +1264,11 @@ export function createSpaceItem(model, deps) {
|
|
|
1262
1264
|
const sight = (id, at, r) => {
|
|
1263
1265
|
projected.set(at[0], at[1], at[2]).applyMatrix4(camera.matrixWorldInverse);
|
|
1264
1266
|
const [cx, cy, front] = [projected.x, projected.y, projected.z < 0];
|
|
1267
|
+
// how far off the line of sight, and how far, in the camera's own axes (it looks down -z)
|
|
1268
|
+
const away = Math.hypot(projected.x, projected.y, projected.z);
|
|
1269
|
+
const offAxis = away === 0 ? 0 : (Math.acos(Math.max(-1, Math.min(1, -projected.z / away))) * 180) / Math.PI;
|
|
1265
1270
|
projected.applyMatrix4(camera.projectionMatrix);
|
|
1266
|
-
sights[id] = { front, x: front ? ((projected.x + 1) / 2) * size.width : 0, y: front ? ((1 - projected.y) / 2) * size.height : 0, r: front ? r : 0, dx: cx, dy: -cy };
|
|
1271
|
+
sights[id] = { front, x: front ? ((projected.x + 1) / 2) * size.width : 0, y: front ? ((1 - projected.y) / 2) * size.height : 0, r: front ? r : 0, dx: cx, dy: -cy, offAxis, distance: away, distanceKm: mode === "true" ? away * EARTH_RADIUS_KM : null };
|
|
1267
1272
|
};
|
|
1268
1273
|
for (const id of SPACE_BODIES)
|
|
1269
1274
|
if (id !== hiddenBody && !(rideFrom && id === rideFrom.around))
|
|
@@ -1274,6 +1279,8 @@ export function createSpaceItem(model, deps) {
|
|
|
1274
1279
|
sight(id, absoluteSite(id), moonPlaces[id]?.r ?? 0);
|
|
1275
1280
|
for (const craft of craftAts)
|
|
1276
1281
|
sight(craft.id, craft.at, craft.px);
|
|
1282
|
+
for (const [id, { at, px: dotPx }] of Object.entries(orbiterPlaces))
|
|
1283
|
+
sight(id, at, dotPx);
|
|
1277
1284
|
projected.set(0, 0, -1).applyMatrix4(camera.projectionMatrix);
|
|
1278
1285
|
deps.onSight(sights, { width: size.width, height: size.height, axis: { x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height } });
|
|
1279
1286
|
}
|
package/dist/space/sight.d.ts
CHANGED
|
@@ -29,6 +29,12 @@ export interface SightInput {
|
|
|
29
29
|
r: number;
|
|
30
30
|
dx: number;
|
|
31
31
|
dy: number;
|
|
32
|
+
/** Degrees between the camera's forward direction and the body, 0 to 180, when the caller knows it. */
|
|
33
|
+
offAxis?: number;
|
|
34
|
+
/** How far the body is from the camera, in the view's units (Earth radii), when the caller knows it. */
|
|
35
|
+
distance?: number;
|
|
36
|
+
/** The same distance in kilometres in the true scale, `null` in the compressed one. */
|
|
37
|
+
distanceKm?: number | null;
|
|
32
38
|
}
|
|
33
39
|
/**
|
|
34
40
|
* Where a body is for the picture: `inView` when its disc is on the picture; otherwise the `edge` it lies beyond, and `x`, `y`, the point on that edge where a line from the middle of the view to the body crosses it, with
|
|
@@ -75,6 +81,23 @@ export declare function sightOf(input: SightInput, width: number, height: number
|
|
|
75
81
|
x: number;
|
|
76
82
|
y: number;
|
|
77
83
|
}): Sight;
|
|
84
|
+
/**
|
|
85
|
+
* Whether a point of the picture is inside it less a margin on every side: `nx` and `ny` are its place from the middle in halves of the picture's width and height (-1 the left or top edge, 1 the right or bottom),
|
|
86
|
+
* and `margin` a fraction of the width for the left and right and of the height for the top and bottom. `turnTo` and a page's own "show" use the same test.
|
|
87
|
+
*
|
|
88
|
+
* @param nx - The place across, -1 to 1.
|
|
89
|
+
* @param ny - The place down, -1 to 1.
|
|
90
|
+
* @param margin - The fraction of each side kept clear, 0 to 0.5.
|
|
91
|
+
* @returns True when the point is inside the picture less the margin.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { withinMargin } from "@johnmorrisdotca/wakusei-planets/space";
|
|
96
|
+
*
|
|
97
|
+
* console.log(withinMargin(0.5, 0, 0.15), withinMargin(0.8, 0, 0.15));
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function withinMargin(nx: number, ny: number, margin: number): boolean;
|
|
78
101
|
/**
|
|
79
102
|
* How far, in CSS pixels, a body out of view moves along its edge before the view tells the page again.
|
|
80
103
|
*
|
package/dist/space/sight.js
CHANGED
|
@@ -40,6 +40,26 @@ export function sightOf(input, width, height, axis = { x: width / 2, y: height /
|
|
|
40
40
|
return { inView: false, behind: !input.front, edge, x, y, along: edge === "top" || edge === "bottom" ? x : y, angle: angleOf(dx, dy) };
|
|
41
41
|
}
|
|
42
42
|
const angleOf = (dx, dy) => (dx === 0 && dy === 0 ? 0 : ((Math.atan2(dx, -dy) * 180) / Math.PI + 360) % 360);
|
|
43
|
+
/**
|
|
44
|
+
* Whether a point of the picture is inside it less a margin on every side: `nx` and `ny` are its place from the middle in halves of the picture's width and height (-1 the left or top edge, 1 the right or bottom),
|
|
45
|
+
* and `margin` a fraction of the width for the left and right and of the height for the top and bottom. `turnTo` and a page's own "show" use the same test.
|
|
46
|
+
*
|
|
47
|
+
* @param nx - The place across, -1 to 1.
|
|
48
|
+
* @param ny - The place down, -1 to 1.
|
|
49
|
+
* @param margin - The fraction of each side kept clear, 0 to 0.5.
|
|
50
|
+
* @returns True when the point is inside the picture less the margin.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { withinMargin } from "@johnmorrisdotca/wakusei-planets/space";
|
|
55
|
+
*
|
|
56
|
+
* console.log(withinMargin(0.5, 0, 0.15), withinMargin(0.8, 0, 0.15));
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export function withinMargin(nx, ny, margin) {
|
|
60
|
+
const inner = 1 - 2 * margin;
|
|
61
|
+
return Math.abs(nx) <= inner && Math.abs(ny) <= inner;
|
|
62
|
+
}
|
|
43
63
|
/**
|
|
44
64
|
* How far, in CSS pixels, a body out of view moves along its edge before the view tells the page again.
|
|
45
65
|
*
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.52.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "0.
|
|
1
|
+
export const VERSION = "0.52.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/wakusei-planets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.52.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",
|
|
@@ -394,6 +394,11 @@
|
|
|
394
394
|
"import": "./dist/ground-track.js",
|
|
395
395
|
"default": "./dist/ground-track.js"
|
|
396
396
|
},
|
|
397
|
+
"./sky-bodies": {
|
|
398
|
+
"types": "./dist/sky-bodies.d.ts",
|
|
399
|
+
"import": "./dist/sky-bodies.js",
|
|
400
|
+
"default": "./dist/sky-bodies.js"
|
|
401
|
+
},
|
|
397
402
|
"./suncalc": {
|
|
398
403
|
"types": "./dist/suncalc.d.ts",
|
|
399
404
|
"import": "./dist/suncalc.js",
|