UNPKG

16.6 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.Elements = undefined;
7
8var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
9
10var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
11
12var _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"); } }; }(); /**
13 * @copyright 2013 Sonia Keys
14 * @copyright 2016 commenthol
15 * @license MIT
16 * @module elliptic
17 */
18/**
19 * Elliptic: Chapter 33, Elliptic Motion.
20 *
21 * Partial: Various formulas and algorithms are unimplemented for lack of
22 * examples or test cases.
23 */
24
25
26exports.position = position;
27exports.astrometricJ2000 = astrometricJ2000;
28exports.velocity = velocity;
29exports.vAphelion = vAphelion;
30exports.vPerihelion = vPerihelion;
31exports.length1 = length1;
32exports.length2 = length2;
33exports.length4 = length4;
34
35var _apparent = require('./apparent');
36
37var _apparent2 = _interopRequireDefault(_apparent);
38
39var _base = require('./base');
40
41var _base2 = _interopRequireDefault(_base);
42
43var _coord = require('./coord');
44
45var _coord2 = _interopRequireDefault(_coord);
46
47var _kepler = require('./kepler');
48
49var _kepler2 = _interopRequireDefault(_kepler);
50
51var _nutation = require('./nutation');
52
53var _nutation2 = _interopRequireDefault(_nutation);
54
55var _planetposition = require('./planetposition');
56
57var _planetposition2 = _interopRequireDefault(_planetposition);
58
59var _solarxyz = require('./solarxyz');
60
61var _solarxyz2 = _interopRequireDefault(_solarxyz);
62
63function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
64
65function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
66
67/**
68 * Position returns observed equatorial coordinates of a planet at a given time.
69 *
70 * Argument p must be a valid V87Planet object for the observed planet.
71 * Argument earth must be a valid V87Planet object for Earth.
72 *
73 * Results are right ascension and declination, α and δ in radians.
74 */
75function position(planet, earth, jde) {
76 // (p, earth *pp.V87Planet, jde float64) (α, δ float64)
77 var x = void 0;
78 var y = void 0;
79 var z = void 0;
80 var posEarth = earth.position(jde);
81 var _ref = [posEarth.lon, posEarth.lat, posEarth.range],
82 L0 = _ref[0],
83 B0 = _ref[1],
84 R0 = _ref[2];
85
86 var _base$sincos = _base2.default.sincos(B0),
87 _base$sincos2 = _slicedToArray(_base$sincos, 2),
88 sB0 = _base$sincos2[0],
89 cB0 = _base$sincos2[1];
90
91 var _base$sincos3 = _base2.default.sincos(L0),
92 _base$sincos4 = _slicedToArray(_base$sincos3, 2),
93 sL0 = _base$sincos4[0],
94 cL0 = _base$sincos4[1];
95
96 function pos() {
97 var τ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
98
99 var pos = planet.position(jde - τ);
100 var _ref2 = [pos.lon, pos.lat, pos.range],
101 L = _ref2[0],
102 B = _ref2[1],
103 R = _ref2[2];
104
105 var _base$sincos5 = _base2.default.sincos(B),
106 _base$sincos6 = _slicedToArray(_base$sincos5, 2),
107 sB = _base$sincos6[0],
108 cB = _base$sincos6[1];
109
110 var _base$sincos7 = _base2.default.sincos(L),
111 _base$sincos8 = _slicedToArray(_base$sincos7, 2),
112 sL = _base$sincos8[0],
113 cL = _base$sincos8[1];
114
115 x = R * cB * cL - R0 * cB0 * cL0;
116 y = R * cB * sL - R0 * cB0 * sL0;
117 z = R * sB - R0 * sB0;
118 }
119
120 pos();
121 var Δ = Math.sqrt(x * x + y * y + z * z); // (33.4) p. 224
122 var τ = _base2.default.lightTime(Δ);
123 // repeating with jde-τ
124 pos(τ);
125
126 var λ = Math.atan2(y, x); // (33.1) p. 223
127 var β = Math.atan2(z, Math.hypot(x, y)); // (33.2) p. 223
128
129 var _apparent$eclipticAbe = _apparent2.default.eclipticAberration(λ, β, jde),
130 _apparent$eclipticAbe2 = _slicedToArray(_apparent$eclipticAbe, 2),
131 Δλ = _apparent$eclipticAbe2[0],
132 Δβ = _apparent$eclipticAbe2[1];
133
134 var fk5 = _planetposition2.default.toFK5(λ + Δλ, β + Δβ, jde);
135 λ = fk5.lon;
136 β = fk5.lat;
137
138 var _nutation$nutation = _nutation2.default.nutation(jde),
139 _nutation$nutation2 = _slicedToArray(_nutation$nutation, 2),
140 Δψ = _nutation$nutation2[0],
141 Δε = _nutation$nutation2[1];
142
143 λ += Δψ;
144 var ε = _nutation2.default.meanObliquity(jde) + Δε;
145 return new _coord2.default.Ecliptic(λ, β).toEquatorial(ε);
146 // Meeus gives a formula for elongation but doesn't spell out how to
147 // obtaion term λ0 and doesn't give an example solution.
148}
149
150/**
151 * Elements holds keplerian elements.
152 */
153
154var Elements = exports.Elements = function () {
155 /*
156 Axis float64 // Semimajor axis, a, in AU
157 Ecc float64 // Eccentricity, e
158 Inc float64 // Inclination, i, in radians
159 ArgP float64 // Argument of perihelion, ω, in radians
160 Node float64 // Longitude of ascending node, Ω, in radians
161 TimeP float64 // Time of perihelion, T, as jde
162 */
163 function Elements(axis, ecc, inc, argP, node, timeP) {
164 _classCallCheck(this, Elements);
165
166 var o = {};
167 if ((typeof axis === 'undefined' ? 'undefined' : _typeof(axis)) === 'object') {
168 o = axis;
169 }
170 this.axis = o.axis || axis;
171 this.ecc = o.ecc || ecc;
172 this.inc = o.inc || inc;
173 this.argP = o.argP || argP;
174 this.node = o.node || node;
175 this.timeP = o.timeP || timeP;
176 }
177
178 /**
179 * Position returns observed equatorial coordinates of a body with Keplerian elements.
180 *
181 * Argument e must be a valid V87Planet object for Earth.
182 *
183 * Results are right ascension and declination α and δ, and elongation ψ,
184 * all in radians.
185 */
186
187
188 _createClass(Elements, [{
189 key: 'position',
190 value: function position(jde, earth) {
191 var _this = this;
192
193 // (α, δ, ψ float64) {
194 // (33.6) p. 227
195 var n = _base2.default.K / this.axis / Math.sqrt(this.axis);
196 var sε = _base2.default.SOblJ2000;
197 var cε = _base2.default.COblJ2000;
198
199 var _base$sincos9 = _base2.default.sincos(this.node),
200 _base$sincos10 = _slicedToArray(_base$sincos9, 2),
201 sΩ = _base$sincos10[0],
202 cΩ = _base$sincos10[1];
203
204 var _base$sincos11 = _base2.default.sincos(this.inc),
205 _base$sincos12 = _slicedToArray(_base$sincos11, 2),
206 si = _base$sincos12[0],
207 ci = _base$sincos12[1];
208 // (33.7) p. 228
209
210
211 var F = cΩ;
212 var G = sΩ * cε;
213 var H = sΩ * sε;
214 var P = -sΩ * ci;
215 var Q = cΩ * ci * cε - si * sε;
216 var R = cΩ * ci * sε + si * cε;
217 // (33.8) p. 229
218 var A = Math.atan2(F, P);
219 var B = Math.atan2(G, Q);
220 var C = Math.atan2(H, R);
221 var a = Math.hypot(F, P);
222 var b = Math.hypot(G, Q);
223 var c = Math.hypot(H, R);
224
225 var f = function f(jde) {
226 // (x, y, z float64) {
227 var M = n * (jde - _this.timeP);
228 var E = void 0;
229 try {
230 E = _kepler2.default.kepler2b(_this.ecc, M, 15);
231 } catch (e) {
232 E = _kepler2.default.kepler3(_this.ecc, M);
233 }
234 var ν = _kepler2.default.trueAnomaly(E, _this.ecc);
235 var r = _kepler2.default.radius(E, _this.ecc, _this.axis);
236 // (33.9) p. 229
237 var x = r * a * Math.sin(A + _this.argP + ν);
238 var y = r * b * Math.sin(B + _this.argP + ν);
239 var z = r * c * Math.sin(C + _this.argP + ν);
240 return { x: x, y: y, z: z };
241 };
242 return astrometricJ2000(f, jde, earth);
243 }
244 }]);
245
246 return Elements;
247}();
248
249/**
250 * AstrometricJ2000 is a utility function for computing astrometric coordinates.
251 *
252 * It is used internally and only exported so that it can be used from
253 * multiple packages. It is not otherwise expected to be used.
254 *
255 * Argument f is a function that returns J2000 equatorial rectangular
256 * coodinates of a body.
257 *
258 * Results are J2000 right ascention, declination, and elongation.
259 */
260
261
262function astrometricJ2000(f, jde, earth) {
263 // (f func(float64) (x, y, z float64), jde float64, e *pp.V87Planet) (α, δ, ψ float64)
264 var sol = _solarxyz2.default.positionJ2000(earth, jde);
265 var _ref3 = [sol.x, sol.y, sol.z],
266 X = _ref3[0],
267 Y = _ref3[1],
268 Z = _ref3[2];
269
270 var ξ = void 0;
271 var η = void 0;
272 var ζ = void 0;
273 var Δ = void 0;
274
275 function fn() {
276 var τ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
277
278 // (33.10) p. 229
279 var _f = f(jde - τ),
280 x = _f.x,
281 y = _f.y,
282 z = _f.z;
283
284 ξ = X + x;
285 η = Y + y;
286 ζ = Z + z;
287 Δ = Math.sqrt(ξ * ξ + η * η + ζ * ζ);
288 }
289
290 fn();
291 var τ = _base2.default.lightTime(Δ);
292 fn(τ);
293
294 var α = Math.atan2(η, ξ);
295 if (α < 0) {
296 α += 2 * Math.PI;
297 }
298 var δ = Math.asin(ζ / Δ);
299 var R0 = Math.sqrt(X * X + Y * Y + Z * Z);
300 var ψ = Math.acos((ξ * X + η * Y + ζ * Z) / R0 / Δ);
301 return new _base2.default.Coord(α, δ, undefined, ψ);
302}
303
304/**
305 * Velocity returns instantaneous velocity of a body in elliptical orbit around the Sun.
306 *
307 * Argument a is the semimajor axis of the body, r is the instaneous distance
308 * to the Sun, both in AU.
309 *
310 * Result is in Km/sec.
311 */
312function velocity(a, r) {
313 // (a, r float64) float64
314 return 42.1219 * Math.sqrt(1 / r - 0.5 / a);
315}
316
317/**
318 * Velocity returns the velocity of a body at aphelion.
319 *
320 * Argument a is the semimajor axis of the body in AU, e is eccentricity.
321 *
322 * Result is in Km/sec.
323 */
324function vAphelion(a, e) {
325 // (a, e float64) float64
326 return 29.7847 * Math.sqrt((1 - e) / (1 + e) / a);
327}
328
329/**
330 * Velocity returns the velocity of a body at perihelion.
331 *
332 * Argument a is the semimajor axis of the body in AU, e is eccentricity.
333 *
334 * Result is in Km/sec.
335 */
336function vPerihelion(a, e) {
337 // (a, e float64) float64
338 return 29.7847 * Math.sqrt((1 + e) / (1 - e) / a);
339}
340
341/**
342 * Length1 returns Ramanujan's approximation for the length of an elliptical
343 * orbit.
344 *
345 * Argument a is semimajor axis, e is eccentricity.
346 *
347 * Result is in units used for semimajor axis, typically AU.
348 */
349function length1(a, e) {
350 // (a, e float64) float64
351 var b = a * Math.sqrt(1 - e * e);
352 return Math.PI * (3 * (a + b) - Math.sqrt((a + 3 * b) * (3 * a + b)));
353}
354
355/**
356 * Length2 returns an alternate approximation for the length of an elliptical
357 * orbit.
358 *
359 * Argument a is semimajor axis, e is eccentricity.
360 *
361 * Result is in units used for semimajor axis, typically AU.
362 */
363function length2(a, e) {
364 // (a, e float64) float64
365 var b = a * Math.sqrt(1 - e * e);
366 var s = a + b;
367 var p = a * b;
368 var A = s * 0.5;
369 var G = Math.sqrt(p);
370 var H = 2 * p / s;
371 return Math.PI * (21 * A - 2 * G - 3 * H) * 0.125;
372}
373
374/**
375 * Length3 returns the length of an elliptical orbit.
376 *
377 * Argument a is semimajor axis, e is eccentricity.
378 *
379 * Result is exact, and in units used for semimajor axis, typically AU.
380 */
381/* As Meeus notes, Length4 converges faster. There is no reason to use
382this function
383export function length3 (a, e) { // (a, e float64) float64
384 const sum0 = 1.0
385 const e2 = e * e
386 const term = e2 * 0.25
387 const sum1 = 1.0 - term
388 const nf = 1.0
389 const df = 2.0
390 while (sum1 !== sum0) {
391 term *= nf
392 nf += 2
393 df += 2
394 term *= nf * e2 / (df * df)
395 sum0 = sum1
396 sum1 -= term
397 }
398 return 2 * Math.PI * a * sum0
399} */
400
401/**
402 * Length4 returns the length of an elliptical orbit.
403 *
404 * Argument a is semimajor axis, e is eccentricity.
405 *
406 * Result is exact, and in units used for semimajor axis, typically AU.
407 */
408function length4(a, e) {
409 // (a, e float64) float64
410 var b = a * Math.sqrt(1 - e * e);
411 var m = (a - b) / (a + b);
412 var m2 = m * m;
413 var sum0 = 1.0;
414 var term = m2 * 0.25;
415 var sum1 = 1.0 + term;
416 var nf = -1.0;
417 var df = 2.0;
418 while (sum1 !== sum0) {
419 nf += 2;
420 df += 2;
421 term *= nf * nf * m2 / (df * df);
422 sum0 = sum1;
423 sum1 += term;
424 }
425 return 2 * Math.PI * a * sum0 / (1 + m);
426}
427
428exports.default = {
429 position: position,
430 Elements: Elements,
431 astrometricJ2000: astrometricJ2000,
432 velocity: velocity,
433 vAphelion: vAphelion,
434 vPerihelion: vPerihelion,
435 length1: length1,
436 length2: length2,
437 // length3,
438 length4: length4
439};
\No newline at end of file