# Need Simple equation for Rise, Transit, and Set time

I've been looking, unsuccessfully, for hours for a simple set of equations:

Input:
RA and Dec of an object
Observers Lat and Lng
Current Time

Output:
Rise Time
Transit Time
Set Time
(and, hopefully) max elevation at transit
(and, hopefully) current alt and az of object

It seems like this should be a simple relationship, but I haven't been able to find it.
If an equation simply gives the current alt/az for an object, I guess I could solve for az and then find the maximum for a given time range.

Questions:
1. Anybody know of such equations? Or, even better, some sample code.
2. If not, can anybody point me in the right direction?

Thanks

• It depends on your definition of "simple". If you're talking about a fixed object (like a star), willing to input the sidereal time (which can be calculated fairly easy from the current time), and willing to use trigonometric functions, this is fairly easy to do. – barrycarter Apr 10 '16 at 2:19
• Yes! I'm only interested in "fixed" objects on the celestial sphere. By "simple," I mean simple for an experienced programmer to implement. Of course, if it is simple to understand, all the better. It does seem like it should be "simple" all around, but I would rather not try to create it all from scratch. Any references or pointers would be greatly appreciated – W. Christopher Moses Apr 10 '16 at 23:09
• I'm writing up an answer based on idlastro.gsfc.nasa.gov/ftp/pro/astro/hadec2altaz.pro but you may want to take a look directly. – barrycarter Apr 10 '16 at 23:55

The calculations are not trivial, but they are encapsulated in software libraries such as pyephem, which has examples of finding rise, set and transit If you want to understand how these are calculated, you can readnthe source, which is based on the xephem application.

One detail which complicates the calculation is the refraction caused by the atmosphere, which can change the moment of setting by several minutes.

• Thanks. I'll take a look at pyephem, but my python is weak. Do you know of any C or .NET based libraries? – W. Christopher Moses Apr 10 '16 at 18:23
• Pyephem is based on xephem, which is in C. Xephem is a graphical application which can calculate all the same things that pyephem does. – James K Apr 10 '16 at 20:09
• @W.ChristopherMoses: pyephem seems to be just a slim wrapper around xephem, whose source code is included. – serv-inc Jun 16 '18 at 16:38
• @W.ChristopherMoses: make that libastro – serv-inc Jul 3 '18 at 19:40

I'm not sure it qualifies as "simple", but, using http://idlastro.gsfc.nasa.gov/ftp/pro/astro/hadec2altaz.pro (and some additional calculations/simplifications):

$\begin{array}{|c|c|c|c|} \hline \text{Event} & \text{Time} & \phi & Z \\ \hline \text{Any} & \text{t} & \tan ^{-1}(\cos (\lambda ) \sin (\delta )-\cos (\delta ) \cos (\alpha -t) \sin (\lambda ),\cos (\delta ) \sin (\alpha -t)) & \tan ^{-1}\left(\sqrt{(\cos (\lambda ) \sin (\delta )-\cos (\delta ) \cos (\alpha -t) \sin (\lambda ))^2+\cos ^2(\delta ) \sin ^2(\alpha -t)},\cos (\delta ) \cos (\lambda ) \cos (\alpha -t)+\sin (\delta ) \sin (\lambda )\right) \\ \hline \text{Rise} & \alpha -\cos ^{-1}(-\tan (\delta ) \tan (\lambda )) & \tan ^{-1}\left(\sec (\lambda ) \sin (\delta ),\cos (\delta ) \sqrt{1-\tan ^2(\delta ) \tan ^2(\lambda )}\right) & 0 \\ \hline \text{Transit} & \alpha & \begin{cases} \delta >\lambda & 0 \\ \delta =\lambda & \text{Zenith} \\ \delta <\lambda & \pi \end{cases} & \frac{\pi }{2}-\left| \delta -\lambda \right| \\ \hline \text{Set} & \alpha +\cos ^{-1}(-\tan (\delta ) \tan (\lambda )) & \tan ^{-1}\left(\sec (\lambda ) \sin (\delta ),-\cos (\delta ) \sqrt{1-\tan ^2(\delta ) \tan ^2(\lambda )}\right) & 0 \\ \hline \text{Lowest Point} & \alpha +\pi & \begin{cases} \delta >-\lambda & 0 \\ \delta =-\lambda & \text{Nadir} \\ \delta <-\lambda & \pi \end{cases} & \left| \delta +\lambda \right|-\frac{\pi }{2} \\ \hline \end{array}$

where:

• $\phi$ is the azimuth of the object

• $Z$ is the altitude of the object above the horizon

• $\alpha$ is the right ascension of the object

• $\delta$ is the declination of the object

• $\lambda$ is the latitude of the observer

• $t$ is the current local sidereal time

Note the two-argument form of arctangent is required so that the results are in the correct quadrant: https://en.wikipedia.org/wiki/Inverse_trigonometric_functions#Two-argument_variant_of_arctangent

• If $\left| \delta -\lambda \right|>\frac{\pi }{2}$, the object is always below the horizon, and the equations for rising time and setting time will not work.

• If $\left| \delta +\lambda \right|>\frac{\pi }{2}$, the object is always above the horizon (circumpolar), and the equations for rising and setting time will also not work.

• The measurements above are in radians. You can convert $\pi \to 180 {}^{\circ}$ for degrees.

• Because we use the local sidereal time, the longitude doesn't appear in any of the formulas above. However, we do need it to find the local sidereal time, as below.

• To find the local sideral time $t$ in radians, we use http://aa.usno.navy.mil/faq/docs/GAST.php and make some substitions to get:

$t = 4.894961212735792 + 6.30038809898489 d + \psi$

where $\psi$ is your longitude in radians, and $d$ is the number of days (including fractional days) since "2000-01-01 12:00:00 UTC". Traditionally, we use $\phi$ for longitude, but I'm already using it in the formulas above for azimuth.

If you combine the formula for local sidereal time and azimuth/altitude and assume excessive precision, you get my answer to https://astronomy.stackexchange.com/a/8415/21

Additional computations for these results at: https://github.com/barrycarter/bcapps/blob/master/STACK/bc-rst.m

I was going to add some graphs to show how the altitude is NOT a sine wave and how the azimuth is NOT a straight line (although you might expect them to be), but they turned out not to be terribly instructive/helpful.

You might also be able to get simpler formulas if you set $t$ to be the "hour angle" (which is $\alpha-t$ in the current setup).

• Can you explain how to interpret the rise/set values in the time column? I know they are in radians, but how can I convert these to actual time values? Many thanks for a great answer by the way! – codebox Nov 17 '18 at 17:32

If you want a website rather than a software package like James suggests, I recommend use the INGT object visibility tool which has all 3 inputs you request and produces an elevation plot with rise and set times, maximum altitude etc. An example is shown below: • Glancing at the source, it does not look like code is available on the page. Do you know of other sites which produce such a nice plot and have the code embedded? – W. Christopher Moses Apr 10 '16 at 18:34
• There are these ones on the bottom of the page under the "More" tab : iObserve, astronomy tools, JSkyCalc, obstools. They might have code embedded if you look through them, however you might like to try Astroplan (astroplan.readthedocs.org/en/latest/tutorials/plots.html) its an Astropy affiliated package that looks very promising as an astronomy planning tool, it should have all the source code on there, although I believe its still in development. – Dean Apr 10 '16 at 20:21