UNPKG

12.2 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.meanLunarMonth = undefined;
7
8var _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; }; }(); /**
9 * @copyright 2013 Sonia Keys
10 * @copyright 2016 commenthol
11 * @license MIT
12 * @module moonphase
13 */
14/**
15 * Moonphase: Chapter 49, Phases of the Moon
16 */
17
18exports.meanNew = meanNew;
19exports.meanFirst = meanFirst;
20exports.meanFull = meanFull;
21exports.meanLast = meanLast;
22exports.newMoon = newMoon;
23exports.first = first;
24exports.full = full;
25exports.last = last;
26
27var _base = require('./base');
28
29var _base2 = _interopRequireDefault(_base);
30
31function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
32
33function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
34
35var ck = 1 / 1236.85;
36
37/**
38 * mean synodial lunar month
39 */
40var meanLunarMonth = exports.meanLunarMonth = 29.530588861;
41
42// (49.1) p. 349
43function mean(T) {
44 return _base2.default.horner(T, 2451550.09766, 29.530588861 / ck, 0.00015437, -0.00000015, 0.00000000073);
45}
46
47/** snap returns k at specified quarter q nearest year y. */
48function snap(y, q) {
49 var k = (y - 2000) * 12.3685; // (49.2) p. 350
50 return Math.floor(k - q + 0.5) + q;
51}
52
53/**
54 * MeanNew returns the jde of the mean New Moon nearest the given datthis.
55 * The mean date is within 0.5 day of the true date of New Moon.
56 *
57 * @param {Number} year - decimal year
58 * @returns {Number} jde
59 */
60function meanNew(year) {
61 return mean(snap(year, 0) * ck);
62}
63
64/**
65 * MeanFirst returns the jde of the mean First Quarter Moon nearest the given datthis.
66 * The mean date is within 0.5 day of the true date of First Quarter Moon.
67 *
68 * @param {Number} year - decimal year
69 * @returns {Number} jde
70 */
71function meanFirst(year) {
72 return mean(snap(year, 0.25) * ck);
73}
74
75/**
76 * MeanFull returns the jde of the mean Full Moon nearest the given datthis.
77 * The mean date is within 0.5 day of the true date of Full Moon.
78 *
79 * @param {Number} year - decimal year
80 * @returns {Number} jde
81 */
82function meanFull(year) {
83 return mean(snap(year, 0.5) * ck);
84}
85
86/**
87 * MeanLast returns the jde of the mean Last Quarter Moon nearest the given datthis.
88 * The mean date is within 0.5 day of the true date of Last Quarter Moon.
89 *
90 * @param {Number} year - decimal year
91 * @returns {Number} jde
92 */
93function meanLast(year) {
94 return mean(snap(year, 0.75) * ck);
95}
96
97/**
98 * New returns the jde of New Moon nearest the given date.
99 *
100 * @param {Number} year - decimal year
101 * @returns {Number} jde
102 */
103function newMoon(year) {
104 var m = new Mp(year, 0);
105 return mean(m.T) + m.nfc(nc) + m.a();
106}
107
108/**
109 * First returns the jde of First Quarter Moon nearest the given datthis.
110 *
111 * @param {Number} year - decimal year
112 * @returns {Number} jde
113 */
114function first(year, month, day) {
115 var m = new Mp(year, 0.25);
116 return mean(m.T) + m.flc() + m.w() + m.a();
117}
118
119/**
120 * Full returns the jde of Full Moon nearest the given datthis.
121 *
122 * @param {Number} year - decimal year
123 * @returns {Number} jde
124 */
125function full(year, month, day) {
126 var m = new Mp(year, 0.5);
127 return mean(m.T) + m.nfc(fc) + m.a();
128}
129
130/**
131 * Last returns the jde of Last Quarter Moon nearest the given datthis.
132 *
133 * @param {Number} year - decimal year
134 * @returns {Number} jde
135 */
136function last(year, month, day) {
137 var m = new Mp(year, 0.75);
138 return mean(m.T) + m.flc() - m.w() + m.a();
139}
140
141var p = Math.PI / 180;
142
143var Mp = function () {
144 function Mp(y, q) {
145 _classCallCheck(this, Mp);
146
147 this.A = new Array(14);
148 this.k = snap(y, q);
149 this.T = this.k * ck; // (49.3) p. 350
150 this.E = _base2.default.horner(this.T, 1, -0.002516, -0.0000074);
151 this.M = _base2.default.horner(this.T, 2.5534 * p, 29.1053567 * p / ck, -0.0000014 * p, -0.00000011 * p);
152 this.M_ = _base2.default.horner(this.T, 201.5643 * p, 385.81693528 * p / ck, 0.0107582 * p, 0.00001238 * p, -0.000000058 * p);
153 this.F = _base2.default.horner(this.T, 160.7108 * p, 390.67050284 * p / ck, -0.0016118 * p, -0.00000227 * p, 0.000000011 * p);
154 this.Ω = _base2.default.horner(this.T, 124.7746 * p, -1.56375588 * p / ck, 0.0020672 * p, 0.00000215 * p);
155 this.A[0] = 299.7 * p + 0.107408 * p * this.k - 0.009173 * this.T * this.T;
156 this.A[1] = 251.88 * p + 0.016321 * p * this.k;
157 this.A[2] = 251.83 * p + 26.651886 * p * this.k;
158 this.A[3] = 349.42 * p + 36.412478 * p * this.k;
159 this.A[4] = 84.66 * p + 18.206239 * p * this.k;
160 this.A[5] = 141.74 * p + 53.303771 * p * this.k;
161 this.A[6] = 207.17 * p + 2.453732 * p * this.k;
162 this.A[7] = 154.84 * p + 7.30686 * p * this.k;
163 this.A[8] = 34.52 * p + 27.261239 * p * this.k;
164 this.A[9] = 207.19 * p + 0.121824 * p * this.k;
165 this.A[10] = 291.34 * p + 1.844379 * p * this.k;
166 this.A[11] = 161.72 * p + 24.198154 * p * this.k;
167 this.A[12] = 239.56 * p + 25.513099 * p * this.k;
168 this.A[13] = 331.55 * p + 3.592518 * p * this.k;
169 }
170
171 // new or full corrections
172
173
174 _createClass(Mp, [{
175 key: 'nfc',
176 value: function nfc(c) {
177 return c[0] * Math.sin(this.M_) + c[1] * Math.sin(this.M) * this.E + c[2] * Math.sin(2 * this.M_) + c[3] * Math.sin(2 * this.F) + c[4] * Math.sin(this.M_ - this.M) * this.E + c[5] * Math.sin(this.M_ + this.M) * this.E + c[6] * Math.sin(2 * this.M) * this.E * this.E + c[7] * Math.sin(this.M_ - 2 * this.F) + c[8] * Math.sin(this.M_ + 2 * this.F) + c[9] * Math.sin(2 * this.M_ + this.M) * this.E + c[10] * Math.sin(3 * this.M_) + c[11] * Math.sin(this.M + 2 * this.F) * this.E + c[12] * Math.sin(this.M - 2 * this.F) * this.E + c[13] * Math.sin(2 * this.M_ - this.M) * this.E + c[14] * Math.sin(this.Ω) + c[15] * Math.sin(this.M_ + 2 * this.M) + c[16] * Math.sin(2 * (this.M_ - this.F)) + c[17] * Math.sin(3 * this.M) + c[18] * Math.sin(this.M_ + this.M - 2 * this.F) + c[19] * Math.sin(2 * (this.M_ + this.F)) + c[20] * Math.sin(this.M_ + this.M + 2 * this.F) + c[21] * Math.sin(this.M_ - this.M + 2 * this.F) + c[22] * Math.sin(this.M_ - this.M - 2 * this.F) + c[23] * Math.sin(3 * this.M_ + this.M) + c[24] * Math.sin(4 * this.M_);
178 }
179
180 // first or last corrections
181
182 }, {
183 key: 'flc',
184 value: function flc() {
185 return -0.62801 * Math.sin(this.M_) + 0.17172 * Math.sin(this.M) * this.E + -0.01183 * Math.sin(this.M_ + this.M) * this.E + 0.00862 * Math.sin(2 * this.M_) + 0.00804 * Math.sin(2 * this.F) + 0.00454 * Math.sin(this.M_ - this.M) * this.E + 0.00204 * Math.sin(2 * this.M) * this.E * this.E + -0.0018 * Math.sin(this.M_ - 2 * this.F) + -0.0007 * Math.sin(this.M_ + 2 * this.F) + -0.0004 * Math.sin(3 * this.M_) + -0.00034 * Math.sin(2 * this.M_ - this.M) + 0.00032 * Math.sin(this.M + 2 * this.F) * this.E + 0.00032 * Math.sin(this.M - 2 * this.F) * this.E + -0.00028 * Math.sin(this.M_ + 2 * this.M) * this.E * this.E + 0.00027 * Math.sin(2 * this.M_ + this.M) * this.E + -0.00017 * Math.sin(this.Ω) + -0.00005 * Math.sin(this.M_ - this.M - 2 * this.F) + 0.00004 * Math.sin(2 * this.M_ + 2 * this.F) + -0.00004 * Math.sin(this.M_ + this.M + 2 * this.F) + 0.00004 * Math.sin(this.M_ - 2 * this.M) + 0.00003 * Math.sin(this.M_ + this.M - 2 * this.F) + 0.00003 * Math.sin(3 * this.M) + 0.00002 * Math.sin(2 * this.M_ - 2 * this.F) + 0.00002 * Math.sin(this.M_ - this.M + 2 * this.F) + -0.00002 * Math.sin(3 * this.M_ + this.M);
186 }
187 }, {
188 key: 'w',
189 value: function w() {
190 return 0.00306 - 0.00038 * this.E * Math.cos(this.M) + 0.00026 * Math.cos(this.M_) - 0.00002 * (Math.cos(this.M_ - this.M) - Math.cos(this.M_ + this.M) - Math.cos(2 * this.F));
191 }
192
193 // additional corrections
194
195 }, {
196 key: 'a',
197 value: function a() {
198 var _this = this;
199
200 var a = 0;
201 ac.forEach(function (c, i) {
202 a += c * Math.sin(_this.A[i]);
203 });
204 return a;
205 }
206 }]);
207
208 return Mp;
209}();
210
211// new coefficients
212
213
214var nc = [-0.4072, 0.17241, 0.01608, 0.01039, 0.00739, -0.00514, 0.00208, -0.00111, -0.00057, 0.00056, -0.00042, 0.00042, 0.00038, -0.00024, -0.00017, -0.00007, 0.00004, 0.00004, 0.00003, 0.00003, -0.00003, 0.00003, -0.00002, -0.00002, 0.00002];
215
216// full coefficients
217var fc = [-0.40614, 0.17302, 0.01614, 0.01043, 0.00734, -0.00515, 0.00209, -0.00111, -0.00057, 0.00056, -0.00042, 0.00042, 0.00038, -0.00024, -0.00017, -0.00007, 0.00004, 0.00004, 0.00003, 0.00003, -0.00003, 0.00003, -0.00002, -0.00002, 0.00002];
218
219// additional corrections
220var ac = [0.000325, 0.000165, 0.000164, 0.000126, 0.00011, 0.000062, 0.00006, 0.000056, 0.000047, 0.000042, 0.000040, 0.000037, 0.000035, 0.000023];
221
222exports.default = {
223 meanLunarMonth: meanLunarMonth,
224 meanNew: meanNew,
225 meanFirst: meanFirst,
226 meanFull: meanFull,
227 meanLast: meanLast,
228 newMoon: newMoon,
229 new: newMoon, // BACKWARDS-COMPATIBILITY
230 first: first,
231 full: full,
232 last: last
233};
\No newline at end of file