UNPKG

12.4 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.TYPE = undefined;
7
8var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); /**
9 * @copyright 2013 Sonia Keys
10 * @copyright 2016 commenthol
11 * @license MIT
12 * @module eclipse
13 */
14/**
15 * Eclipse: Chapter 54, Eclipses.
16 */
17
18
19exports.solar = solar;
20exports.lunar = lunar;
21
22var _base = require('./base');
23
24var _base2 = _interopRequireDefault(_base);
25
26var _moonphase = require('./moonphase');
27
28var _moonphase2 = _interopRequireDefault(_moonphase);
29
30function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
32/**
33 * @private
34 */
35var g = function g(k, jm, c1, c2) {
36 // (k, jm, c1, c2 float64) (eclipse bool, jdeMax, γ, u, Mʹ float64)
37 var ck = 1 / 1236.85;
38 var p = Math.PI / 180;
39 var T = k * ck;
40 var F = _base2.default.horner(T, 160.7108 * p, 390.67050284 * p / ck, -0.0016118 * p, -0.00000227 * p, 0.000000011 * p);
41 if (Math.abs(Math.sin(F)) > 0.36) {
42 return; // no eclipse
43 }
44 var eclipse = true;
45 var E = _base2.default.horner(T, 1, -0.002516, -0.0000074);
46 var M = _base2.default.horner(T, 2.5534 * p, 29.1053567 * p / ck, -0.0000014 * p, -0.00000011 * p);
47 var Mʹ = _base2.default.horner(T, 201.5643 * p, 385.81693528 * p / ck, 0.0107582 * p, 0.00001238 * p, -0.000000058 * p);
48 var Ω = _base2.default.horner(T, 124.7746 * p, -1.56375588 * p / ck, 0.0020672 * p, 0.00000215 * p);
49 var sΩ = Math.sin(Ω);
50 var F1 = F - 0.02665 * p * sΩ;
51 var A1 = _base2.default.horner(T, 299.77 * p, 0.107408 * p / ck, -0.009173 * p);
52 // (54.1) p. 380
53 var jdeMax = jm + c1 * Math.sin(Mʹ) + c2 * Math.sin(M) * E + 0.0161 * Math.sin(2 * Mʹ) + -0.0097 * Math.sin(2 * F1) + 0.0073 * Math.sin(Mʹ - M) * E + -0.005 * Math.sin(Mʹ + M) * E + -0.0023 * Math.sin(Mʹ - 2 * F1) + 0.0021 * Math.sin(2 * M) * E + 0.0012 * Math.sin(Mʹ + 2 * F1) + 0.0006 * Math.sin(2 * Mʹ + M) * E + -0.0004 * Math.sin(3 * Mʹ) + -0.0003 * Math.sin(M + 2 * F1) * E + 0.0003 * Math.sin(A1) + -0.0002 * Math.sin(M - 2 * F1) * E + -0.0002 * Math.sin(2 * Mʹ - M) * E + -0.0002 * sΩ;
54 var P = 0.207 * Math.sin(M) * E + 0.0024 * Math.sin(2 * M) * E + -0.0392 * Math.sin(Mʹ) + 0.0116 * Math.sin(2 * Mʹ) + -0.0073 * Math.sin(Mʹ + M) * E + 0.0067 * Math.sin(Mʹ - M) * E + 0.0118 * Math.sin(2 * F1);
55 var Q = 5.2207 + -0.0048 * Math.cos(M) * E + 0.002 * Math.cos(2 * M) * E + -0.3299 * Math.cos(Mʹ) + -0.006 * Math.cos(Mʹ + M) * E + 0.0041 * Math.cos(Mʹ - M) * E;
56
57 var _base$sincos = _base2.default.sincos(F1),
58 _base$sincos2 = _slicedToArray(_base$sincos, 2),
59 sF1 = _base$sincos2[0],
60 cF1 = _base$sincos2[1];
61
62 var W = Math.abs(cF1);
63 var γ = (P * cF1 + Q * sF1) * (1 - 0.0048 * W);
64 var u = 0.0059 + 0.0046 * Math.cos(M) * E + -0.0182 * Math.cos(Mʹ) + 0.0004 * Math.cos(2 * Mʹ) + -0.0005 * Math.cos(M + Mʹ);
65 return [eclipse, jdeMax, γ, u, Mʹ]; // (eclipse bool, jdeMax, γ, u, Mʹ float64)
66};
67
68/**
69 * Eclipse type identifiers returned from Solar and Lunar.
70 */
71var TYPE = exports.TYPE = {
72 None: 0,
73 Partial: 1, // for solar eclipses
74 Annular: 2, // solar
75 AnnularTotal: 3, // solar
76 Penumbral: 4, // for lunar eclipses
77 Umbral: 5, // lunar
78 Total: 6 // solar or lunar
79
80
81 /**
82 * Snap returns k at specified quarter q nearest year y.
83 * Cut and paste from moonphase. Time corresponding to k needed in these
84 * algorithms but otherwise not meaningful enough to export from moonphase.
85 */
86};var snap = function snap(y, q) {
87 // (y, q float64) float64
88 var k = (y - 2000) * 12.3685; // (49.2) p. 350
89 return Math.floor(k - q + 0.5) + q;
90};
91
92/**
93 * Solar computes quantities related to solar eclipses.
94 *
95 * Argument year is a decimal year specifying a date.
96 *
97 * eclipseType will be None, Partial, Annular, AnnularTotal, or Total.
98 * If None, none of the other return values may be meaningful.
99 *
100 * central is true if the center of the eclipse shadow touches the Earth.
101 *
102 * jdeMax is the jde when the center of the eclipse shadow is closest to the
103 * Earth center, in a plane through the center of the Earth.
104 *
105 * γ is the distance from the eclipse shadow center to the Earth center
106 * at time jdeMax.
107 *
108 * u is the radius of the Moon's umbral cone in the plane of the Earth.
109 *
110 * p is the radius of the penumbral cone.
111 *
112 * mag is eclipse magnitude for partial eclipses. It is not valid for other
113 * eclipse types.
114 *
115 * γ, u, and p are in units of equatorial Earth radii.
116 */
117function solar(year) {
118 // (year float64) (eclipseType int, central bool, jdeMax, γ, u, p, mag float64)
119 var eclipseType = TYPE.None;
120 var mag = void 0;
121
122 var _g = g(snap(year, 0), _moonphase2.default.meanNew(year), -0.4075, 0.1721),
123 _g2 = _slicedToArray(_g, 5),
124 e = _g2[0],
125 jdeMax = _g2[1],
126 γ = _g2[2],
127 u = _g2[3],
128 _ = _g2[4]; // eslint-disable-line no-unused-vars
129
130 var p = u + 0.5461;
131 if (!e) {
132 return { type: eclipseType // no eclipse
133 };
134 }
135 var aγ = Math.abs(γ);
136 if (aγ > 1.5433 + u) {
137 return { type: eclipseType // no eclipse
138 };
139 }
140 var central = aγ < 0.9972; // eclipse center touches Earth
141
142 if (!central) {
143 eclipseType = TYPE.Partial; // most common case
144 if (aγ < 1.026) {
145 // umbral cone may touch earth
146 if (aγ < 0.9972 + Math.abs(u)) {
147 // total or annular
148 eclipseType = TYPE.Total; // report total in both cases
149 }
150 }
151 } else if (u < 0) {
152 eclipseType = TYPE.Total;
153 } else if (u > 0.0047) {
154 eclipseType = TYPE.Annular;
155 } else {
156 var ω = 0.00464 * Math.sqrt(1 - γ * γ);
157 if (u < ω) {
158 eclipseType = TYPE.AnnularTotal;
159 } else {
160 eclipseType = TYPE.Annular;
161 }
162 }
163
164 if (eclipseType === TYPE.Partial) {
165 // (54.2) p. 382
166 mag = (1.5433 + u - aγ) / (0.5461 + 2 * u);
167 }
168
169 return {
170 type: eclipseType,
171 central: central,
172 jdeMax: jdeMax,
173 magnitude: mag,
174 distance: γ,
175 umbral: u,
176 penumbral: p
177 };
178}
179
180/**
181 * Lunar computes quantities related to lunar eclipses.
182 *
183 * Argument year is a decimal year specifying a date.
184 *
185 * eclipseType will be None, Penumbral, Umbral, or Total.
186 * If None, none of the other return values may be meaningful.
187 *
188 * jdeMax is the jde when the center of the eclipse shadow is closest to the
189 * Moon center, in a plane through the center of the Moon.
190 *
191 * γ is the distance from the eclipse shadow center to the moon center
192 * at time jdeMax.
193 *
194 * σ is the radius of the umbral cone in the plane of the Moon.
195 *
196 * ρ is the radius of the penumbral cone.
197 *
198 * mag is eclipse magnitude.
199 *
200 * sd- return values are semidurations of the phases of the eclipse, in days.
201 *
202 * γ, σ, and ρ are in units of equatorial Earth radii.
203 */
204function lunar(year) {
205 // (year float64) (eclipseType int, jdeMax, γ, ρ, σ, mag, sdTotal, sdPartial, sdPenumbral float64)
206 var eclipseType = TYPE.None;
207 var mag = void 0;
208 var sdTotal = void 0;
209 var sdPartial = void 0;
210 var sdPenumbral = void 0;
211
212 var _g3 = g(snap(year, 0.5), _moonphase2.default.meanFull(year), -0.4065, 0.1727),
213 _g4 = _slicedToArray(_g3, 5),
214 e = _g4[0],
215 jdeMax = _g4[1],
216 γ = _g4[2],
217 u = _g4[3],
218 Mʹ = _g4[4];
219
220 if (!e) {
221 return { type: eclipseType // no eclipse
222 };
223 }
224 var ρ = 1.2848 + u;
225 var σ = 0.7403 - u;
226 var aγ = Math.abs(γ);
227 mag = (1.0128 - u - aγ) / 0.545; // (54.3) p. 382
228
229 if (mag > 1) {
230 eclipseType = TYPE.Total;
231 } else if (mag > 0) {
232 eclipseType = TYPE.Umbral;
233 } else {
234 mag = (1.5573 + u - aγ) / 0.545; // (54.4) p. 382
235 if (mag < 0) {
236 return; // no eclipse
237 }
238 eclipseType = TYPE.Penumbral;
239 }
240
241 var p = 1.0128 - u;
242 var t = 0.4678 - u;
243 var n = 0.5458 + 0.04 * Math.cos(Mʹ);
244 var γ2 = γ * γ;
245
246 /* eslint-disable no-fallthrough */
247 switch (eclipseType) {
248 case TYPE.Total:
249 {
250 sdTotal = Math.sqrt(t * t - γ2) / n / 24;
251 }
252 case TYPE.Umbral:
253 {
254 sdPartial = Math.sqrt(p * p - γ2) / n / 24;
255 }
256 default:
257 {
258 var h = 1.5573 + u;
259 sdPenumbral = Math.sqrt(h * h - γ2) / n / 24;
260 }
261 }
262 /* eslint-enable */
263
264 return {
265 type: eclipseType,
266 jdeMax: jdeMax,
267 magnitude: mag,
268 distance: γ,
269 umbral: σ,
270 penumbral: ρ,
271 sdTotal: sdTotal,
272 sdPartial: sdPartial,
273 sdPenumbral: sdPenumbral
274 };
275}
276
277exports.default = {
278 TYPE: TYPE,
279 solar: solar,
280 lunar: lunar
281};
\No newline at end of file