UNPKG

8.25 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 parallactic
12 */
13/**
14 * Parallactic: Chapter 14, The Parallactic Angle, and three other Topics.
15 */
16
17exports.parallacticAngle = parallacticAngle;
18exports.parallacticAngleOnHorizon = parallacticAngleOnHorizon;
19exports.eclipticAtHorizon = eclipticAtHorizon;
20exports.eclipticAtEquator = eclipticAtEquator;
21exports.diurnalPathAtHorizon = diurnalPathAtHorizon;
22
23var _base = require('./base');
24
25var _base2 = _interopRequireDefault(_base);
26
27function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
28
29/**
30 * ParallacticAngle returns parallactic angle of a celestial object.
31 *
32 * φ is geographic latitude of observer.
33 * δ is declination of observed object.
34 * H is hour angle of observed object.
35 *
36 * All angles including result are in radians.
37 */
38function parallacticAngle(φ, δ, H) {
39 // (φ, δ, H float64) float64
40 var _base$sincos = _base2.default.sincos(δ),
41 _base$sincos2 = _slicedToArray(_base$sincos, 2),
42 sδ = _base$sincos2[0],
43 cδ = _base$sincos2[1];
44
45 var _base$sincos3 = _base2.default.sincos(H),
46 _base$sincos4 = _slicedToArray(_base$sincos3, 2),
47 sH = _base$sincos4[0],
48 cH = _base$sincos4[1];
49
50 return Math.atan2(sH, Math.tan(φ) * cδ - sδ * cH); // (14.1) p. 98
51}
52
53/**
54 * ParallacticAngleOnHorizon is a special case of ParallacticAngle.
55 *
56 * The hour angle is not needed as an input and the math inside simplifies.
57 */
58function parallacticAngleOnHorizon(φ, δ) {
59 // (φ, δ float64) float64
60 return Math.acos(Math.sin(φ) / Math.cos(δ));
61}
62
63/**
64 * EclipticAtHorizon computes how the plane of the ecliptic intersects
65 * the horizon at a given local sidereal time as observed from a given
66 * geographic latitude.
67 *
68 * ε is obliquity of the ecliptic.
69 * φ is geographic latitude of observer.
70 * θ is local sidereal time expressed as an hour angle.
71 *
72 * λ1 and λ2 are ecliptic longitudes where the ecliptic intersects the horizon.
73 * I is the angle at which the ecliptic intersects the horizon.
74 *
75 * All angles, arguments and results, are in radians.
76 */
77function eclipticAtHorizon(ε, φ, θ) {
78 // (ε, φ, θ float64) (λ1, λ2, I float64)
79 var _base$sincos5 = _base2.default.sincos(ε),
80 _base$sincos6 = _slicedToArray(_base$sincos5, 2),
81 sε = _base$sincos6[0],
82 cε = _base$sincos6[1];
83
84 var _base$sincos7 = _base2.default.sincos(φ),
85 _base$sincos8 = _slicedToArray(_base$sincos7, 2),
86 sφ = _base$sincos8[0],
87 cφ = _base$sincos8[1];
88
89 var _base$sincos9 = _base2.default.sincos(θ),
90 _base$sincos10 = _slicedToArray(_base$sincos9, 2),
91 sθ = _base$sincos10[0],
92 cθ = _base$sincos10[1];
93
94 var λ = Math.atan2(-cθ, sε * (sφ / cφ) + cε * sθ); // (14.2) p. 99
95 if (λ < 0) {
96 λ += Math.PI;
97 }
98 return [λ, λ + Math.PI, Math.acos(cε * sφ - sε * cφ * sθ)]; // (14.3) p. 99
99}
100
101/**
102 * EclipticAtEquator computes the angle between the ecliptic and the parallels
103 * of ecliptic latitude at a given ecliptic longitude.
104 *
105 * (The function name EclipticAtEquator is for consistency with the Meeus text,
106 * and works if you consider the equator a nominal parallel of latitude.)
107 *
108 * λ is ecliptic longitude.
109 * ε is obliquity of the ecliptic.
110 *
111 * All angles in radians.
112 */
113function eclipticAtEquator(λ, ε) {
114 // (λ, ε float64) float64
115 return Math.atan(-Math.cos(λ) * Math.tan(ε));
116}
117
118/**
119 * DiurnalPathAtHorizon computes the angle of the path a celestial object
120 * relative to the horizon at the time of its rising or setting.
121 *
122 * δ is declination of the object.
123 * φ is geographic latitude of observer.
124 *
125 * All angles in radians.
126 */
127function diurnalPathAtHorizon(δ, φ) {
128 // (δ, φ float64) (J float64)
129 var tφ = Math.tan(φ);
130 var b = Math.tan(δ) * tφ;
131 var c = Math.sqrt(1 - b * b);
132 return Math.atan(c * Math.cos(δ) / tφ);
133}
134
135exports.default = {
136 parallacticAngle: parallacticAngle,
137 parallacticAngleOnHorizon: parallacticAngleOnHorizon,
138 eclipticAtHorizon: eclipticAtHorizon,
139 eclipticAtEquator: eclipticAtEquator,
140 diurnalPathAtHorizon: diurnalPathAtHorizon
141};
\No newline at end of file