@johnmorrisdotca/wakusei-planets 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/NOTICE.md +14 -3
- package/README.md +39 -6
- package/dist/bodies/earth.js +13 -5
- package/dist/calendar.d.ts +119 -0
- package/dist/calendar.js +155 -0
- package/dist/clock.d.ts +244 -0
- package/dist/clock.js +325 -0
- package/dist/coordinates.d.ts +172 -0
- package/dist/coordinates.js +170 -0
- package/dist/craft/cassini.d.ts +1 -0
- package/dist/craft/cassini.js +1131 -0
- package/dist/craft/galileo.d.ts +1 -0
- package/dist/craft/galileo.js +224 -0
- package/dist/craft/juno.d.ts +1 -0
- package/dist/craft/juno.js +640 -0
- package/dist/craft/newhorizons.d.ts +1 -0
- package/dist/craft/newhorizons.js +18 -0
- package/dist/craft/parker.d.ts +1 -0
- package/dist/craft/parker.js +221 -0
- package/dist/craft/pioneer10.d.ts +1 -0
- package/dist/craft/pioneer10.js +24 -0
- package/dist/craft/pioneer11.d.ts +1 -0
- package/dist/craft/pioneer11.js +34 -0
- package/dist/craft/voyager1.d.ts +1 -0
- package/dist/craft/voyager1.js +28 -0
- package/dist/craft/voyager2.d.ts +1 -0
- package/dist/craft/voyager2.js +43 -0
- package/dist/craft/webb.d.ts +1 -0
- package/dist/craft/webb.js +28 -0
- package/dist/data/craft.d.ts +23 -0
- package/dist/data/craft.js +53 -0
- package/dist/data/lunar.d.ts +4 -0
- package/dist/data/lunar.js +548 -0
- package/dist/data/pluto.d.ts +6 -0
- package/dist/data/pluto.js +29 -0
- package/dist/data/stars.d.ts +4 -0
- package/dist/data/stars.js +5088 -0
- package/dist/data/tables.d.ts +41 -0
- package/dist/data/tables.js +37 -0
- package/dist/data/vsop.d.ts +19 -1
- package/dist/data/vsop.js +25 -8
- package/dist/element.d.ts +2 -23
- package/dist/element.js +75 -110
- package/dist/ephemeris.d.ts +22 -14
- package/dist/ephemeris.js +106 -58
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/mars.d.ts +41 -0
- package/dist/mars.js +52 -0
- package/dist/portrait/element.d.ts +1 -0
- package/dist/portrait/element.js +27 -39
- package/dist/scales.d.ts +46 -0
- package/dist/scales.js +75 -0
- package/dist/scene/basis.d.ts +3 -0
- package/dist/scene/basis.js +4 -0
- package/dist/scene/body.d.ts +2 -4
- package/dist/scene/body.js +55 -67
- package/dist/scene/fallback.d.ts +4 -0
- package/dist/scene/fallback.js +5 -0
- package/dist/scene/painter.js +10 -23
- package/dist/scene/store.d.ts +2 -2
- package/dist/scene/textures.d.ts +30 -0
- package/dist/scene/textures.js +47 -0
- package/dist/sidereal.d.ts +70 -0
- package/dist/sidereal.js +94 -0
- package/dist/sky/engine.d.ts +37 -0
- package/dist/sky/engine.js +116 -0
- package/dist/sky/events.d.ts +37 -0
- package/dist/sky/events.js +133 -0
- package/dist/sky/frames.d.ts +3 -0
- package/dist/sky/frames.js +26 -0
- package/dist/sky/types.d.ts +20 -0
- package/dist/sky/types.js +1 -0
- package/dist/space/aim.d.ts +18 -0
- package/dist/space/aim.js +28 -0
- package/dist/space/element.d.ts +212 -0
- package/dist/space/element.js +524 -0
- package/dist/space/frame.d.ts +152 -0
- package/dist/space/frame.js +169 -0
- package/dist/space/index.d.ts +4 -0
- package/dist/space/index.js +5 -0
- package/dist/space/ride.d.ts +89 -0
- package/dist/space/ride.js +58 -0
- package/dist/space/scale.d.ts +126 -0
- package/dist/space/scale.js +139 -0
- package/dist/space/scene.d.ts +189 -0
- package/dist/space/scene.js +422 -0
- package/dist/spacecraft-facts.d.ts +114 -0
- package/dist/spacecraft-facts.js +215 -0
- package/dist/spacecraft.d.ts +134 -0
- package/dist/spacecraft.js +198 -0
- package/dist/stars.d.ts +160 -0
- package/dist/stars.js +193 -0
- package/dist/suncalc-legacy.d.ts +187 -0
- package/dist/suncalc-legacy.js +168 -0
- package/dist/suncalc.d.ts +209 -0
- package/dist/suncalc.js +167 -0
- package/dist/tables/all.d.ts +2 -0
- package/dist/tables/all.js +2 -0
- package/dist/tables/ceres.d.ts +1 -0
- package/dist/tables/ceres.js +57 -0
- package/dist/tables/dwarfs.d.ts +1 -0
- package/dist/tables/dwarfs.js +59 -0
- package/dist/theory.d.ts +20 -0
- package/dist/theory.js +98 -0
- package/dist/time.d.ts +6 -108
- package/dist/time.js +7 -180
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/when.d.ts +16 -0
- package/dist/when.js +13 -0
- package/package.json +95 -4
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import type { EquatorialAngles, HorizontalAngles, Observer } from "./sky/types.ts";
|
|
2
|
+
/** Named axes. Of-date axes are mean, not nutated.
|
|
3
|
+
* @example
|
|
4
|
+
* ```ts
|
|
5
|
+
* import type { CoordinateFrame } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
6
|
+
* const value: CoordinateFrame = "eclipticJ2000";
|
|
7
|
+
* console.log(value);
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export type CoordinateFrame = "eclipticJ2000" | "equatorialJ2000" | "eclipticOfDate" | "equatorialOfDate";
|
|
11
|
+
/** Origin is preserved by every rotation; no observer translation is performed.
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import type { CoordinateOrigin } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
15
|
+
* const value: CoordinateOrigin = "geocentric";
|
|
16
|
+
* console.log(value);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export type CoordinateOrigin = "heliocentric" | "geocentric" | "topocentric";
|
|
20
|
+
/** Scientific context. Numeric epoch is Unix UTC milliseconds identifying the mean frame's instant; J2000 is JD 2451545.0 TT.
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* import type { CoordinateContext } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
24
|
+
* const value: CoordinateContext = { origin: "geocentric", frame: "equatorialJ2000", epoch: "J2000", corrections: "geometric" };
|
|
25
|
+
* console.log(value);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export interface CoordinateContext {
|
|
29
|
+
origin: CoordinateOrigin;
|
|
30
|
+
frame: CoordinateFrame;
|
|
31
|
+
epoch: "J2000" | number;
|
|
32
|
+
corrections: "geometric";
|
|
33
|
+
}
|
|
34
|
+
/** Spherical coordinates: longitude [0,360), latitude [-90,90], radius in AU.
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { cartesianToSpherical, type SphericalAu } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
38
|
+
* const value: SphericalAu = cartesianToSpherical({ origin: "heliocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", xAu: 0, yAu: 1, zAu: 0 });
|
|
39
|
+
* console.log(value);
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export interface SphericalAu extends CoordinateContext {
|
|
43
|
+
longitude: number;
|
|
44
|
+
latitude: number;
|
|
45
|
+
distanceAu: number;
|
|
46
|
+
}
|
|
47
|
+
/** Right-handed Cartesian components in AU: x at longitude zero, y at 90 degrees, z north.
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { sphericalToCartesian, type CartesianAu } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
51
|
+
* const value: CartesianAu = sphericalToCartesian({ origin: "heliocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", longitude: 90, latitude: 0, distanceAu: 1 });
|
|
52
|
+
* console.log(value);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export interface CartesianAu extends CoordinateContext {
|
|
56
|
+
xAu: number;
|
|
57
|
+
yAu: number;
|
|
58
|
+
zAu: number;
|
|
59
|
+
}
|
|
60
|
+
/** Ecliptic angles, in degrees, in the named mean ecliptic frame.
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { equatorialToEcliptic, type EclipticCoordinates } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
64
|
+
* const value: EclipticCoordinates = equatorialToEcliptic({ origin: "geocentric", frame: "equatorialJ2000", epoch: "J2000", corrections: "geometric", rightAscension: 90, declination: 0 });
|
|
65
|
+
* console.log(value);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export interface EclipticCoordinates extends CoordinateContext {
|
|
69
|
+
frame: "eclipticJ2000" | "eclipticOfDate";
|
|
70
|
+
eclipticLongitude: number;
|
|
71
|
+
eclipticLatitude: number;
|
|
72
|
+
}
|
|
73
|
+
/** Equatorial angles, in degrees (right ascension is never hours).
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { eclipticToEquatorial, type EquatorialCoordinates } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
77
|
+
* const value: EquatorialCoordinates = eclipticToEquatorial({ origin: "geocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", eclipticLongitude: 90, eclipticLatitude: 0 });
|
|
78
|
+
* console.log(value);
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export interface EquatorialCoordinates extends CoordinateContext, EquatorialAngles {
|
|
82
|
+
frame: "equatorialJ2000" | "equatorialOfDate";
|
|
83
|
+
}
|
|
84
|
+
/** Earth observer: degrees north/east; optional metres above the WGS 84 ellipsoid. Rotations do not use height.
|
|
85
|
+
* @example
|
|
86
|
+
* ```ts
|
|
87
|
+
* import type { CoordinateObserver } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
88
|
+
* const value: CoordinateObserver = { latitude: 49, longitude: -123 };
|
|
89
|
+
* console.log(value);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
export interface CoordinateObserver extends Observer {
|
|
93
|
+
heightM?: Observer["heightM"];
|
|
94
|
+
}
|
|
95
|
+
/** Geometric horizontal direction. Azimuth is clockwise from north; origin remains that of the supplied direction.
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { equatorialToHorizontal, type HorizontalCoordinates } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
99
|
+
* const value: HorizontalCoordinates = equatorialToHorizontal({ origin: "topocentric", frame: "equatorialOfDate", epoch: 0, corrections: "geometric", rightAscension: 0, declination: 0 }, 0, { observer: { latitude: 49, longitude: -123 } });
|
|
100
|
+
* console.log(value);
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export interface HorizontalCoordinates extends HorizontalAngles {
|
|
104
|
+
origin: CoordinateOrigin;
|
|
105
|
+
frame: "horizontal";
|
|
106
|
+
epoch: number;
|
|
107
|
+
corrections: "geometric";
|
|
108
|
+
}
|
|
109
|
+
/** Convert spherical to Cartesian, preserving origin, frame, epoch and geometric corrections. Radius must be positive.
|
|
110
|
+
* @param value - Coordinates with explicit origin, frame, epoch and geometric corrections.
|
|
111
|
+
* @returns Cartesian components in AU with the same context.
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* import { sphericalToCartesian } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
115
|
+
* console.log(sphericalToCartesian({ origin: "heliocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", longitude: 90, latitude: 0, distanceAu: 1 }));
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function sphericalToCartesian(value: SphericalAu): CartesianAu;
|
|
119
|
+
/** Convert Cartesian to spherical. Zero vectors throw; longitude at either pole is conventionally zero.
|
|
120
|
+
* @param value - Coordinates with explicit origin, frame, epoch and geometric corrections.
|
|
121
|
+
* @returns Spherical angles in degrees and radius in AU with the same context.
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* import { cartesianToSpherical } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
125
|
+
* console.log(cartesianToSpherical({ origin: "heliocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", xAu: 0, yAu: 1, zAu: 0 }));
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
export declare function cartesianToSpherical(value: CartesianAu): SphericalAu;
|
|
129
|
+
/** Mean obliquity in degrees: IAU 1980 (Meeus 22.2), evaluated in TT. Validated for 1800–2050; extrapolates outside it.
|
|
130
|
+
* @param when - Date or Unix UTC milliseconds.
|
|
131
|
+
* @returns Mean obliquity in degrees.
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* import { meanObliquity } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
135
|
+
* console.log(meanObliquity(new Date("2000-01-01T12:00:00Z")));
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export declare function meanObliquity(when: Date | number): number;
|
|
139
|
+
/** Rotate a mean ecliptic direction into the matching mean equatorial frame. No precession between epochs, nutation, aberration or light-time is added.
|
|
140
|
+
* @param value - Coordinates with explicit origin, frame, epoch and geometric corrections.
|
|
141
|
+
* @returns Right ascension and declination in the matching mean equatorial frame.
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* import { eclipticToEquatorial } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
145
|
+
* console.log(eclipticToEquatorial({ origin: "geocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", eclipticLongitude: 90, eclipticLatitude: 0 }));
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export declare function eclipticToEquatorial(value: EclipticCoordinates): EquatorialCoordinates;
|
|
149
|
+
/** Inverse mean-equator rotation, retaining the same origin and epoch.
|
|
150
|
+
* @param value - Coordinates with explicit origin, frame, epoch and geometric corrections.
|
|
151
|
+
* @returns Ecliptic longitude and latitude in the matching mean ecliptic frame.
|
|
152
|
+
* @example
|
|
153
|
+
* ```ts
|
|
154
|
+
* import { equatorialToEcliptic } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
155
|
+
* console.log(equatorialToEcliptic({ origin: "geocentric", frame: "equatorialJ2000", epoch: "J2000", corrections: "geometric", rightAscension: 90, declination: 0 }));
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export declare function equatorialToEcliptic(value: EquatorialCoordinates): EclipticCoordinates;
|
|
159
|
+
/** Rotate a mean equatorial-of-date direction to an observer's horizon (Meeus 12.4, 13.5–6). The input epoch must equal when. UTC approximates UT1; height is validated but unused. No parallax, refraction, nutation or horizon dip. Azimuth at zenith/nadir is conventionally zero.
|
|
160
|
+
* @param value - Mean equatorial-of-date direction with explicit origin and epoch.
|
|
161
|
+
* @param when - Date or Unix UTC milliseconds equal to the input epoch.
|
|
162
|
+
* @param options - Observer in degrees north/east; height in metres above the WGS 84 ellipsoid.
|
|
163
|
+
* @returns Altitude and north-based azimuth in degrees; original origin preserved.
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* import { equatorialToHorizontal } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
167
|
+
* console.log(equatorialToHorizontal({ origin: "topocentric", frame: "equatorialOfDate", epoch: 0, corrections: "geometric", rightAscension: 0, declination: 0 }, 0, { observer: { latitude: 49, longitude: -123 } }));
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
export declare function equatorialToHorizontal(value: EquatorialCoordinates, when: Date | number, options: {
|
|
171
|
+
observer: CoordinateObserver;
|
|
172
|
+
}): HorizontalCoordinates;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// Coordinate rotations: Meeus, Astronomical Algorithms, 2nd ed., chapters 12, 13, 22.
|
|
2
|
+
// Standalone mathematics; no body data, ephemerides or rendering dependencies.
|
|
3
|
+
import { ttMinusUtc } from "./clock.js";
|
|
4
|
+
import { meanObliquityArcseconds, meanSiderealDegrees } from "./sidereal.js";
|
|
5
|
+
const RAD = Math.PI / 180;
|
|
6
|
+
const J2000 = 2451545;
|
|
7
|
+
const DAY_MS = 86400000;
|
|
8
|
+
function finite(name, value) {
|
|
9
|
+
if (!Number.isFinite(value))
|
|
10
|
+
throw new RangeError(`${name}: ${String(value)} must be finite`);
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
function bounded(name, value, low, high) {
|
|
14
|
+
finite(name, value);
|
|
15
|
+
if (value < low || value > high)
|
|
16
|
+
throw new RangeError(`${name}: ${value} must be in [${low}, ${high}]`);
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function wrap(value) { return ((value % 360) + 360) % 360; }
|
|
20
|
+
function instant(when) {
|
|
21
|
+
const ms = finite("when", when instanceof Date ? when.getTime() : when);
|
|
22
|
+
if (Math.abs(ms) > 8640000000000000)
|
|
23
|
+
throw new RangeError(`when: ${ms} is outside the Date range`);
|
|
24
|
+
return ms;
|
|
25
|
+
}
|
|
26
|
+
function context(c) {
|
|
27
|
+
if (!["heliocentric", "geocentric", "topocentric"].includes(c.origin))
|
|
28
|
+
throw new RangeError(`origin: ${c.origin}`);
|
|
29
|
+
if (!["eclipticJ2000", "equatorialJ2000", "eclipticOfDate", "equatorialOfDate"].includes(c.frame))
|
|
30
|
+
throw new RangeError(`frame: ${c.frame}`);
|
|
31
|
+
if (c.corrections !== "geometric")
|
|
32
|
+
throw new RangeError(`corrections: ${c.corrections}; expected geometric`);
|
|
33
|
+
if (c.frame.endsWith("J2000")) {
|
|
34
|
+
if (c.epoch !== "J2000")
|
|
35
|
+
throw new RangeError(`epoch: ${c.epoch}; expected J2000`);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
if (typeof c.epoch !== "number")
|
|
39
|
+
throw new RangeError(`epoch: ${c.epoch}; expected Unix milliseconds`);
|
|
40
|
+
instant(c.epoch);
|
|
41
|
+
}
|
|
42
|
+
return { origin: c.origin, frame: c.frame, epoch: c.epoch, corrections: "geometric" };
|
|
43
|
+
}
|
|
44
|
+
function unitDirection(longitude, latitude) {
|
|
45
|
+
const l = wrap(finite("longitude", longitude)) * RAD;
|
|
46
|
+
const b = bounded("latitude", latitude, -90, 90) * RAD;
|
|
47
|
+
const cb = Math.abs(latitude) === 90 ? 0 : Math.cos(b);
|
|
48
|
+
return [cb * Math.cos(l), cb * Math.sin(l), Math.sin(b)];
|
|
49
|
+
}
|
|
50
|
+
function directionAngles(x, y, z, radius = Math.hypot(x, y, z)) {
|
|
51
|
+
const xy = Math.hypot(x, y);
|
|
52
|
+
return [xy < 1e-15 * radius ? 0 : wrap(Math.atan2(y, x) / RAD), Math.atan2(z, xy) / RAD];
|
|
53
|
+
}
|
|
54
|
+
/** Convert spherical to Cartesian, preserving origin, frame, epoch and geometric corrections. Radius must be positive.
|
|
55
|
+
* @param value - Coordinates with explicit origin, frame, epoch and geometric corrections.
|
|
56
|
+
* @returns Cartesian components in AU with the same context.
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { sphericalToCartesian } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
60
|
+
* console.log(sphericalToCartesian({ origin: "heliocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", longitude: 90, latitude: 0, distanceAu: 1 }));
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export function sphericalToCartesian(value) {
|
|
64
|
+
const c = context(value);
|
|
65
|
+
const d = finite("distanceAu", value.distanceAu);
|
|
66
|
+
if (d <= 0)
|
|
67
|
+
throw new RangeError(`distanceAu: ${d} must be positive`);
|
|
68
|
+
const [x, y, z] = unitDirection(value.longitude, value.latitude);
|
|
69
|
+
return { ...c, xAu: x * d, yAu: y * d, zAu: z * d };
|
|
70
|
+
}
|
|
71
|
+
/** Convert Cartesian to spherical. Zero vectors throw; longitude at either pole is conventionally zero.
|
|
72
|
+
* @param value - Coordinates with explicit origin, frame, epoch and geometric corrections.
|
|
73
|
+
* @returns Spherical angles in degrees and radius in AU with the same context.
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { cartesianToSpherical } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
77
|
+
* console.log(cartesianToSpherical({ origin: "heliocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", xAu: 0, yAu: 1, zAu: 0 }));
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export function cartesianToSpherical(value) {
|
|
81
|
+
const c = context(value);
|
|
82
|
+
const x = finite("xAu", value.xAu), y = finite("yAu", value.yAu), z = finite("zAu", value.zAu);
|
|
83
|
+
const d = finite("distanceAu", Math.hypot(x, y, z));
|
|
84
|
+
if (d === 0)
|
|
85
|
+
throw new RangeError("distanceAu: 0 has no direction");
|
|
86
|
+
const [longitude, latitude] = directionAngles(x / d, y / d, z / d);
|
|
87
|
+
return { ...c, longitude, latitude, distanceAu: d };
|
|
88
|
+
}
|
|
89
|
+
/** Mean obliquity in degrees: IAU 1980 (Meeus 22.2), evaluated in TT. Validated for 1800–2050; extrapolates outside it.
|
|
90
|
+
* @param when - Date or Unix UTC milliseconds.
|
|
91
|
+
* @returns Mean obliquity in degrees.
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* import { meanObliquity } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
95
|
+
* console.log(meanObliquity(new Date("2000-01-01T12:00:00Z")));
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export function meanObliquity(when) {
|
|
99
|
+
const utc = instant(when);
|
|
100
|
+
const t = ((utc + ttMinusUtc(utc) * 1000) / DAY_MS + 2440587.5 - J2000) / 36525;
|
|
101
|
+
return meanObliquityArcseconds(t) / 3600;
|
|
102
|
+
}
|
|
103
|
+
function obliquity(c) {
|
|
104
|
+
return (c.epoch === "J2000" ? meanObliquityArcseconds(0) / 3600 : meanObliquity(c.epoch)) * RAD;
|
|
105
|
+
}
|
|
106
|
+
/** Rotate a mean ecliptic direction into the matching mean equatorial frame. No precession between epochs, nutation, aberration or light-time is added.
|
|
107
|
+
* @param value - Coordinates with explicit origin, frame, epoch and geometric corrections.
|
|
108
|
+
* @returns Right ascension and declination in the matching mean equatorial frame.
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* import { eclipticToEquatorial } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
112
|
+
* console.log(eclipticToEquatorial({ origin: "geocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", eclipticLongitude: 90, eclipticLatitude: 0 }));
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export function eclipticToEquatorial(value) {
|
|
116
|
+
const c = context(value);
|
|
117
|
+
if (!c.frame.startsWith("ecliptic"))
|
|
118
|
+
throw new RangeError(`frame: ${c.frame}; expected ecliptic`);
|
|
119
|
+
const [x, y, z] = unitDirection(value.eclipticLongitude, value.eclipticLatitude);
|
|
120
|
+
const e = obliquity(c);
|
|
121
|
+
const [rightAscension, declination] = directionAngles(x, y * Math.cos(e) - z * Math.sin(e), y * Math.sin(e) + z * Math.cos(e));
|
|
122
|
+
return { ...c, frame: c.frame === "eclipticJ2000" ? "equatorialJ2000" : "equatorialOfDate", rightAscension, declination };
|
|
123
|
+
}
|
|
124
|
+
/** Inverse mean-equator rotation, retaining the same origin and epoch.
|
|
125
|
+
* @param value - Coordinates with explicit origin, frame, epoch and geometric corrections.
|
|
126
|
+
* @returns Ecliptic longitude and latitude in the matching mean ecliptic frame.
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* import { equatorialToEcliptic } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
130
|
+
* console.log(equatorialToEcliptic({ origin: "geocentric", frame: "equatorialJ2000", epoch: "J2000", corrections: "geometric", rightAscension: 90, declination: 0 }));
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export function equatorialToEcliptic(value) {
|
|
134
|
+
const c = context(value);
|
|
135
|
+
if (!c.frame.startsWith("equatorial"))
|
|
136
|
+
throw new RangeError(`frame: ${c.frame}; expected equatorial`);
|
|
137
|
+
const [x, y, z] = unitDirection(value.rightAscension, value.declination);
|
|
138
|
+
const e = obliquity(c);
|
|
139
|
+
const [eclipticLongitude, eclipticLatitude] = directionAngles(x, y * Math.cos(e) + z * Math.sin(e), -y * Math.sin(e) + z * Math.cos(e));
|
|
140
|
+
return { ...c, frame: c.frame === "equatorialJ2000" ? "eclipticJ2000" : "eclipticOfDate", eclipticLongitude, eclipticLatitude };
|
|
141
|
+
}
|
|
142
|
+
/** Rotate a mean equatorial-of-date direction to an observer's horizon (Meeus 12.4, 13.5–6). The input epoch must equal when. UTC approximates UT1; height is validated but unused. No parallax, refraction, nutation or horizon dip. Azimuth at zenith/nadir is conventionally zero.
|
|
143
|
+
* @param value - Mean equatorial-of-date direction with explicit origin and epoch.
|
|
144
|
+
* @param when - Date or Unix UTC milliseconds equal to the input epoch.
|
|
145
|
+
* @param options - Observer in degrees north/east; height in metres above the WGS 84 ellipsoid.
|
|
146
|
+
* @returns Altitude and north-based azimuth in degrees; original origin preserved.
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* import { equatorialToHorizontal } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
150
|
+
* console.log(equatorialToHorizontal({ origin: "topocentric", frame: "equatorialOfDate", epoch: 0, corrections: "geometric", rightAscension: 0, declination: 0 }, 0, { observer: { latitude: 49, longitude: -123 } }));
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export function equatorialToHorizontal(value, when, options) {
|
|
154
|
+
const c = context(value), ms = instant(when);
|
|
155
|
+
if (c.frame !== "equatorialOfDate" || c.epoch !== ms)
|
|
156
|
+
throw new RangeError(`frame/epoch: ${c.frame}/${c.epoch}; expected equatorialOfDate at when ${ms}`);
|
|
157
|
+
const observer = options.observer;
|
|
158
|
+
const p = bounded("observer.latitude", observer.latitude, -90, 90) * RAD;
|
|
159
|
+
const l = bounded("observer.longitude", observer.longitude, -180, 180);
|
|
160
|
+
finite("observer.heightM", observer.heightM ?? 0);
|
|
161
|
+
const ra = wrap(finite("rightAscension", value.rightAscension));
|
|
162
|
+
const d = bounded("declination", value.declination, -90, 90) * RAD;
|
|
163
|
+
const days = ms / DAY_MS + 2440587.5 - J2000;
|
|
164
|
+
const h = wrap(meanSiderealDegrees(days) + l - ra) * RAD;
|
|
165
|
+
const east = -Math.cos(d) * Math.sin(h);
|
|
166
|
+
const north = Math.sin(d) * Math.cos(p) - Math.cos(d) * Math.cos(h) * Math.sin(p);
|
|
167
|
+
const up = Math.sin(d) * Math.sin(p) + Math.cos(d) * Math.cos(h) * Math.cos(p);
|
|
168
|
+
const [azimuth, altitude] = directionAngles(north, east, up, 1);
|
|
169
|
+
return { origin: c.origin, frame: "horizontal", epoch: ms, corrections: "geometric", altitude, azimuth };
|
|
170
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|