Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code for calculating "exact" sunrise/sunset #28

Open
ghost opened this issue Apr 1, 2022 · 0 comments
Open

Code for calculating "exact" sunrise/sunset #28

ghost opened this issue Apr 1, 2022 · 0 comments

Comments

@ghost
Copy link

ghost commented Apr 1, 2022

Hello

this little snippet of code was implemented from, if i remember, wikipedia.
It assumes longitude/latitude is stored in lon/lat variables.
The results are not "exact" to the minute, but approximately so. Better than the moshier calculations tho.


datesr = {
	year: 2000,
	month: 1,
	day: 1),
	hours: 12,
	minutes: 0,
	seconds: 0.0
};

nj = datesr.julian - 2451545.0;
Jst = nj - (lon/360.0);
Mas = (357.5291 + (0.98560028*Jst)) % 360.0;
Cen = 1.9148*Math.sin(Mas*$const.DTR) + 0.02*Math.sin(2*Mas*$const.DTR) + 0.0003*Math.sin(3*Mas*$const.DTR);
lamda = (Mas + Cen + 180 + 102.9372) % 360.0;
Jtra = 2451545.0 + Jst + 0.0053*Math.sin(Mas*$const.DTR) - 0.0069*Math.sin(2*lamda*$const.DTR);
sindelta = Math.sin(lamda*$const.DTR) * Math.sin(23.44*$const.DTR);
deltainv = Math.asin(sindelta);
elevel = -1.15*Math.sqrt(60)/60;
cosw = ((Math.sin((elevel-0.83)*$const.DTR) - Math.sin(lat*$const.DTR)*sindelta)/(Math.cos(lat*$const.DTR)*Math.cos(deltainv)));
wo = Math.acos(cosw)*$const.RTD;
Jsunrise = Jtra - wo/360;
Jsunset = Jtra + wo/360;
sunr = { year:0, month:0, day:0, hours:0, minutes:0, seconds:0 };
suns = { year:0, month:0, day:0, hours:0, minutes:0, seconds:0 };
$copy(sunr , d);
$copy(suns , d);
sunr.universalDate = $moshier.julian.toGregorian ({ julian: Jsunrise + ((tz*3600.0)/86400.0) });
suns.universalDate = $moshier.julian.toGregorian ({ julian: Jsunset  + ((tz*3600.0)/86400.0)});
sunriset = (sunr.universalDate.hours % 12) + ":" + ("00"+sunr.universalDate.minutes).substr(-2) + " AM";
sunsett =  (suns.universalDate.hours % 12) + ":" + ("00"+suns.universalDate.minutes).substr(-2) + " PM";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant