UNPKG

4.38 kBJavaScriptView Raw
1/**
2 * @copyright 2013 Sonia Keys
3 * @copyright 2016 commenthol
4 * @license MIT
5 * @module moonillum
6 */
7/**
8 * Moonillum: Chapter 48, Illuminated Fraction of the Moon's Disk
9 *
10 * Also see functions `illuminated` and `limb` in package base. The function
11 * for computing illuminated fraction given a phase angle (48.1) is
12 * base.illuminated. Formula (48.3) is implemented as base.limb.
13 */
14
15import base from './base';
16
17var p = Math.PI / 180;
18
19/**
20 * phaseAngleEquatorial computes the phase angle of the Moon given equatorial coordinates.
21 *
22 * @param {base.Coord} cMoon - geocentric right ascension, declination and distance to the Moon
23 * @param {base.Coord} cSun - coordinates and distance of the Sun
24 * @returns {number} phase angle of the Moon in radians
25 */
26export function phaseAngleEquatorial(cMoon, cSun) {
27 return pa(cMoon.range, cSun.range, cosEq(cMoon.ra, cMoon.dec, cSun.ra, cSun.dec));
28}
29
30/**
31 * cos elongation from equatorial coordinates
32 * @private
33 */
34function cosEq(α, δ, α0, δ0) {
35 var _base$sincos = base.sincos(δ),
36 sδ = _base$sincos[0],
37 cδ = _base$sincos[1];
38
39 var _base$sincos2 = base.sincos(δ0),
400 = _base$sincos2[0],
410 = _base$sincos2[1];
42
43 return0 * sδ + cδ0 * cδ * Math.cos(α0 - α);
44}
45
46/**
47 * phase angle from cos elongation and distances
48 * @private
49 * @param {number} Δ
50 * @param {number} R
51 * @param {number} cψ
52 * @returns {number}
53 */
54function pa(Δ, R, cψ) {
55 var sψ = Math.sin(Math.acos(cψ));
56 var i = Math.atan(R * sψ / (Δ - R * cψ));
57 if (i < 0) {
58 i += Math.PI;
59 }
60 return i;
61}
62
63/**
64 * phaseAngleEquatorial2 computes the phase angle of the Moon given equatorial coordinates.
65 *
66 * Less accurate than phaseAngleEquatorial.
67 *
68 * Arguments α, δ are geocentric right ascension and declination of the Moon;
69 * α0, δ0 are coordinates of the Sun. Angles must be in radians.
70 *
71 * @param {base.Coord} cMoon - eocentric right ascension and declination of the Moon
72 * @param {base.Coord} cSun - coordinates of the Sun
73 * @returns {number} phase angle of the Moon in radians
74 */
75export function phaseAngleEquatorial2(cMoon, cSun) {
76 return Math.acos(-cosEq(cMoon.ra, cMoon.dec, cSun.ra, cSun.dec));
77}
78
79/**
80 * phaseAngleEcliptic computes the phase angle of the Moon given ecliptic coordinates.
81 *
82 * Distances must be in the same units as each other.
83 *
84 * @param {base.Coord} cMoon - geocentric longitude, latitude and distance to the Moon
85 * @param {base.Coord} cSun - longitude and distance to the Sun
86 * @returns {number} phase angle of the Moon in radians
87 */
88export function phaseAngleEcliptic(cMoon, cSun) {
89 return pa(cMoon.range, cSun.range, cosEcl(cMoon.lon, cMoon.lat, cSun.lon));
90}
91
92/**
93 * cos elongation from ecliptic coordinates
94 * @private
95 */
96function cosEcl(λ, β, λ0) {
97 // (λ, β, λ0 float64) float64
98 return Math.cos(β) * Math.cos(λ - λ0);
99}
100
101/**
102 * phaseAngleEcliptic2 computes the phase angle of the Moon given ecliptic coordinates.
103 *
104 * Less accurate than phaseAngleEcliptic.
105 *
106 * Angles must be in radians.
107 *
108 * @param {base.Coord} cMoon - geocentric longitude, latitude of the Moon
109 * @param {base.Coord} cSun - longitude of the Sun
110 * @returns {number} phase angle of the Moon in radians
111 */
112export function phaseAngleEcliptic2(cMoon, cSun) {
113 return Math.acos(-cosEcl(cMoon.lon, cMoon.lat, cSun.lon));
114}
115
116/**
117 * phaseAngle3 computes the phase angle of the Moon given a julian day.
118 *
119 * Less accurate than phaseAngle functions taking coordinates.
120 *
121 * Result in radians.
122 */
123export function phaseAngle3(jde) {
124 // (jde float64) float64
125 var T = base.J2000Century(jde);
126 var D = base.horner(T, 297.8501921 * p, 445267.1114034 * p, -0.0018819 * p, p / 545868, -p / 113065000);
127 var m = base.horner(T, 357.5291092 * p, 35999.0502909 * p, -0.0001535 * p, p / 24490000);
128 var m_ = base.horner(T, 134.9633964 * p, 477198.8675055 * p, 0.0087414 * p, p / 69699, -p / 14712000);
129 return Math.PI - base.pmod(D, 2 * Math.PI) + -6.289 * p * Math.sin(m_) + 2.1 * p * Math.sin(m) + -1.274 * p * Math.sin(2 * D - m_) + -0.658 * p * Math.sin(2 * D) + -0.214 * p * Math.sin(2 * m_) + -0.11 * p * Math.sin(D);
130}
131
132export default {
133 phaseAngleEquatorial: phaseAngleEquatorial,
134 phaseAngleEquatorial2: phaseAngleEquatorial2,
135 phaseAngleEcliptic: phaseAngleEcliptic,
136 phaseAngleEcliptic2: phaseAngleEcliptic2,
137 phaseAngle3: phaseAngle3
138};
\No newline at end of file