@johnmorrisdotca/wakusei-planets 0.51.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 CHANGED
@@ -2,6 +2,12 @@
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
+
5
11
  ## [0.51.0] - 2026-11-13
6
12
 
7
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.
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.51.0/docs/images/lineup-desk.png" width="640"></p>
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.51.0/docs/images/portrait-family.png" width="640"></p>
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.51.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
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
 
@@ -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.51.0/dist/textures/";
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.51.0/textures/";
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/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.51.0";
1
+ export declare const VERSION = "0.52.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.51.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.51.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",