UNPKG

3.15 kBJavaScriptView Raw
1function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2
3/**
4 * @copyright 2013 Sonia Keys
5 * @copyright 2016 commenthol
6 * @license MIT
7 * @module nearparabolic
8 */
9/**
10 * Nearparabolic: Chapter 35, Near-parabolic Motion.
11 */
12import base from './base';
13
14/**
15 * Elements holds orbital elements for near-parabolic orbits.
16 */
17export var Elements = function () {
18 /**
19 * @param {Number} timeP - time of Perihelion, T
20 * @param {Number} pDis - Perihelion distance, q
21 * @param {Number} ecc - eccentricity, e
22 */
23 function Elements(timeP, pDis, ecc) {
24 _classCallCheck(this, Elements);
25
26 this.timeP = timeP;
27 this.pDis = pDis;
28 this.ecc = ecc;
29 }
30
31 /**
32 * AnomalyDistance returns true anomaly and distance for near-parabolic orbits.
33 *
34 * True anomaly ν returned in radians. Distance r returned in AU.
35 * An error is returned if the algorithm fails to converge.
36 */
37
38
39 Elements.prototype.anomalyDistance = function anomalyDistance(jde) {
40 // fairly literal translation of code on p. 246
41 var q1 = base.K * Math.sqrt((1 + this.ecc) / this.pDis) / (2 * this.pDis); // line 20
42 var g = (1 - this.ecc) / (1 + this.ecc); // line 20
43
44 var t = jde - this.timeP; // line 22
45 if (t === 0) {
46 // line 24
47 return { ano: 0, dist: this.pDis, err: null };
48 }
49 var d1 = 1e4;
50 var d = 1e-9; // line 14
51 var q2 = q1 * t; // line 28
52 var s = 2.0 / (3 * Math.abs(q2)); // line 30
53 s = 2 / Math.tan(2 * Math.atan(Math.cbrt(Math.tan(Math.atan(s) / 2))));
54 if (t < 0) {
55 // line 34
56 s = -s;
57 }
58 if (this.ecc !== 1) {
59 // line 36
60 var l = 0; // line 38
61 for (;;) {
62 var s0 = s; // line 40
63 var z = 1.0;
64 var y = s * s;
65 var g1 = -y * s;
66 var q3 = q2 + 2 * g * s * y / 3; // line 42
67 for (;;) {
68 z += 1; // line 44
69 g1 = -g1 * g * y; // line 46
70 var z1 = (z - (z + 1) * g) / (2 * z + 1); // line 48
71 var f = z1 * g1; // line 50
72 q3 += f; // line 52
73 if (z > 50 || Math.abs(f) > d1) {
74 // line 54
75 return {
76 err: new Error('No convergence')
77 };
78 }
79 if (Math.abs(f) <= d) {
80 // line 56
81 break;
82 }
83 }
84 l++; // line 58
85 if (l > 50) {
86 return {
87 err: new Error('No convergence')
88 };
89 }
90 for (;;) {
91 var s1 = s; // line 60
92 s = (2 * s * s * s / 3 + q3) / (s * s + 1);
93 if (Math.abs(s - s1) <= d) {
94 // line 62
95 break;
96 }
97 }
98 if (Math.abs(s - s0) <= d) {
99 // line 64
100 break;
101 }
102 }
103 }
104 var ν = 2 * Math.atan(s); // line 66
105 var r = this.pDis * (1 + this.ecc) / (1 + this.ecc * Math.cos(ν)); // line 68
106 if (ν < 0) {
107 // line 70
108 ν += 2 * Math.PI;
109 }
110 return {
111 ano: ν,
112 dist: r,
113 err: null
114 };
115 };
116
117 return Elements;
118}();
119
120export default {
121 Elements: Elements
122};
\No newline at end of file