Created
March 7, 2017 17:21
-
-
Save g00dv1n/94d4b15155acd07b8c53bbf034d1db79 to your computer and use it in GitHub Desktop.
calculate Moon's ecliptic longitude
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var date = new Date(); | |
function normalize(v) { | |
v = v - Math.floor(v); | |
if (v < 0) { | |
v = v + 1; | |
} | |
return v; | |
} | |
function moonCoords(d) { // geocentric ecliptic coordinates of the moon | |
var age, // Moon's age | |
distance, // Moon's distance in earth radii | |
latitude, // Moon's ecliptic latitude | |
longitude, // Moon's ecliptic longitude | |
phase, // Moon's phase | |
trajectory, // Moon's trajectory | |
zodiac; // Moon's zodiac sign | |
var yy, mm, k1, k2, k3, jd; | |
var ip, dp, np, rp; | |
var year = date.getFullYear(); | |
var month = date.getMonth()+1; | |
var day = date.getDate(); | |
yy = year - Math.floor((12 - month) / 10); | |
mm = month + 9; | |
if (mm >= 12) { | |
mm = mm - 12; | |
} | |
k1 = Math.floor(365.25 * (yy + 4712)); | |
k2 = Math.floor(30.6 * mm + 0.5); | |
k3 = Math.floor(Math.floor((yy / 100) + 49) * 0.75) - 38; | |
jd = k1 + k2 + day + 59; // for dates in Julian calendar | |
if (jd > 2299160) { | |
jd = jd - k3; // for Gregorian calendar | |
} | |
//calculate moon's age in days | |
ip = normalize((jd - 2451550.1) / 29.530588853); | |
ip = ip * 2 * Math.PI; //Convert phase to radians | |
// Calculate moon's distance | |
dp = 2 * Math.PI * normalize((jd - 2451562.2) / 27.55454988); | |
distance = 60.4 - 3.3 * Math.cos(dp) - 0.6 * Math.cos(2 * ip - dp) - 0.5 * Math.cos(2 * ip); | |
// Calculate moon's ecliptic latitude | |
np = 2 * Math.PI * normalize((jd - 2451565.2) / 27.212220817); | |
latitude = 5.1 * Math.sin(np); | |
// Calculate moon's ecliptic longitude | |
rp = normalize((jd - 2451555.8) / 27.321582241); | |
longitude = 360 * rp + 6.3 * Math.sin(dp) + 1.3 * Math.sin(2 * ip - dp) + 0.7 * Math.sin(2 * ip); | |
return longitude; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment