@johnmorrisdotca/wakusei-planets 0.19.0 → 0.20.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 +10 -0
- package/NOTICE.md +5 -3
- package/README.md +8 -5
- package/dist/calendar.d.ts +119 -0
- package/dist/calendar.js +154 -0
- package/dist/clock.d.ts +244 -0
- package/dist/clock.js +326 -0
- package/dist/coordinates.d.ts +177 -0
- package/dist/coordinates.js +169 -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/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 +3 -2
- package/dist/element.js +1 -0
- package/dist/ephemeris.d.ts +3 -15
- package/dist/ephemeris.js +66 -49
- package/dist/mars.d.ts +41 -0
- package/dist/mars.js +52 -0
- package/dist/scales.d.ts +46 -0
- package/dist/scales.js +75 -0
- package/dist/sidereal.d.ts +66 -0
- package/dist/sidereal.js +88 -0
- package/dist/sky/engine.d.ts +46 -0
- package/dist/sky/engine.js +145 -0
- package/dist/sky/events.d.ts +37 -0
- package/dist/sky/events.js +133 -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 +173 -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 +18 -0
- package/package.json +45 -3
package/dist/clock.js
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
// The clock under the sky: Julian dates, the leap seconds and delta T, and the step from the clock (UTC) to terrestrial time (TT), the dynamical time the planets' theories are written in. Pure: no DOM, no three.js.
|
|
2
|
+
// `time.ts` is the public entry that gathers this with the calendar, the time scales, sidereal time and Mars time.
|
|
3
|
+
// From 1972 the step is exact: TT is TAI plus 32.184 seconds and TAI is UTC plus the leap seconds (IERS Bulletin C). Before 1972 it is delta T, from the polynomials of Espenak and Meeus
|
|
4
|
+
// (NASA, https://eclipse.gsfc.nasa.gov/SEhelp/deltatpoly2004.html, for 1800 to 1972) and Morrison and Stephenson's parabola outside 1800 to 1972.
|
|
5
|
+
import { moment } from "./when.js";
|
|
6
|
+
export const DAY_MS = 86_400_000;
|
|
7
|
+
/** The Julian date of the Unix epoch, 1970-01-01T00:00:00Z. */
|
|
8
|
+
export const UNIX_EPOCH_JD = 2_440_587.5;
|
|
9
|
+
/** The Julian date of the Unix epoch in milliseconds: exact in a 64-bit number, so the day and the milliseconds of the day lose nothing. */
|
|
10
|
+
const JD_EPOCH_MS = 210_866_760_000_000;
|
|
11
|
+
const MJD_OFFSET = 2_400_000.5;
|
|
12
|
+
export const TT_MINUS_TAI_SECONDS = 32.184;
|
|
13
|
+
/** The length of a Gregorian year in milliseconds, for turning a time into a decimal year. */
|
|
14
|
+
export const YEAR_MS = 31_556_952_000;
|
|
15
|
+
/** TAI minus UTC, in seconds, from the date it took effect (IERS Bulletin C). After the last one, none has been added. */
|
|
16
|
+
export const LEAP_SECONDS = [
|
|
17
|
+
[Date.UTC(1972, 0, 1), 10], [Date.UTC(1972, 6, 1), 11], [Date.UTC(1973, 0, 1), 12], [Date.UTC(1974, 0, 1), 13], [Date.UTC(1975, 0, 1), 14], [Date.UTC(1976, 0, 1), 15],
|
|
18
|
+
[Date.UTC(1977, 0, 1), 16], [Date.UTC(1978, 0, 1), 17], [Date.UTC(1979, 0, 1), 18], [Date.UTC(1980, 0, 1), 19], [Date.UTC(1981, 6, 1), 20], [Date.UTC(1982, 6, 1), 21],
|
|
19
|
+
[Date.UTC(1983, 6, 1), 22], [Date.UTC(1985, 6, 1), 23], [Date.UTC(1988, 0, 1), 24], [Date.UTC(1990, 0, 1), 25], [Date.UTC(1991, 0, 1), 26], [Date.UTC(1992, 6, 1), 27],
|
|
20
|
+
[Date.UTC(1993, 6, 1), 28], [Date.UTC(1994, 6, 1), 29], [Date.UTC(1996, 0, 1), 30], [Date.UTC(1997, 6, 1), 31], [Date.UTC(1999, 0, 1), 32], [Date.UTC(2006, 0, 1), 33],
|
|
21
|
+
[Date.UTC(2009, 0, 1), 34], [Date.UTC(2012, 6, 1), 35], [Date.UTC(2015, 6, 1), 36], [Date.UTC(2017, 0, 1), 37],
|
|
22
|
+
];
|
|
23
|
+
/**
|
|
24
|
+
* A time as a Julian date: the days since noon on 1 January 4713 BC (Julian calendar), as a number. A `Date` or milliseconds since 1970 in, the same scale out (UTC stays UTC).
|
|
25
|
+
* A number near today holds about a tenth of a millisecond; `toJulianDay` and `toMillisecondsInJulianDay` give the same instant with nothing lost.
|
|
26
|
+
* @param when - A `Date` or milliseconds since 1970.
|
|
27
|
+
* @returns The Julian date.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { toJulianDate } from "@johnmorrisdotca/wakusei-planets/time";
|
|
32
|
+
*
|
|
33
|
+
* console.log(toJulianDate(Date.UTC(2013, 10, 21, 10, 47, 2)).toFixed(6));
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export function toJulianDate(when) {
|
|
37
|
+
return moment(when) / DAY_MS + UNIX_EPOCH_JD;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The time, in milliseconds since 1970, of a Julian date.
|
|
41
|
+
* @param jd - The Julian date.
|
|
42
|
+
* @returns Milliseconds since 1970.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { fromJulianDate } from "@johnmorrisdotca/wakusei-planets/time";
|
|
47
|
+
*
|
|
48
|
+
* console.log(new Date(fromJulianDate(2451545)).toISOString());
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export function fromJulianDate(jd) {
|
|
52
|
+
return (jd - UNIX_EPOCH_JD) * DAY_MS;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The modified Julian date: the Julian date less 2,400,000.5, so a day starts at midnight and the numbers are shorter.
|
|
56
|
+
* @param when - A `Date` or milliseconds since 1970.
|
|
57
|
+
* @returns The modified Julian date.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { modifiedJulianDate } from "@johnmorrisdotca/wakusei-planets/time";
|
|
62
|
+
*
|
|
63
|
+
* console.log(modifiedJulianDate(Date.UTC(2000, 0, 1)));
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export function modifiedJulianDate(when) {
|
|
67
|
+
return toJulianDate(when) - MJD_OFFSET;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The whole Julian day of a time. A Julian day starts at noon, so 11:59 and 12:00 are in different days.
|
|
71
|
+
* @param when - A `Date` or milliseconds since 1970.
|
|
72
|
+
* @returns The integer Julian day number.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* import { toJulianDay } from "@johnmorrisdotca/wakusei-planets/time";
|
|
77
|
+
*
|
|
78
|
+
* console.log(toJulianDay(Date.UTC(2000, 0, 1, 12)));
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export function toJulianDay(when) {
|
|
82
|
+
return Math.floor((moment(when) + JD_EPOCH_MS) / DAY_MS);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The milliseconds since noon, the start of the Julian day, that a time is into it.
|
|
86
|
+
* @param when - A `Date` or milliseconds since 1970.
|
|
87
|
+
* @returns Milliseconds from 0 up to one day.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { toMillisecondsInJulianDay } from "@johnmorrisdotca/wakusei-planets/time";
|
|
92
|
+
*
|
|
93
|
+
* console.log(toMillisecondsInJulianDay(Date.UTC(2000, 0, 1, 18)));
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export function toMillisecondsInJulianDay(when) {
|
|
97
|
+
const t = moment(when) + JD_EPOCH_MS;
|
|
98
|
+
return t - Math.floor(t / DAY_MS) * DAY_MS;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* A time from a Julian day and the milliseconds into it, with no digit lost: `fromJulianDayAndMilliseconds(toJulianDay(t), toMillisecondsInJulianDay(t))` is `t`.
|
|
102
|
+
* @param day - The integer Julian day number.
|
|
103
|
+
* @param msInDay - Milliseconds since the day began at noon.
|
|
104
|
+
* @returns Milliseconds since 1970.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* import { fromJulianDayAndMilliseconds, toJulianDay, toMillisecondsInJulianDay } from "@johnmorrisdotca/wakusei-planets/time";
|
|
109
|
+
*
|
|
110
|
+
* const t = Date.UTC(2026, 10, 7, 9, 30, 15, 123);
|
|
111
|
+
* console.log(fromJulianDayAndMilliseconds(toJulianDay(t), toMillisecondsInJulianDay(t)) === t);
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export function fromJulianDayAndMilliseconds(day, msInDay) {
|
|
115
|
+
return day * DAY_MS + msInDay - JD_EPOCH_MS;
|
|
116
|
+
}
|
|
117
|
+
export function deltaTPolynomial(year) {
|
|
118
|
+
if (year < 1800 || year >= 1972) {
|
|
119
|
+
const u = (year - 1820) / 100;
|
|
120
|
+
return -20 + 32 * u * u;
|
|
121
|
+
}
|
|
122
|
+
if (year < 1860) {
|
|
123
|
+
const t = year - 1800;
|
|
124
|
+
return 13.72 - 0.332447 * t + 0.0068612 * t ** 2 + 0.0041116 * t ** 3 - 0.00037436 * t ** 4 + 0.0000121272 * t ** 5 - 0.0000001699 * t ** 6 + 0.000000000875 * t ** 7;
|
|
125
|
+
}
|
|
126
|
+
if (year < 1900) {
|
|
127
|
+
const t = year - 1860;
|
|
128
|
+
return 7.62 + 0.5737 * t - 0.251754 * t ** 2 + 0.01680668 * t ** 3 - 0.0004473624 * t ** 4 + t ** 5 / 233174;
|
|
129
|
+
}
|
|
130
|
+
if (year < 1920) {
|
|
131
|
+
const t = year - 1900;
|
|
132
|
+
return -2.79 + 1.494119 * t - 0.0598939 * t ** 2 + 0.0061966 * t ** 3 - 0.000197 * t ** 4;
|
|
133
|
+
}
|
|
134
|
+
if (year < 1941) {
|
|
135
|
+
const t = year - 1920;
|
|
136
|
+
return 21.2 + 0.84493 * t - 0.0761 * t ** 2 + 0.0020936 * t ** 3;
|
|
137
|
+
}
|
|
138
|
+
if (year < 1961) {
|
|
139
|
+
const t = year - 1950;
|
|
140
|
+
return 29.07 + 0.407 * t - t ** 2 / 233 + t ** 3 / 2547;
|
|
141
|
+
}
|
|
142
|
+
const t = year - 1975;
|
|
143
|
+
return 45.45 + 1.067 * t - t ** 2 / 260 - t ** 3 / 718;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Terrestrial time minus the clock's time, in seconds, at a moment given in UTC: 69.184 from the last leap second in 2017 on (until another is added), exact from 1972, and delta T before.
|
|
147
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
148
|
+
* @returns Seconds to add to UTC to get TT.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```ts
|
|
152
|
+
* import { ttMinusUtc } from "@johnmorrisdotca/wakusei-planets/time";
|
|
153
|
+
*
|
|
154
|
+
* console.log(ttMinusUtc(Date.UTC(2026, 10, 7)));
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export function ttMinusUtc(when) {
|
|
158
|
+
const ms = moment(when);
|
|
159
|
+
if (ms >= LEAP_SECONDS[0][0]) {
|
|
160
|
+
let taiMinusUtc = LEAP_SECONDS[0][1];
|
|
161
|
+
for (const [from, seconds] of LEAP_SECONDS)
|
|
162
|
+
if (ms >= from)
|
|
163
|
+
taiMinusUtc = seconds;
|
|
164
|
+
return taiMinusUtc + TT_MINUS_TAI_SECONDS;
|
|
165
|
+
}
|
|
166
|
+
return deltaTPolynomial(1970 + ms / YEAR_MS);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* A moment in UTC as the same moment in terrestrial time, on the same scale of milliseconds since 1970.
|
|
170
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
171
|
+
* @returns The same moment in TT, in milliseconds.
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```ts
|
|
175
|
+
* import { toTerrestrialTime } from "@johnmorrisdotca/wakusei-planets/time";
|
|
176
|
+
*
|
|
177
|
+
* const utc = Date.UTC(2000, 0, 1, 12);
|
|
178
|
+
* console.log((toTerrestrialTime(utc) - utc) / 1000);
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
export function toTerrestrialTime(when) {
|
|
182
|
+
const ms = moment(when);
|
|
183
|
+
return ms + ttMinusUtc(ms) * 1000;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* The Julian date of J2000.0, 2000-01-01 12:00 TT: the epoch of the planets' theories.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```ts
|
|
190
|
+
* import { J2000_JD, toJulianDate } from "@johnmorrisdotca/wakusei-planets/time";
|
|
191
|
+
*
|
|
192
|
+
* console.log(J2000_JD === toJulianDate(Date.UTC(2000, 0, 1, 12)));
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
export const J2000_JD = 2_451_545;
|
|
196
|
+
/**
|
|
197
|
+
* J2000.0, 2000-01-01 12:00, as milliseconds since 1970 counted on a clock that reads TT: a terrestrial time is this far from it.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* import { J2000_MS } from "@johnmorrisdotca/wakusei-planets/time";
|
|
202
|
+
*
|
|
203
|
+
* console.log(new Date(J2000_MS).toISOString());
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
export const J2000_MS = 946_728_000_000;
|
|
207
|
+
/**
|
|
208
|
+
* The Julian date of the Besselian epoch B1950.0, 1950 January 0.923 (Meeus).
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```ts
|
|
212
|
+
* import { B1950_JD } from "@johnmorrisdotca/wakusei-planets/time";
|
|
213
|
+
*
|
|
214
|
+
* console.log(B1950_JD);
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
export const B1950_JD = 2_433_282.4235;
|
|
218
|
+
/**
|
|
219
|
+
* The Julian date of the Unix epoch, 1970-01-01T00:00:00Z (UTC).
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* import { UNIX_EPOCH_JULIAN_DATE, toJulianDate } from "@johnmorrisdotca/wakusei-planets/time";
|
|
224
|
+
*
|
|
225
|
+
* console.log(UNIX_EPOCH_JULIAN_DATE === toJulianDate(0));
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export const UNIX_EPOCH_JULIAN_DATE = UNIX_EPOCH_JD;
|
|
229
|
+
/**
|
|
230
|
+
* A time as a string of its Julian date with six decimals, as the `julian` package gives it (a tenth of a second).
|
|
231
|
+
* @param when - A `Date` or milliseconds since 1970.
|
|
232
|
+
* @returns The Julian date as a string.
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```ts
|
|
236
|
+
* import { julian } from "@johnmorrisdotca/wakusei-planets/time";
|
|
237
|
+
*
|
|
238
|
+
* console.log(julian(new Date("2013-11-21T10:47:02Z")));
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
export function julian(when) {
|
|
242
|
+
return toJulianDate(when).toFixed(6);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* The `Date` of a Julian date (a number, or the string `julian` gives), rounded to the millisecond.
|
|
246
|
+
* @param jd - The Julian date.
|
|
247
|
+
* @returns A `Date`.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```ts
|
|
251
|
+
* import { toDate } from "@johnmorrisdotca/wakusei-planets/time";
|
|
252
|
+
*
|
|
253
|
+
* console.log(toDate("2456617.949335").toISOString());
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
export function toDate(jd) {
|
|
257
|
+
const value = typeof jd === "string" ? Number(jd) : jd;
|
|
258
|
+
if (!Number.isFinite(value))
|
|
259
|
+
throw new RangeError(`jd must be a finite Julian date, got ${String(jd)}`);
|
|
260
|
+
return new Date(Math.round(fromJulianDate(value)));
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Julian centuries (36,525 days) from J2000.0: the time argument of most theories. In terrestrial time unless `scale` says UTC.
|
|
264
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
265
|
+
* @param scale - `"tt"` (the default, what the theories want) or `"utc"` to count the clock's days.
|
|
266
|
+
* @returns Julian centuries, negative before 2000.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```ts
|
|
270
|
+
* import { julianCenturies } from "@johnmorrisdotca/wakusei-planets/time";
|
|
271
|
+
*
|
|
272
|
+
* console.log(julianCenturies(Date.UTC(2100, 0, 1, 12)).toFixed(6));
|
|
273
|
+
* ```
|
|
274
|
+
*/
|
|
275
|
+
export function julianCenturies(when, scale = "tt") {
|
|
276
|
+
const ms = scale === "tt" ? toTerrestrialTime(when) : moment(when);
|
|
277
|
+
return (ms - J2000_MS) / (36_525 * DAY_MS);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Julian millennia (365,250 days) from J2000.0, in terrestrial time unless `scale` says UTC: the time argument of the VSOP87 series.
|
|
281
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
282
|
+
* @param scale - `"tt"` (the default) or `"utc"`.
|
|
283
|
+
* @returns Julian millennia, negative before 2000.
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```ts
|
|
287
|
+
* import { julianMillennia } from "@johnmorrisdotca/wakusei-planets/time";
|
|
288
|
+
*
|
|
289
|
+
* console.log(julianMillennia(Date.UTC(3000, 0, 1, 12)).toFixed(6));
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
export function julianMillennia(when, scale = "tt") {
|
|
293
|
+
return julianCenturies(when, scale) / 10;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* TAI minus UTC in seconds: the leap seconds from 1972 (10 then, 37 since 2017), and before 1972 delta T less 32.184, which is how far the atomic scale would have been from the Earth's turn.
|
|
297
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
298
|
+
* @returns Seconds to add to UTC to get TAI.
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* ```ts
|
|
302
|
+
* import { taiMinusUtc } from "@johnmorrisdotca/wakusei-planets/time";
|
|
303
|
+
*
|
|
304
|
+
* console.log(taiMinusUtc(Date.UTC(2026, 10, 7)));
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
export function taiMinusUtc(when) {
|
|
308
|
+
return ttMinusUtc(when) - TT_MINUS_TAI_SECONDS;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Delta T, terrestrial time minus universal time (UT1), in seconds. From 1972 it is the leap seconds plus 32.184 s less `dut1` (UT1 minus UTC, which the IERS publishes and is under 0.9 s: leave it out and it is taken as 0),
|
|
312
|
+
* before 1972 the polynomials of Espenak and Meeus (NASA). After the last leap second it is held at 69.184 s, the assumption JPL Horizons makes.
|
|
313
|
+
* @param when - A `Date` or milliseconds since 1970 (UTC).
|
|
314
|
+
* @param dut1 - UT1 minus UTC in seconds, from the IERS; default 0.
|
|
315
|
+
* @returns Seconds.
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* ```ts
|
|
319
|
+
* import { deltaT } from "@johnmorrisdotca/wakusei-planets/time";
|
|
320
|
+
*
|
|
321
|
+
* console.log(deltaT(Date.UTC(1900, 0, 1)).toFixed(1), deltaT(Date.UTC(2026, 10, 7)));
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
export function deltaT(when, dut1 = 0) {
|
|
325
|
+
return ttMinusUtc(when) - dut1;
|
|
326
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/** Named axes. Of-date axes are mean, not nutated.
|
|
2
|
+
* @example
|
|
3
|
+
* ```ts
|
|
4
|
+
* import type { CoordinateFrame } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
5
|
+
* const value: CoordinateFrame = "eclipticJ2000";
|
|
6
|
+
* console.log(value);
|
|
7
|
+
* ```
|
|
8
|
+
*/
|
|
9
|
+
export type CoordinateFrame = "eclipticJ2000" | "equatorialJ2000" | "eclipticOfDate" | "equatorialOfDate";
|
|
10
|
+
/** Origin is preserved by every rotation; no observer translation is performed.
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import type { CoordinateOrigin } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
14
|
+
* const value: CoordinateOrigin = "geocentric";
|
|
15
|
+
* console.log(value);
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export type CoordinateOrigin = "heliocentric" | "geocentric" | "topocentric";
|
|
19
|
+
/** Scientific context. Numeric epoch is Unix UTC milliseconds identifying the mean frame's instant; J2000 is JD 2451545.0 TT.
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import type { CoordinateContext } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
23
|
+
* const value: CoordinateContext = { origin: "geocentric", frame: "equatorialJ2000", epoch: "J2000", corrections: "geometric" };
|
|
24
|
+
* console.log(value);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export interface CoordinateContext {
|
|
28
|
+
origin: CoordinateOrigin;
|
|
29
|
+
frame: CoordinateFrame;
|
|
30
|
+
epoch: "J2000" | number;
|
|
31
|
+
corrections: "geometric";
|
|
32
|
+
}
|
|
33
|
+
/** Spherical coordinates: longitude [0,360), latitude [-90,90], radius in AU.
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { cartesianToSpherical, type SphericalAu } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
37
|
+
* const value: SphericalAu = cartesianToSpherical({ origin: "heliocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", xAu: 0, yAu: 1, zAu: 0 });
|
|
38
|
+
* console.log(value);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export interface SphericalAu extends CoordinateContext {
|
|
42
|
+
longitude: number;
|
|
43
|
+
latitude: number;
|
|
44
|
+
distanceAu: number;
|
|
45
|
+
}
|
|
46
|
+
/** Right-handed Cartesian components in AU: x at longitude zero, y at 90 degrees, z north.
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { sphericalToCartesian, type CartesianAu } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
50
|
+
* const value: CartesianAu = sphericalToCartesian({ origin: "heliocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", longitude: 90, latitude: 0, distanceAu: 1 });
|
|
51
|
+
* console.log(value);
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export interface CartesianAu extends CoordinateContext {
|
|
55
|
+
xAu: number;
|
|
56
|
+
yAu: number;
|
|
57
|
+
zAu: number;
|
|
58
|
+
}
|
|
59
|
+
/** Ecliptic angles, in degrees, in the named mean ecliptic frame.
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { equatorialToEcliptic, type EclipticCoordinates } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
63
|
+
* const value: EclipticCoordinates = equatorialToEcliptic({ origin: "geocentric", frame: "equatorialJ2000", epoch: "J2000", corrections: "geometric", rightAscension: 90, declination: 0 });
|
|
64
|
+
* console.log(value);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export interface EclipticCoordinates extends CoordinateContext {
|
|
68
|
+
frame: "eclipticJ2000" | "eclipticOfDate";
|
|
69
|
+
eclipticLongitude: number;
|
|
70
|
+
eclipticLatitude: number;
|
|
71
|
+
}
|
|
72
|
+
/** Equatorial angles, in degrees (right ascension is never hours).
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { eclipticToEquatorial, type EquatorialCoordinates } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
76
|
+
* const value: EquatorialCoordinates = eclipticToEquatorial({ origin: "geocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", eclipticLongitude: 90, eclipticLatitude: 0 });
|
|
77
|
+
* console.log(value);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
export interface EquatorialCoordinates extends CoordinateContext {
|
|
81
|
+
frame: "equatorialJ2000" | "equatorialOfDate";
|
|
82
|
+
rightAscension: number;
|
|
83
|
+
declination: number;
|
|
84
|
+
}
|
|
85
|
+
/** Earth observer: degrees north/east; optional metres above mean sea level. Rotations do not use height.
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* import type { CoordinateObserver } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
89
|
+
* const value: CoordinateObserver = { latitude: 49, longitude: -123 };
|
|
90
|
+
* console.log(value);
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export interface CoordinateObserver {
|
|
94
|
+
latitude: number;
|
|
95
|
+
longitude: number;
|
|
96
|
+
heightM?: number;
|
|
97
|
+
}
|
|
98
|
+
/** Geometric horizontal direction. Azimuth is clockwise from north; origin remains that of the supplied direction.
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { equatorialToHorizontal, type HorizontalCoordinates } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
102
|
+
* const value: HorizontalCoordinates = equatorialToHorizontal({ origin: "topocentric", frame: "equatorialOfDate", epoch: 0, corrections: "geometric", rightAscension: 0, declination: 0 }, 0, { observer: { latitude: 49, longitude: -123 } });
|
|
103
|
+
* console.log(value);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export interface HorizontalCoordinates {
|
|
107
|
+
origin: CoordinateOrigin;
|
|
108
|
+
frame: "horizontal";
|
|
109
|
+
epoch: number;
|
|
110
|
+
corrections: "geometric";
|
|
111
|
+
altitude: number;
|
|
112
|
+
azimuth: number;
|
|
113
|
+
}
|
|
114
|
+
/** Convert spherical to Cartesian, preserving origin, frame, epoch and geometric corrections. Radius must be positive.
|
|
115
|
+
* @param value - Coordinates with explicit origin, frame, epoch and geometric corrections.
|
|
116
|
+
* @returns Cartesian components in AU with the same context.
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* import { sphericalToCartesian } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
120
|
+
* console.log(sphericalToCartesian({ origin: "heliocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", longitude: 90, latitude: 0, distanceAu: 1 }));
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare function sphericalToCartesian(value: SphericalAu): CartesianAu;
|
|
124
|
+
/** Convert Cartesian to spherical. Zero vectors throw; longitude at either pole is conventionally zero.
|
|
125
|
+
* @param value - Coordinates with explicit origin, frame, epoch and geometric corrections.
|
|
126
|
+
* @returns Spherical angles in degrees and radius in AU with the same context.
|
|
127
|
+
* @example
|
|
128
|
+
* ```ts
|
|
129
|
+
* import { cartesianToSpherical } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
130
|
+
* console.log(cartesianToSpherical({ origin: "heliocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", xAu: 0, yAu: 1, zAu: 0 }));
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export declare function cartesianToSpherical(value: CartesianAu): SphericalAu;
|
|
134
|
+
/** Mean obliquity in degrees: IAU 1980 (Meeus 22.2), evaluated in TT. Validated for 1800–2050; extrapolates outside it.
|
|
135
|
+
* @param when - Date or Unix UTC milliseconds.
|
|
136
|
+
* @returns Mean obliquity in degrees.
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* import { meanObliquity } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
140
|
+
* console.log(meanObliquity(new Date("2000-01-01T12:00:00Z")));
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
export declare function meanObliquity(when: Date | number): number;
|
|
144
|
+
/** Rotate a mean ecliptic direction into the matching mean equatorial frame. No precession between epochs, nutation, aberration or light-time is added.
|
|
145
|
+
* @param value - Coordinates with explicit origin, frame, epoch and geometric corrections.
|
|
146
|
+
* @returns Right ascension and declination in the matching mean equatorial frame.
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* import { eclipticToEquatorial } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
150
|
+
* console.log(eclipticToEquatorial({ origin: "geocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", eclipticLongitude: 90, eclipticLatitude: 0 }));
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
export declare function eclipticToEquatorial(value: EclipticCoordinates): EquatorialCoordinates;
|
|
154
|
+
/** Inverse mean-equator rotation, retaining the same origin and epoch.
|
|
155
|
+
* @param value - Coordinates with explicit origin, frame, epoch and geometric corrections.
|
|
156
|
+
* @returns Ecliptic longitude and latitude in the matching mean ecliptic frame.
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* import { equatorialToEcliptic } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
160
|
+
* console.log(equatorialToEcliptic({ origin: "geocentric", frame: "equatorialJ2000", epoch: "J2000", corrections: "geometric", rightAscension: 90, declination: 0 }));
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export declare function equatorialToEcliptic(value: EquatorialCoordinates): EclipticCoordinates;
|
|
164
|
+
/** 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.
|
|
165
|
+
* @param value - Mean equatorial-of-date direction with explicit origin and epoch.
|
|
166
|
+
* @param when - Date or Unix UTC milliseconds equal to the input epoch.
|
|
167
|
+
* @param options - Observer in degrees north/east; height in metres above mean sea level.
|
|
168
|
+
* @returns Altitude and north-based azimuth in degrees; original origin preserved.
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* import { equatorialToHorizontal } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
172
|
+
* console.log(equatorialToHorizontal({ origin: "topocentric", frame: "equatorialOfDate", epoch: 0, corrections: "geometric", rightAscension: 0, declination: 0 }, 0, { observer: { latitude: 49, longitude: -123 } }));
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
export declare function equatorialToHorizontal(value: EquatorialCoordinates, when: Date | number, options: {
|
|
176
|
+
observer: CoordinateObserver;
|
|
177
|
+
}): HorizontalCoordinates;
|
|
@@ -0,0 +1,169 @@
|
|
|
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
|
+
const RAD = Math.PI / 180;
|
|
5
|
+
const J2000 = 2451545;
|
|
6
|
+
const DAY_MS = 86400000;
|
|
7
|
+
function finite(name, value) {
|
|
8
|
+
if (typeof value !== "number" || !Number.isFinite(value))
|
|
9
|
+
throw new RangeError(`${name}: ${String(value)} must be finite`);
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
function bounded(name, value, low, high) {
|
|
13
|
+
finite(name, value);
|
|
14
|
+
if (value < low || value > high)
|
|
15
|
+
throw new RangeError(`${name}: ${value} must be in [${low}, ${high}]`);
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
function wrap(value) { return ((value % 360) + 360) % 360; }
|
|
19
|
+
function instant(when) {
|
|
20
|
+
const ms = finite("when", when instanceof Date ? when.getTime() : when);
|
|
21
|
+
if (Math.abs(ms) > 8640000000000000)
|
|
22
|
+
throw new RangeError(`when: ${ms} is outside the Date range`);
|
|
23
|
+
return ms;
|
|
24
|
+
}
|
|
25
|
+
function context(c) {
|
|
26
|
+
if (!["heliocentric", "geocentric", "topocentric"].includes(c.origin))
|
|
27
|
+
throw new RangeError(`origin: ${c.origin}`);
|
|
28
|
+
if (!["eclipticJ2000", "equatorialJ2000", "eclipticOfDate", "equatorialOfDate"].includes(c.frame))
|
|
29
|
+
throw new RangeError(`frame: ${c.frame}`);
|
|
30
|
+
if (c.corrections !== "geometric")
|
|
31
|
+
throw new RangeError(`corrections: ${c.corrections}; expected geometric`);
|
|
32
|
+
if (c.frame.endsWith("J2000")) {
|
|
33
|
+
if (c.epoch !== "J2000")
|
|
34
|
+
throw new RangeError(`epoch: ${c.epoch}; expected J2000`);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (typeof c.epoch !== "number")
|
|
38
|
+
throw new RangeError(`epoch: ${c.epoch}; expected Unix milliseconds`);
|
|
39
|
+
instant(c.epoch);
|
|
40
|
+
}
|
|
41
|
+
return { origin: c.origin, frame: c.frame, epoch: c.epoch, corrections: c.corrections };
|
|
42
|
+
}
|
|
43
|
+
function spherical(longitude, latitude) {
|
|
44
|
+
const l = wrap(finite("longitude", longitude)) * RAD;
|
|
45
|
+
const b = bounded("latitude", latitude, -90, 90) * RAD;
|
|
46
|
+
const cb = Math.abs(latitude) === 90 ? 0 : Math.cos(b);
|
|
47
|
+
return [cb * Math.cos(l), cb * Math.sin(l), Math.sin(b)];
|
|
48
|
+
}
|
|
49
|
+
function angles(x, y, z) {
|
|
50
|
+
const xy = Math.hypot(x, y);
|
|
51
|
+
return [xy < 1e-15 * Math.hypot(x, y, z) ? 0 : wrap(Math.atan2(y, x) / RAD), Math.atan2(z, xy) / RAD];
|
|
52
|
+
}
|
|
53
|
+
/** Convert spherical to Cartesian, preserving origin, frame, epoch and geometric corrections. Radius must be positive.
|
|
54
|
+
* @param value - Coordinates with explicit origin, frame, epoch and geometric corrections.
|
|
55
|
+
* @returns Cartesian components in AU with the same context.
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* import { sphericalToCartesian } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
59
|
+
* console.log(sphericalToCartesian({ origin: "heliocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", longitude: 90, latitude: 0, distanceAu: 1 }));
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export function sphericalToCartesian(value) {
|
|
63
|
+
const c = context(value);
|
|
64
|
+
const d = finite("distanceAu", value.distanceAu);
|
|
65
|
+
if (d <= 0)
|
|
66
|
+
throw new RangeError(`distanceAu: ${d} must be positive`);
|
|
67
|
+
const [x, y, z] = spherical(value.longitude, value.latitude);
|
|
68
|
+
return { ...c, xAu: x * d, yAu: y * d, zAu: z * d };
|
|
69
|
+
}
|
|
70
|
+
/** Convert Cartesian to spherical. Zero vectors throw; longitude at either pole is conventionally zero.
|
|
71
|
+
* @param value - Coordinates with explicit origin, frame, epoch and geometric corrections.
|
|
72
|
+
* @returns Spherical angles in degrees and radius in AU with the same context.
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* import { cartesianToSpherical } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
76
|
+
* console.log(cartesianToSpherical({ origin: "heliocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", xAu: 0, yAu: 1, zAu: 0 }));
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export function cartesianToSpherical(value) {
|
|
80
|
+
const c = context(value);
|
|
81
|
+
const x = finite("xAu", value.xAu), y = finite("yAu", value.yAu), z = finite("zAu", value.zAu);
|
|
82
|
+
const d = finite("distanceAu", Math.hypot(x, y, z));
|
|
83
|
+
if (d === 0)
|
|
84
|
+
throw new RangeError("distanceAu: 0 has no direction");
|
|
85
|
+
const [longitude, latitude] = angles(x / d, y / d, z / d);
|
|
86
|
+
return { ...c, longitude, latitude, distanceAu: d };
|
|
87
|
+
}
|
|
88
|
+
/** Mean obliquity in degrees: IAU 1980 (Meeus 22.2), evaluated in TT. Validated for 1800–2050; extrapolates outside it.
|
|
89
|
+
* @param when - Date or Unix UTC milliseconds.
|
|
90
|
+
* @returns Mean obliquity in degrees.
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* import { meanObliquity } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
94
|
+
* console.log(meanObliquity(new Date("2000-01-01T12:00:00Z")));
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export function meanObliquity(when) {
|
|
98
|
+
const utc = instant(when);
|
|
99
|
+
const t = ((utc + ttMinusUtc(utc) * 1000) / DAY_MS + 2440587.5 - J2000) / 36525;
|
|
100
|
+
return (84381.448 - 46.815 * t - 0.00059 * t * t + 0.001813 * t * t * t) / 3600;
|
|
101
|
+
}
|
|
102
|
+
function obliquity(c) {
|
|
103
|
+
return (c.epoch === "J2000" ? 84381.448 / 3600 : meanObliquity(c.epoch)) * RAD;
|
|
104
|
+
}
|
|
105
|
+
/** Rotate a mean ecliptic direction into the matching mean equatorial frame. No precession between epochs, nutation, aberration or light-time is added.
|
|
106
|
+
* @param value - Coordinates with explicit origin, frame, epoch and geometric corrections.
|
|
107
|
+
* @returns Right ascension and declination in the matching mean equatorial frame.
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* import { eclipticToEquatorial } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
111
|
+
* console.log(eclipticToEquatorial({ origin: "geocentric", frame: "eclipticJ2000", epoch: "J2000", corrections: "geometric", eclipticLongitude: 90, eclipticLatitude: 0 }));
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export function eclipticToEquatorial(value) {
|
|
115
|
+
const c = context(value);
|
|
116
|
+
if (!c.frame.startsWith("ecliptic"))
|
|
117
|
+
throw new RangeError(`frame: ${c.frame}; expected ecliptic`);
|
|
118
|
+
const [x, y, z] = spherical(value.eclipticLongitude, value.eclipticLatitude);
|
|
119
|
+
const e = obliquity(c);
|
|
120
|
+
const [rightAscension, declination] = angles(x, y * Math.cos(e) - z * Math.sin(e), y * Math.sin(e) + z * Math.cos(e));
|
|
121
|
+
return { ...c, frame: c.frame === "eclipticJ2000" ? "equatorialJ2000" : "equatorialOfDate", rightAscension, declination };
|
|
122
|
+
}
|
|
123
|
+
/** Inverse mean-equator rotation, retaining the same origin and epoch.
|
|
124
|
+
* @param value - Coordinates with explicit origin, frame, epoch and geometric corrections.
|
|
125
|
+
* @returns Ecliptic longitude and latitude in the matching mean ecliptic frame.
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* import { equatorialToEcliptic } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
129
|
+
* console.log(equatorialToEcliptic({ origin: "geocentric", frame: "equatorialJ2000", epoch: "J2000", corrections: "geometric", rightAscension: 90, declination: 0 }));
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export function equatorialToEcliptic(value) {
|
|
133
|
+
const c = context(value);
|
|
134
|
+
if (!c.frame.startsWith("equatorial"))
|
|
135
|
+
throw new RangeError(`frame: ${c.frame}; expected equatorial`);
|
|
136
|
+
const [x, y, z] = spherical(value.rightAscension, value.declination);
|
|
137
|
+
const e = obliquity(c);
|
|
138
|
+
const [eclipticLongitude, eclipticLatitude] = angles(x, y * Math.cos(e) + z * Math.sin(e), -y * Math.sin(e) + z * Math.cos(e));
|
|
139
|
+
return { ...c, frame: c.frame === "equatorialJ2000" ? "eclipticJ2000" : "eclipticOfDate", eclipticLongitude, eclipticLatitude };
|
|
140
|
+
}
|
|
141
|
+
/** 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.
|
|
142
|
+
* @param value - Mean equatorial-of-date direction with explicit origin and epoch.
|
|
143
|
+
* @param when - Date or Unix UTC milliseconds equal to the input epoch.
|
|
144
|
+
* @param options - Observer in degrees north/east; height in metres above mean sea level.
|
|
145
|
+
* @returns Altitude and north-based azimuth in degrees; original origin preserved.
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* import { equatorialToHorizontal } from "@johnmorrisdotca/wakusei-planets/coordinates";
|
|
149
|
+
* console.log(equatorialToHorizontal({ origin: "topocentric", frame: "equatorialOfDate", epoch: 0, corrections: "geometric", rightAscension: 0, declination: 0 }, 0, { observer: { latitude: 49, longitude: -123 } }));
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
export function equatorialToHorizontal(value, when, options) {
|
|
153
|
+
const c = context(value), ms = instant(when);
|
|
154
|
+
if (c.frame !== "equatorialOfDate" || c.epoch !== ms)
|
|
155
|
+
throw new RangeError(`frame/epoch: ${c.frame}/${c.epoch}; expected equatorialOfDate at when ${ms}`);
|
|
156
|
+
const observer = options.observer;
|
|
157
|
+
const p = bounded("observer.latitude", observer.latitude, -90, 90) * RAD;
|
|
158
|
+
const l = bounded("observer.longitude", observer.longitude, -180, 180);
|
|
159
|
+
finite("observer.heightM", observer.heightM ?? 0);
|
|
160
|
+
const ra = wrap(finite("rightAscension", value.rightAscension));
|
|
161
|
+
const d = bounded("declination", value.declination, -90, 90) * RAD;
|
|
162
|
+
const days = ms / DAY_MS + 2440587.5 - J2000, t = days / 36525;
|
|
163
|
+
const h = wrap(280.46061837 + 360.98564736629 * days + 0.000387933 * t * t - t * t * t / 38710000 + l - ra) * RAD;
|
|
164
|
+
const east = -Math.cos(d) * Math.sin(h);
|
|
165
|
+
const north = Math.sin(d) * Math.cos(p) - Math.cos(d) * Math.cos(h) * Math.sin(p);
|
|
166
|
+
const up = Math.sin(d) * Math.sin(p) + Math.cos(d) * Math.cos(h) * Math.cos(p);
|
|
167
|
+
const horizontal = Math.hypot(east, north);
|
|
168
|
+
return { origin: c.origin, frame: "horizontal", epoch: ms, corrections: "geometric", altitude: Math.atan2(up, horizontal) / RAD, azimuth: horizontal < 1e-15 ? 0 : wrap(Math.atan2(east, north) / RAD) };
|
|
169
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The main problem: coordinate (0 longitude, 1 latitude, 2 distance), amplitude, then the multipliers of D, l', l and F. A distance term is a cosine, which the evaluator makes a sine a quarter turn on. */
|
|
2
|
+
export declare const LUNAR_MAIN: readonly (readonly number[])[];
|
|
3
|
+
/** The perturbations: coordinate, the power of time the amplitude is multiplied by, amplitude, phase in degrees, then the multipliers of D, l', l, F, zeta (the Moon's mean longitude with the precession) and the eight planets' mean longitudes (the Earth's is the third). */
|
|
4
|
+
export declare const LUNAR_PERIODIC: readonly (readonly number[])[];
|