UNPKG

15.2 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _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"); } }; }(); /**
8 * @copyright 2013 Sonia Keys
9 * @copyright 2016 commenthol
10 * @license MIT
11 * @module solar
12 */
13/**
14 * Solar: Chapter 25, Solar Coordinates.
15 *
16 * Partial implementation:
17 *
18 * 1. Higher accuracy positions are not computed with Appendix III but with
19 * full VSOP87 as implemented in package planetposition.
20 *
21 * 2. Higher accuracy correction for aberration (using the formula for
22 * variation Δλ on p. 168) is not implemented. Results for example 25.b
23 * already match the full VSOP87 values on p. 165 even with the low accuracy
24 * correction for aberration, thus there are no more significant digits that
25 * would check a more accurate result. Also the size of the formula presents
26 * significant chance of typographical error.
27 */
28
29exports.trueLongitude = trueLongitude;
30exports.meanAnomaly = meanAnomaly;
31exports.eccentricity = eccentricity;
32exports.radius = radius;
33exports.apparentLongitude = apparentLongitude;
34exports.true2000 = true2000;
35exports.trueEquatorial = trueEquatorial;
36exports.apparentEquatorial = apparentEquatorial;
37exports.trueVSOP87 = trueVSOP87;
38exports.apparentVSOP87 = apparentVSOP87;
39exports.apparentEquatorialVSOP87 = apparentEquatorialVSOP87;
40exports.aberration = aberration;
41
42var _base = require('./base');
43
44var _base2 = _interopRequireDefault(_base);
45
46var _coord = require('./coord');
47
48var _coord2 = _interopRequireDefault(_coord);
49
50var _nutation = require('./nutation');
51
52var _nutation2 = _interopRequireDefault(_nutation);
53
54function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
55
56/**
57 * True returns true geometric longitude and anomaly of the sun referenced to the mean equinox of date.
58 *
59 * @param {Number} T - number of Julian centuries since J2000. See base.J2000Century.
60 * @returns {Object}
61 * {Number} lon = true geometric longitude, ☉, in radians
62 * {Number} ano = true anomaly in radians
63 */
64function trueLongitude(T) {
65 // (25.2) p. 163
66 var L0 = _base2.default.horner(T, 280.46646, 36000.76983, 0.0003032) * Math.PI / 180;
67 var m = meanAnomaly(T);
68 var C = (_base2.default.horner(T, 1.914602, -0.004817, -0.000014) * Math.sin(m) + (0.019993 - 0.000101 * T) * Math.sin(2 * m) + 0.000289 * Math.sin(3 * m)) * Math.PI / 180;
69 var lon = _base2.default.pmod(L0 + C, 2 * Math.PI);
70 var ano = _base2.default.pmod(m + C, 2 * Math.PI);
71 return { lon: lon, ano: ano };
72}
73
74/**
75 * meanAnomaly returns the mean anomaly of Earth at the given T.
76 *
77 * @param {Number} T - number of Julian centuries since J2000. See base.J2000Century.
78 * @returns {Number} Result is in radians and is not normalized to the range 0..2π.
79 */
80function meanAnomaly(T) {
81 // (25.3) p. 163
82 return _base2.default.horner(T, 357.52911, 35999.05029, -0.0001537) * Math.PI / 180;
83}
84
85/**
86 * eccentricity returns eccentricity of the Earth's orbit around the sun.
87 *
88 * @param {Number} T - number of Julian centuries since J2000. See base.J2000Century.
89 * @returns {Number} eccentricity of the Earth's orbit around the sun.
90 */
91function eccentricity(T) {
92 // (25.4) p. 163
93 return _base2.default.horner(T, 0.016708634, -0.000042037, -0.0000001267);
94}
95
96/**
97 * Radius returns the Sun-Earth distance in AU.
98 *
99 * @param {Number} T - number of Julian centuries since J2000. See base.J2000Century.
100 * @returns {Number} Sun-Earth distance in AU
101 */
102function radius(T) {
103 var _trueLongitude = trueLongitude(T),
104 lon = _trueLongitude.lon,
105 ano = _trueLongitude.ano; // eslint-disable-line
106
107
108 var e = eccentricity(T);
109 // (25.5) p. 164
110 return 1.000001018 * (1 - e * e) / (1 + e * Math.cos(ano));
111}
112
113/**
114 * ApparentLongitude returns apparent longitude of the Sun referenced to the true equinox of date.
115 * Result includes correction for nutation and aberration. Unit is radians.
116 *
117 * @param {Number} T - number of Julian centuries since J2000. See base.J2000Century.
118 * @returns {Number} apparent longitude of the Sun referenced to the true equinox of date.
119 */
120function apparentLongitude(T) {
121 var Ω = node(T);
122
123 var _trueLongitude2 = trueLongitude(T),
124 lon = _trueLongitude2.lon,
125 ano = _trueLongitude2.ano; // eslint-disable-line
126
127
128 return lon - 0.00569 * Math.PI / 180 - 0.00478 * Math.PI / 180 * Math.sin(Ω);
129}
130
131/**
132 * @private
133 */
134function node(T) {
135 return 125.04 * Math.PI / 180 - 1934.136 * Math.PI / 180 * T;
136}
137
138/**
139 * true2000 returns true geometric longitude and anomaly of the sun referenced to equinox J2000.
140 * Results are accurate to .01 degree for years 1900 to 2100.
141 *
142 * @param {Number} T - number of Julian centuries since J2000. See base.J2000Century.
143 * @returns {Object}
144 * {Number} lon - true geometric longitude, ☉, in radians
145 * {Number} ano - true anomaly in radians
146 */
147function true2000(T) {
148 var _trueLongitude3 = trueLongitude(T),
149 lon = _trueLongitude3.lon,
150 ano = _trueLongitude3.ano;
151
152 lon -= 0.01397 * Math.PI / 180 * T * 100;
153 return { lon: lon, ano: ano };
154}
155
156/**
157 * trueEquatorial returns the true geometric position of the Sun as equatorial coordinates.
158 *
159 * @param {Number} jde - Julian ephemeris day
160 * @returns {base.Coord}
161 * {Number} ra - right ascension in radians
162 * {Number} dec - declination in radians
163 */
164function trueEquatorial(jde) {
165 var _trueLongitude4 = trueLongitude(_base2.default.J2000Century(jde)),
166 lon = _trueLongitude4.lon,
167 ano = _trueLongitude4.ano; // eslint-disable-line
168
169
170 var ε = _nutation2.default.meanObliquity(jde);
171
172 var _base$sincos = _base2.default.sincos(lon),
173 _base$sincos2 = _slicedToArray(_base$sincos, 2),
174 ss = _base$sincos2[0],
175 cs = _base$sincos2[1];
176
177 var _base$sincos3 = _base2.default.sincos(ε),
178 _base$sincos4 = _slicedToArray(_base$sincos3, 2),
179 sε = _base$sincos4[0],
180 cε = _base$sincos4[1];
181 // (25.6, 25.7) p. 165
182
183
184 var ra = Math.atan2(cε * ss, cs);
185 var dec = sε * ss;
186 return new _base2.default.Coord(ra, dec);
187}
188
189/**
190 * apparentEquatorial returns the apparent position of the Sun as equatorial coordinates.
191 *
192 * @param {Number} jde - Julian ephemeris day
193 * @returns {base.Coord}
194 * {Number} ra - right ascension in radians
195 * {Number} dec - declination in radians
196 */
197function apparentEquatorial(jde) {
198 var T = _base2.default.J2000Century(jde);
199 var λ = apparentLongitude(T);
200 var ε = _nutation2.default.meanObliquity(jde);
201
202 var _base$sincos5 = _base2.default.sincos(λ),
203 _base$sincos6 = _slicedToArray(_base$sincos5, 2),
204 sλ = _base$sincos6[0],
205 cλ = _base$sincos6[1];
206 // (25.8) p. 165
207
208
209 var _base$sincos7 = _base2.default.sincos(ε + 0.00256 * Math.PI / 180 * Math.cos(node(T))),
210 _base$sincos8 = _slicedToArray(_base$sincos7, 2),
211 sε = _base$sincos8[0],
212 cε = _base$sincos8[1];
213
214 var ra = Math.atan2(cε * sλ, cλ);
215 var dec = Math.asin(sε * sλ);
216 return new _base2.default.Coord(ra, dec);
217}
218
219/**
220 * trueVSOP87 returns the true geometric position of the sun as ecliptic coordinates.
221 *
222 * Result computed by full VSOP87 theory. Result is at equator and equinox
223 * of date in the FK5 frame. It does not include nutation or aberration.
224 *
225 * @param {planetposition.Planet} planet
226 * @param {Number} jde - Julian ephemeris day
227 * @returns {Object}
228 * {Number} lon - ecliptic longitude in radians
229 * {Number} lat - ecliptic latitude in radians
230 * {Number} range - range in AU
231 */
232function trueVSOP87(planet, jde) {
233 var _planet$position = planet.position(jde),
234 lon = _planet$position.lon,
235 lat = _planet$position.lat,
236 range = _planet$position.range;
237
238 var s = lon + Math.PI;
239 // FK5 correction.
240 var λp = _base2.default.horner(_base2.default.J2000Century(jde), s, -1.397 * Math.PI / 180, -0.00031 * Math.PI / 180);
241
242 var _base$sincos9 = _base2.default.sincos(λp),
243 _base$sincos10 = _slicedToArray(_base$sincos9, 2),
244 sλp = _base$sincos10[0],
245 cλp = _base$sincos10[1];
246
247 var Δβ = 0.03916 / 3600 * Math.PI / 180 * (cλp - sλp);
248 // (25.9) p. 166
249 lon = _base2.default.pmod(s - 0.09033 / 3600 * Math.PI / 180, 2 * Math.PI);
250 lat = Δβ - lat;
251 return new _base2.default.Coord(lon, lat, range);
252}
253
254/**
255 * apparentVSOP87 returns the apparent position of the sun as ecliptic coordinates.
256 *
257 * Result computed by VSOP87, at equator and equinox of date in the FK5 frame,
258 * and includes effects of nutation and aberration.
259 *
260 * @param {planetposition.Planet} planet
261 * @param {Number} jde - Julian ephemeris day
262 * @returns {base.Coord}
263 * {Number} lon - ecliptic longitude in radians
264 * {Number} lat - ecliptic latitude in radians
265 * {Number} range - range in AU
266 */
267function apparentVSOP87(planet, jde) {
268 // note: see duplicated code in ApparentEquatorialVSOP87.
269 var _trueVSOP = trueVSOP87(planet, jde),
270 lon = _trueVSOP.lon,
271 lat = _trueVSOP.lat,
272 range = _trueVSOP.range;
273
274 var Δψ = _nutation2.default.nutation(jde)[0];
275 var a = aberration(range);
276 lon = lon + Δψ + a;
277 return new _base2.default.Coord(lon, lat, range);
278}
279
280/**
281 * apparentEquatorialVSOP87 returns the apparent position of the sun as equatorial coordinates.
282 *
283 * Result computed by VSOP87, at equator and equinox of date in the FK5 frame,
284 * and includes effects of nutation and aberration.
285 *
286 * @param {planetposition.Planet} planet
287 * @param {Number} jde - Julian ephemeris day
288 * @returns
289 * {Number} ra - right ascension in radians
290 * {Number} dec - declination in radians
291 * {Number} range - range in AU
292 */
293function apparentEquatorialVSOP87(planet, jde) {
294 // note: duplicate code from ApparentVSOP87 so we can keep Δε.
295 // see also duplicate code in time.E().
296 var _trueVSOP2 = trueVSOP87(planet, jde),
297 lon = _trueVSOP2.lon,
298 lat = _trueVSOP2.lat,
299 range = _trueVSOP2.range;
300
301 var _nutation$nutation = _nutation2.default.nutation(jde),
302 _nutation$nutation2 = _slicedToArray(_nutation$nutation, 2),
303 Δψ = _nutation$nutation2[0],
304 Δε = _nutation$nutation2[1];
305
306 var a = aberration(range);
307 var λ = lon + Δψ + a;
308 var ε = _nutation2.default.meanObliquity(jde) + Δε;
309
310 var _toEquatorial = new _coord2.default.Ecliptic(λ, lat).toEquatorial(ε),
311 ra = _toEquatorial.ra,
312 dec = _toEquatorial.dec;
313
314 return new _base2.default.Coord(ra, dec, range);
315}
316
317/**
318 * Low precision formula. The high precision formula is not implemented
319 * because the low precision formula already gives position results to the
320 * accuracy given on p. 165. The high precision formula represents lots
321 * of typing with associated chance of typos, and no way to test the result.
322 * @param {Number} range
323 * @returns {Number} aberation
324 */
325function aberration(range) {
326 // (25.10) p. 167
327 return -20.4898 / 3600 * Math.PI / 180 / range;
328}
329
330exports.default = {
331 trueLongitude: trueLongitude,
332 true: trueLongitude, // BACKWARDS-COMPATIBILITY
333 meanAnomaly: meanAnomaly,
334 eccentricity: eccentricity,
335 radius: radius,
336 apparentLongitude: apparentLongitude,
337 true2000: true2000,
338 trueEquatorial: trueEquatorial,
339 apparentEquatorial: apparentEquatorial,
340 trueVSOP87: trueVSOP87,
341 apparentVSOP87: apparentVSOP87,
342 apparentEquatorialVSOP87: apparentEquatorialVSOP87,
343 aberration: aberration
344};
\No newline at end of file