Take the 2-minute tour ×
Physics Stack Exchange is a question and answer site for active researchers, academics and students of physics. It's 100% free.

Given a position on earth (latitude/longitude, and maybe also height relative to sea-level) and a time, what's the algorithm to find how many degrees the Sun is from the horizon?

And the same for the opposite, given a location and date, how do you calculate the time when the Sun will be such-and-such degrees from the horizon (such as to calculate astronomical dusk and dawn)?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

There are a number of steps involved, each of which are straightforward individually, but when combined make the process a bit tedious to do by hand. The following steps are only a conceptual outline, and ignore a number of important considerations, including but not limited to the ellipticity of the Earth's orbit. The outline of the algorithm is:

  1. Calculate the position of the Sun in ecliptic coordinates. By definition, the ecliptic latitude of the Sun is 0. If you are willing to accept the inaccuracy introduced by pretending the Earths orbit is circular rather than elliptical, and can look up the ecliptic coordinates of the Sun for some time relatively close to the time for which you want the position, you can make the approximation $$\lambda = \lambda_D + \frac{360^\circ}{365.242191\, \mathrm{days}} \Delta D$$ where $\lambda_D$ is the ecliptic longtitude of the sun at date $D$, and $\Delta D$ is the number of days between the time you want and date $D$.
  2. Convert the ecliptic coordinates to equatorial coordinates. Because the ecliptic latitude of the Sun is 0, this reduces to: $$\alpha = \tan^{-1} \left[\frac{\sin \lambda \cos \epsilon}{\cos \lambda}\right]$$ $$\delta = \sin^{-1} [\sin \epsilon \sin \lambda]$$ where $\epsilon$ is the obliquity of the ecliptic, currently about 23.4378 degrees, but it does change over time.
  3. Now you need to convert the right ascension in ecliptic coordinates to an hour angle at the time and longitude of interest. To do this, you need to calculate the local sidereal time. (You can do this by first calculating the Greenwich Sidereal Time (GST), and converting to local sidereal time. Sidereal time and solar time agree at the autumn equinox, so look up the autumn equinox in UT, and calculate the time between then and the time of interest. A sidereal year is one day longer than a solar year, so convert that duration from solar time to sidereal time by multiplying by $\frac{365.242191+1}{365.242191}$. Then convert Greenwich sidereal time to local sidereal time by subtracting the (west) longitude. Be careful with the units here: 24 hours is 360 degrees is $2 \pi$ radians.) Then you can calculate the hour angle: $$H=\mathrm{LST} - \alpha$$.
  4. Once you have the hour angle, $H$, you can calculate the altitude, $a$ (which is half of the conversion to horizon coordinates): $$a=\sin^{-1} [\sin \delta \sin \phi + \cos \delta \cos \phi \cos H]$$ where is $\phi$ is the geographic latitude of interest.

For a treatment sufficient for actual calculation, you can start with Practical Astronomy with your Calculator or Spreadsheet by Duffett-Smith & Zwart. For higher precision, you can go to Astronomical Algorithms by Meeus.

share|improve this answer
Wow!, excellent answer. I'l wait a day or 2 before accepting. –  Philomath Sep 18 '11 at 18:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.