-
Notifications
You must be signed in to change notification settings - Fork 0
/
meeus-illuminated_fraction_of_the_moon.html
132 lines (106 loc) · 3.88 KB
/
meeus-illuminated_fraction_of_the_moon.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<html>
<head>
<title>Illuminated Fraction of the Moon</title>
<link rel="stylesheet" href="default.css">
<link rel="stylesheet" href="highlight/styles/default.css">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style>
body{}
</style>
</head>
<body>
<h1>Illuminated Fraction of the Moon</h1>
This is an implementation of approximation aglorithm (48.4) in Astronomical Algorithms.
<pre id="output"></pre>
<pre id="sourceOutput">
<code class="JavaScript" id='code1'>
/*
Greg Miller [email protected] 2021
http://www.celestialprogramming.com/
Released as public domain
*/
function JulianDateFromUnixTime(t){
//Not valid for dates before Oct 15, 1582
return (t / 86400000) + 2440587.5;
}
function UnixTimeFromJulianDate(jd){
//Not valid for dates before Oct 15, 1582
return (jd-2440587.5)*86400000;
}
function constrain(d){
let t=d%360;
if(t<0){t+=360;}
return t;
}
function getIlluminatedFractionOfMoon(jd){
const toRad=Math.PI/180.0;
const T=(jd-2451545)/36525.0;
const D = constrain(297.8501921 + 445267.1114034*T - 0.0018819*T*T + 1.0/545868.0*T*T*T - 1.0/113065000.0*T*T*T*T)*toRad; //47.2
const M = constrain(357.5291092 + 35999.0502909*T - 0.0001536*T*T + 1.0/24490000.0*T*T*T)*toRad; //47.3
const Mp = constrain(134.9633964 + 477198.8675055*T + 0.0087414*T*T + 1.0/69699.0*T*T*T - 1.0/14712000.0*T*T*T*T)*toRad; //47.4
//48.4
const i=constrain(180 - D*180/Math.PI - 6.289 * Math.sin(Mp) + 2.1 * Math.sin(M) -1.274 * Math.sin(2*D - Mp) -0.658 * Math.sin(2*D) -0.214 * Math.sin(2*Mp) -0.11 * Math.sin(D))*toRad;
const k=(1+Math.cos(i))/2;
return k;
}
</code>
</pre>
<script id='sourceCode'>
/*
Greg Miller [email protected] 2021
http://www.celestialprogramming.com/
Released as public domain
*/
function JulianDateFromUnixTime(t){
//Not valid for dates before Oct 15, 1582
return (t / 86400000) + 2440587.5;
}
function UnixTimeFromJulianDate(jd){
//Not valid for dates before Oct 15, 1582
return (jd-2440587.5)*86400000;
}
function constrain(d){
let t=d%360;
if(t<0){t+=360;}
return t;
}
function getIlluminatedFractionOfMoon(jd){
const toRad=Math.PI/180.0;
const T=(jd-2451545)/36525.0;
const D = constrain(297.8501921 + 445267.1114034*T - 0.0018819*T*T + 1.0/545868.0*T*T*T - 1.0/113065000.0*T*T*T*T)*toRad; //47.2
const M = constrain(357.5291092 + 35999.0502909*T - 0.0001536*T*T + 1.0/24490000.0*T*T*T)*toRad; //47.3
const Mp = constrain(134.9633964 + 477198.8675055*T + 0.0087414*T*T + 1.0/69699.0*T*T*T - 1.0/14712000.0*T*T*T*T)*toRad; //47.4
//48.4
const i=constrain(180 - D*180/Math.PI - 6.289 * Math.sin(Mp) + 2.1 * Math.sin(M) -1.274 * Math.sin(2*D - Mp) -0.658 * Math.sin(2*D) -0.214 * Math.sin(2*Mp) -0.11 * Math.sin(D))*toRad;
const k=(1+Math.cos(i))/2;
return k;
}
</script>
<script>
show30Days();
function show30Days(){
const t=new Date().getTime();
const jd=JulianDateFromUnixTime(t);
let text="";
for(let i=0;i<30;i++){
const f=Math.round(getIlluminatedFractionOfMoon(jd+i)*100);
text+=new Date(UnixTimeFromJulianDate(jd+i))+": "+ f+"%\r\n";
}
document.getElementById("output").innerText=text;
}
//MeeusExample48a();
function MeeusExample48a(){
const jd=JulianDateFromUnixTime(Date.UTC(1992,3,12));
getIlluminatedFractionOfMoon(jd);
}
</script>
<script>
let t=document.getElementById("sourceCode").innerText;
t=t.replaceAll("<","<")
t=t.replaceAll(">",">")
document.getElementById("code1").innerHTML=t;
</script>
<script src="highlight/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</body>
</html>