# Calculating the time of dawn

Knowing that astronomical twilight (i.e. astronomical dawn) is when the sun is 18 degrees below the horizon, I am calculating the astronomical twilight time this way:

Sunrise of day1 - [ (Sunrise of day1 - Sunset of day0) / 180° ] * 18°

Is that correct?

-

No, that's not correct. Or, rather, it would only be correct on the equator at the equinox, when the sun rises and sets straight up and traces a full great circle across the sky.

Instead, start with the formula for the solar elevation angle $\theta_\mathrm{s}$,

$$\sin \theta_\mathrm{s} = \cos h \cos \delta \cos \Phi + \sin \delta \sin \Phi,$$

and solve for the hour angle $h$ (in the local solar time):

$$\cos h = \frac{\sin \theta_\mathrm{s} - \sin \delta \sin \Phi}{\cos \delta \cos \Phi}$$

where $\delta$ is the current sun declination, $\Phi$ is the local latitude and $\theta_\mathrm{s} = -18^\circ$ (plus a correction for atmospheric refraction, if that's not already included in the 18° figure).

-

With thanks to Ilmari Karonen above, for the guidance provided here, I modified this go library cpucycle/astrotime (on github.com) to take account of dawn and dusk calculations (results here ninjasphere/astrotime also on github.com).

To test these results, I compared the library outputs with those generated by http://www.timeanddate.com/worldclock/sunrise.html. To reproduce those results, I had to omit the refractive index from the calculations of dawn and dusk. Presumably this is because the definitions of dawn and dusk are based on the actual, rather than apparent, location of the sun and so do not need to take account of refractive index.

-