UNPKG

17.4 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.galactic0Lon1950 = exports.galacticLon0 = exports.galacticNorth1950 = exports.galacticNorth = exports.Galactic = exports.Horizontal = exports.Equatorial = exports.Ecliptic = 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
10var _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; };
11
12var _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; }; }(); /**
13 * @copyright 2013 Sonia Keys
14 * @copyright 2016 commenthol
15 * @license MIT
16 * @module coord
17 */
18/**
19 * Coord: Chapter 13, Transformation of Coordinates.
20 *
21 * Transforms in this package are provided in two forms, function and method.
22 * The results of the two forms should be identical.
23 *
24 * The function forms pass all arguments and results as single values. These
25 * forms are best used when you are transforming a single pair of coordinates
26 * and wish to avoid memory allocation.
27 *
28 * The method forms take and return pointers to structs. These forms are best
29 * used when you are transforming multiple coordinates and can reuse one or
30 * more of the structs. In this case reuse of structs will minimize
31 * allocations, and the struct pointers will pass more efficiently on the
32 * stack. These methods transform their arguments, placing the result in
33 * the receiver. The receiver is then returned for convenience.
34 *
35 * A number of the functions take sine and cosine of the obliquity of the
36 * ecliptic. This becomes an advantage when you doing multiple transformations
37 * with the same obliquity. The efficiency of computing sine and cosine once
38 * and reuse these values far outweighs the overhead of passing one number as
39 * opposed to two.
40 */
41
42var _base = require('./base');
43
44var _base2 = _interopRequireDefault(_base);
45
46var _sexagesimal = require('./sexagesimal');
47
48var _sexagesimal2 = _interopRequireDefault(_sexagesimal);
49
50function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
51
52function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
53
54/**
55* Ecliptic coordinates are referenced to the plane of the ecliptic.
56*/
57var Ecliptic = exports.Ecliptic = function () {
58 /**
59 * IMPORTANT: Longitudes are measured *positively* westwards
60 * e.g. Washington D.C. +77°04; Vienna -16°23'
61 * @param {Number} lon - Longitude (λ) in radians
62 * @param {Number} lat - Latitude (β) in radians
63 */
64 function Ecliptic(lon, lat) {
65 _classCallCheck(this, Ecliptic);
66
67 if ((typeof lon === 'undefined' ? 'undefined' : _typeof(lon)) === 'object') {
68 lat = lon.lat;
69 lon = lon.lon;
70 }
71 this.lon = lon || 0;
72 this.lat = lat || 0;
73 }
74
75 /**
76 * converts ecliptic coordinates to equatorial coordinates.
77 * @param {Number} ε - Obliquity
78 * @returns {Equatorial}
79 */
80
81
82 _createClass(Ecliptic, [{
83 key: 'toEquatorial',
84 value: function toEquatorial(ε) {
85 var _base$sincos = _base2.default.sincos(ε),
86 _base$sincos2 = _slicedToArray(_base$sincos, 2),
87 εsin = _base$sincos2[0],
88 εcos = _base$sincos2[1];
89
90 var _base$sincos3 = _base2.default.sincos(this.lat),
91 _base$sincos4 = _slicedToArray(_base$sincos3, 2),
92 sβ = _base$sincos4[0],
93 cβ = _base$sincos4[1];
94
95 var _base$sincos5 = _base2.default.sincos(this.lon),
96 _base$sincos6 = _slicedToArray(_base$sincos5, 2),
97 sλ = _base$sincos6[0],
98 cλ = _base$sincos6[1];
99
100 var ra = Math.atan2(sλ * εcos - sβ / cβ * εsin, cλ); // (13.3) p. 93
101 if (ra < 0) {
102 ra += 2 * Math.PI;
103 }
104 var dec = Math.asin(sβ * εcos + cβ * εsin * sλ); // (13.4) p. 93
105 return new Equatorial(ra, dec);
106 }
107 }]);
108
109 return Ecliptic;
110}();
111
112/**
113 * Equatorial coordinates are referenced to the Earth's rotational axis.
114 */
115
116
117var Equatorial = exports.Equatorial = function () {
118 /**
119 * @param {Number} ra - (float) Right ascension (α) in radians
120 * @param {Number} dec - (float) Declination (δ) in radians
121 */
122 function Equatorial() {
123 var ra = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
124 var dec = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
125
126 _classCallCheck(this, Equatorial);
127
128 this.ra = ra;
129 this.dec = dec;
130 }
131
132 /**
133 * EqToEcl converts equatorial coordinates to ecliptic coordinates.
134 * @param {Number} ε - Obliquity
135 * @returns {Ecliptic}
136 */
137
138
139 _createClass(Equatorial, [{
140 key: 'toEcliptic',
141 value: function toEcliptic(ε) {
142 var _base$sincos7 = _base2.default.sincos(ε),
143 _base$sincos8 = _slicedToArray(_base$sincos7, 2),
144 εsin = _base$sincos8[0],
145 εcos = _base$sincos8[1];
146
147 var _base$sincos9 = _base2.default.sincos(this.ra),
148 _base$sincos10 = _slicedToArray(_base$sincos9, 2),
149 sα = _base$sincos10[0],
150 cα = _base$sincos10[1];
151
152 var _base$sincos11 = _base2.default.sincos(this.dec),
153 _base$sincos12 = _slicedToArray(_base$sincos11, 2),
154 sδ = _base$sincos12[0],
155 cδ = _base$sincos12[1];
156
157 var lon = Math.atan2(sα * εcos + sδ / cδ * εsin, cα); // (13.1) p. 93
158 var lat = Math.asin(sδ * εcos - cδ * εsin * sα); // (13.2) p. 93
159 return new Ecliptic(lon, lat);
160 }
161
162 /**
163 * EqToHz computes Horizontal coordinates from equatorial coordinates.
164 *
165 * Argument g is the location of the observer on the Earth. Argument st
166 * is the sidereal time at Greenwich.
167 *
168 * Sidereal time must be consistent with the equatorial coordinates.
169 * If coordinates are apparent, sidereal time must be apparent as well.
170 *
171 * @param {Equatorial} eq - equatorial coordinates (right ascension, declination)
172 * @param {globe.Coord} g - coordinates of observer on Earth
173 * @param {Number} st - sidereal time at Greenwich at time of observation
174 * @returns {Horizontal}
175 */
176
177 }, {
178 key: 'toHorizontal',
179 value: function toHorizontal(g, st) {
180 var H = new _sexagesimal2.default.Time(st).rad() - g.lon - this.ra;
181
182 var _base$sincos13 = _base2.default.sincos(H),
183 _base$sincos14 = _slicedToArray(_base$sincos13, 2),
184 sH = _base$sincos14[0],
185 cH = _base$sincos14[1];
186
187 var _base$sincos15 = _base2.default.sincos(g.lat),
188 _base$sincos16 = _slicedToArray(_base$sincos15, 2),
189 sφ = _base$sincos16[0],
190 cφ = _base$sincos16[1];
191
192 var _base$sincos17 = _base2.default.sincos(this.dec),
193 _base$sincos18 = _slicedToArray(_base$sincos17, 2),
194 sδ = _base$sincos18[0],
195 cδ = _base$sincos18[1];
196
197 var azimuth = Math.atan2(sH, cH * sφ - sδ / cδ * cφ); // (13.5) p. 93
198 var altitude = Math.asin(sφ * sδ + cφ * cδ * cH); // (13.6) p. 93
199 return new Horizontal(azimuth, altitude);
200 }
201
202 /**
203 * EqToGal converts equatorial coordinates to galactic coordinates.
204 *
205 * Equatorial coordinates must be referred to the standard equinox of B1950.0.
206 * For conversion to B1950, see package precess and utility functions in
207 * package "common".
208 *
209 * @param {Equatorial} eq
210 * @returns {Galactic}
211 */
212
213 }, {
214 key: 'toGalactic',
215 value: function toGalactic() {
216 var _base$sincos19 = _base2.default.sincos(galacticNorth1950.ra - this.ra),
217 _base$sincos20 = _slicedToArray(_base$sincos19, 2),
218 sdα = _base$sincos20[0],
219 cdα = _base$sincos20[1];
220
221 var _base$sincos21 = _base2.default.sincos(galacticNorth1950.dec),
222 _base$sincos22 = _slicedToArray(_base$sincos21, 2),
223 sgδ = _base$sincos22[0],
224 cgδ = _base$sincos22[1];
225
226 var _base$sincos23 = _base2.default.sincos(this.dec),
227 _base$sincos24 = _slicedToArray(_base$sincos23, 2),
228 sδ = _base$sincos24[0],
229 cδ = _base$sincos24[1];
230
231 var x = Math.atan2(sdα, cdα * sgδ - sδ / cδ * cgδ); // (13.7) p. 94
232 // (galactic0Lon1950 + 1.5*math.Pi) = magic number of 303 deg
233 var lon = (galactic0Lon1950 + 1.5 * Math.PI - x) % (2 * Math.PI); // (13.8) p. 94
234 var lat = Math.asin(sδ * sgδ + cδ * cgδ * cdα);
235 return new Galactic(lon, lat);
236 }
237 }]);
238
239 return Equatorial;
240}();
241
242/**
243 * Horizontal coordinates are referenced to the local horizon of an observer
244 * on the surface of the Earth.
245 * @param {Number} az - Azimuth (A) in radians
246 * @param {Number} alt - Altitude (h) in radians
247 */
248
249
250var Horizontal = exports.Horizontal = function () {
251 function Horizontal() {
252 var az = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
253 var alt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
254
255 _classCallCheck(this, Horizontal);
256
257 this.az = az;
258 this.alt = alt;
259 }
260
261 /**
262 * transforms horizontal coordinates to equatorial coordinates.
263 *
264 * Sidereal time must be consistent with the equatorial coordinates.
265 * If coordinates are apparent, sidereal time must be apparent as well.
266 * @param {globe.Coord} g - coordinates of observer on Earth (lat, lon)
267 * @param {Number} st - sidereal time at Greenwich at time of observation.
268 * @returns {Equatorial} (right ascension, declination)
269 */
270
271
272 _createClass(Horizontal, [{
273 key: 'toEquatorial',
274 value: function toEquatorial(g, st) {
275 var _base$sincos25 = _base2.default.sincos(this.az),
276 _base$sincos26 = _slicedToArray(_base$sincos25, 2),
277 sA = _base$sincos26[0],
278 cA = _base$sincos26[1];
279
280 var _base$sincos27 = _base2.default.sincos(this.alt),
281 _base$sincos28 = _slicedToArray(_base$sincos27, 2),
282 sh = _base$sincos28[0],
283 ch = _base$sincos28[1];
284
285 var _base$sincos29 = _base2.default.sincos(g.lat),
286 _base$sincos30 = _slicedToArray(_base$sincos29, 2),
287 sφ = _base$sincos30[0],
288 cφ = _base$sincos30[1];
289
290 var H = Math.atan2(sA, cA * sφ + sh / ch * cφ);
291 var ra = _base2.default.pmod(new _sexagesimal2.default.Time(st).rad() - g.lon - H, 2 * Math.PI);
292 var dec = Math.asin(sφ * sh - cφ * ch * cA);
293 return new Equatorial(ra, dec);
294 }
295 }]);
296
297 return Horizontal;
298}();
299
300/**
301 * Galactic coordinates are referenced to the plane of the Milky Way.
302 * @param {Number} lon - Longitude (l) in radians
303 * @param {Number} lat - Latitude (b) in radians
304 */
305
306
307var Galactic = exports.Galactic = function () {
308 function Galactic() {
309 var lon = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
310 var lat = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
311
312 _classCallCheck(this, Galactic);
313
314 this.lon = lon;
315 this.lat = lat;
316 }
317
318 /**
319 * GalToEq converts galactic coordinates to equatorial coordinates.
320 *
321 * Resulting equatorial coordinates will be referred to the standard equinox of
322 * B1950.0. For subsequent conversion to other epochs, see package precess and
323 * utility functions in package meeus.
324 *
325 * @returns {Equatorial} (right ascension, declination)
326 */
327
328
329 _createClass(Galactic, [{
330 key: 'toEquatorial',
331 value: function toEquatorial() {
332 // (-galactic0Lon1950 - math.Pi/2) = magic number of -123 deg
333 var _base$sincos31 = _base2.default.sincos(this.lon - galactic0Lon1950 - Math.PI / 2),
334 _base$sincos32 = _slicedToArray(_base$sincos31, 2),
335 sdLon = _base$sincos32[0],
336 cdLon = _base$sincos32[1];
337
338 var _base$sincos33 = _base2.default.sincos(galacticNorth1950.dec),
339 _base$sincos34 = _slicedToArray(_base$sincos33, 2),
340 sgδ = _base$sincos34[0],
341 cgδ = _base$sincos34[1];
342
343 var _base$sincos35 = _base2.default.sincos(this.lat),
344 _base$sincos36 = _slicedToArray(_base$sincos35, 2),
345 sb = _base$sincos36[0],
346 cb = _base$sincos36[1];
347
348 var y = Math.atan2(sdLon, cdLon * sgδ - sb / cb * cgδ);
349 // (galacticNorth1950.RA.Rad() - math.Pi) = magic number of 12.25 deg
350 var ra = _base2.default.pmod(y + galacticNorth1950.ra - Math.PI, 2 * Math.PI);
351 var dec = Math.asin(sb * sgδ + cb * cgδ * cdLon);
352 return new Equatorial(ra, dec);
353 }
354 }]);
355
356 return Galactic;
357}();
358
359/**
360* equatorial coords for galactic north
361* IAU B1950.0 coordinates of galactic North Pole
362*/
363
364
365var galacticNorth = exports.galacticNorth = new Equatorial(new _sexagesimal2.default.RA(12, 49, 0).rad(), 27.4 * Math.PI / 180);
366var galacticNorth1950 = exports.galacticNorth1950 = galacticNorth;
367
368/**
369* Galactic Longitude 0°
370* Meeus gives 33 as the origin of galactic longitudes relative to the
371* ascending node of of the galactic equator. 33 + 90 = 123, the IAU
372* value for origin relative to the equatorial pole.
373*/
374var galacticLon0 = exports.galacticLon0 = 33 * Math.PI / 180;
375var galactic0Lon1950 = exports.galactic0Lon1950 = galacticLon0;
376
377exports.default = {
378 Ecliptic: Ecliptic,
379 Equatorial: Equatorial,
380 Horizontal: Horizontal,
381 Galactic: Galactic,
382 galacticNorth: galacticNorth,
383 galacticNorth1950: galacticNorth1950,
384 galacticLon0: galacticLon0,
385 galactic0Lon1950: galactic0Lon1950
386};
\No newline at end of file