UNPKG

8.17 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 moonphase
8 */
9/**
10 * Moonphase: Chapter 49, Phases of the Moon
11 */
12
13import base from './base';
14
15var ck = 1 / 1236.85;
16
17/**
18 * mean synodial lunar month
19 */
20export var meanLunarMonth = 29.530588861;
21
22// (49.1) p. 349
23function mean(T) {
24 return base.horner(T, 2451550.09766, 29.530588861 / ck, 0.00015437, -0.00000015, 0.00000000073);
25}
26
27/** snap returns k at specified quarter q nearest year y. */
28function snap(y, q) {
29 var k = (y - 2000) * 12.3685; // (49.2) p. 350
30 return Math.floor(k - q + 0.5) + q;
31}
32
33/**
34 * MeanNew returns the jde of the mean New Moon nearest the given datthis.
35 * The mean date is within 0.5 day of the true date of New Moon.
36 *
37 * @param {Number} year - decimal year
38 * @returns {Number} jde
39 */
40export function meanNew(year) {
41 return mean(snap(year, 0) * ck);
42}
43
44/**
45 * MeanFirst returns the jde of the mean First Quarter Moon nearest the given datthis.
46 * The mean date is within 0.5 day of the true date of First Quarter Moon.
47 *
48 * @param {Number} year - decimal year
49 * @returns {Number} jde
50 */
51export function meanFirst(year) {
52 return mean(snap(year, 0.25) * ck);
53}
54
55/**
56 * MeanFull returns the jde of the mean Full Moon nearest the given datthis.
57 * The mean date is within 0.5 day of the true date of Full Moon.
58 *
59 * @param {Number} year - decimal year
60 * @returns {Number} jde
61 */
62export function meanFull(year) {
63 return mean(snap(year, 0.5) * ck);
64}
65
66/**
67 * MeanLast returns the jde of the mean Last Quarter Moon nearest the given datthis.
68 * The mean date is within 0.5 day of the true date of Last Quarter Moon.
69 *
70 * @param {Number} year - decimal year
71 * @returns {Number} jde
72 */
73export function meanLast(year) {
74 return mean(snap(year, 0.75) * ck);
75}
76
77/**
78 * New returns the jde of New Moon nearest the given date.
79 *
80 * @param {Number} year - decimal year
81 * @returns {Number} jde
82 */
83export function newMoon(year) {
84 var m = new Mp(year, 0);
85 return mean(m.T) + m.nfc(nc) + m.a();
86}
87
88/**
89 * First returns the jde of First Quarter Moon nearest the given datthis.
90 *
91 * @param {Number} year - decimal year
92 * @returns {Number} jde
93 */
94export function first(year, month, day) {
95 var m = new Mp(year, 0.25);
96 return mean(m.T) + m.flc() + m.w() + m.a();
97}
98
99/**
100 * Full returns the jde of Full Moon nearest the given datthis.
101 *
102 * @param {Number} year - decimal year
103 * @returns {Number} jde
104 */
105export function full(year, month, day) {
106 var m = new Mp(year, 0.5);
107 return mean(m.T) + m.nfc(fc) + m.a();
108}
109
110/**
111 * Last returns the jde of Last Quarter Moon nearest the given datthis.
112 *
113 * @param {Number} year - decimal year
114 * @returns {Number} jde
115 */
116export function last(year, month, day) {
117 var m = new Mp(year, 0.75);
118 return mean(m.T) + m.flc() - m.w() + m.a();
119}
120
121var p = Math.PI / 180;
122
123var Mp = function () {
124 function Mp(y, q) {
125 _classCallCheck(this, Mp);
126
127 this.A = new Array(14);
128 this.k = snap(y, q);
129 this.T = this.k * ck; // (49.3) p. 350
130 this.E = base.horner(this.T, 1, -0.002516, -0.0000074);
131 this.M = base.horner(this.T, 2.5534 * p, 29.1053567 * p / ck, -0.0000014 * p, -0.00000011 * p);
132 this.M_ = base.horner(this.T, 201.5643 * p, 385.81693528 * p / ck, 0.0107582 * p, 0.00001238 * p, -0.000000058 * p);
133 this.F = base.horner(this.T, 160.7108 * p, 390.67050284 * p / ck, -0.0016118 * p, -0.00000227 * p, 0.000000011 * p);
134 this.Ω = base.horner(this.T, 124.7746 * p, -1.56375588 * p / ck, 0.0020672 * p, 0.00000215 * p);
135 this.A[0] = 299.7 * p + 0.107408 * p * this.k - 0.009173 * this.T * this.T;
136 this.A[1] = 251.88 * p + 0.016321 * p * this.k;
137 this.A[2] = 251.83 * p + 26.651886 * p * this.k;
138 this.A[3] = 349.42 * p + 36.412478 * p * this.k;
139 this.A[4] = 84.66 * p + 18.206239 * p * this.k;
140 this.A[5] = 141.74 * p + 53.303771 * p * this.k;
141 this.A[6] = 207.17 * p + 2.453732 * p * this.k;
142 this.A[7] = 154.84 * p + 7.30686 * p * this.k;
143 this.A[8] = 34.52 * p + 27.261239 * p * this.k;
144 this.A[9] = 207.19 * p + 0.121824 * p * this.k;
145 this.A[10] = 291.34 * p + 1.844379 * p * this.k;
146 this.A[11] = 161.72 * p + 24.198154 * p * this.k;
147 this.A[12] = 239.56 * p + 25.513099 * p * this.k;
148 this.A[13] = 331.55 * p + 3.592518 * p * this.k;
149 }
150
151 // new or full corrections
152
153
154 Mp.prototype.nfc = function nfc(c) {
155 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_);
156 };
157
158 // first or last corrections
159
160
161 Mp.prototype.flc = function flc() {
162 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);
163 };
164
165 Mp.prototype.w = function w() {
166 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));
167 };
168
169 // additional corrections
170
171
172 Mp.prototype.a = function a() {
173 var _this = this;
174
175 var a = 0;
176 ac.forEach(function (c, i) {
177 a += c * Math.sin(_this.A[i]);
178 });
179 return a;
180 };
181
182 return Mp;
183}();
184
185// new coefficients
186
187
188var 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];
189
190// full coefficients
191var 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];
192
193// additional corrections
194var 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];
195
196export default {
197 meanLunarMonth: meanLunarMonth,
198 meanNew: meanNew,
199 meanFirst: meanFirst,
200 meanFull: meanFull,
201 meanLast: meanLast,
202 newMoon: newMoon,
203 new: newMoon, // BACKWARDS-COMPATIBILITY
204 first: first,
205 full: full,
206 last: last
207};
\No newline at end of file