I'm trying to improve a site that shows the region of the Earth currently under daylight, and I need a formula that, given the current time, tells where (latitude/longitude) the sun and moon are overhead, accurate to 1 mile. Can anyone come up with one?
I've tried several things (eg, Fourier series on the Sun/Moon's RA/DEC), but nothing seems quite accurate enough.
EDIT: Thanks, Dustin and everyone.
Actually, I'm aware of http://ssd.jpl.nasa.gov/?horizons and even wrote programs to download and parse their data (https://github.com/barrycarter/bcapps/blob/master/bc-email-horizons.pl and https://github.com/barrycarter/bcapps/blob/master/bc-parse-horizons.pl) with the hope of finding simple formulas (https://github.com/barrycarter/bcapps/blob/master/bc-fourier-cont.m and others), but got nowhere.
Currently, I rebuild the script every minute (https://github.com/barrycarter/bcapps/blob/master/bc-sun-always-shines.pl) using interpolated JPLs data (the sun/moonfakex/y.txt files in https://github.com/barrycarter/bcapps/tree/master/data), but this seems insanely complicated.
This may be an inherently difficult and/or pointless question: to get accuracy of 1 mile, you have to calculate the position within 52 seconds of arc, which is considerably smaller than the 30 minute (1800 seconds) width of the sun and moon themselves.
The ultimate goal is to let people zoom into their city on google maps and watch the sunset "sweep" over their city (ie, predict the sun is setting over a certain part of the city and have people in that part of the city confirm it), but given refraction and parallax, this may be impossible.