### 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 objectIt 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

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

I'm writing up an answer based on http://idlastro.gsfc.nasa.gov/ftp/pro/astro/hadec2altaz.pro but you may want to take a look directly.

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_arctangentAdditional caveats:

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/21Additional computations for these results at:

https://github.com/barrycarter/bcapps/blob/master/STACK/bc-rst.mI 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!

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?

Pyephem is based on xephem, which is in C. Xephem is a graphical application which can calculate all the same things that pyephem does.

@W.ChristopherMoses: `pyephem` seems to be just a slim wrapper around `xephem`, whose source code is included.

@W.ChristopherMoses: make that libastro

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?

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 (https://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.

Meeus provides a fairly simple algorithm in Astronomical Algorithms. An example implementation is available in Rise and Set Algorithm. The code is fairly simple and I have reproduced it below.

A couple of warnings. The first is that the algorithm assumes longitudes to the West are positive, which is the opposite of how most GPS APIs return it. And, if the object moves considerably through the day, you may want to recompute the position for the given times, then recompute the rise and set times again.

`//By Greg Miller [email protected] www.astrogreg.com`

//Released as public domain

const toRad=Math.PI/180.0;

const toDeg=180.0/Math.PI;

//Corrects values to make them between 0 and 1

function constrain(v){

if(v<0){return v+1;}

if(v>1){return v-1;}

return v;

}

//All angles must be in radians

//Outputs are times in hours GMT (not accounting for daylight saving time)

//From Meeus Page 101

function getRiseSet(jd,lat,lon,ra,dec){

const h0=-0.8333 //For Sun

//const h0=-0.5667 //For stars and planets

//const h0=0.125 //For Moon

const cosH=(Math.sin(h0*Math.PI/180.0)-Math.sin(lat)*Math.sin(dec)) / (Math.cos(lat)*Math.cos(dec));

const H0=Math.acos(cosH)*180.0/Math.PI;

const gmst=GMST(Math.floor(jd)+.5);

const transit=(ra*toDeg+lon*toDeg-gmst)/360.0;

const rise=transit-(H0/360.0);

const set=transit+(H0/360.0);

return [constrain(transit)*24.0,constrain(rise)*24.0,constrain(set)*24.0];

}

//Greenwhich mean sidreal time from Meeus page 87

//Input is julian date, does not have to be 0h

//Output is angle in degrees

function GMST(jd){

const T=(jd-2451545.0)/36525.0;

let st=280.46061837+360.98564736629*(jd-2451545.0)+0.000387933*T*T - T*T*T/38710000.0;

st=st%360;

if(st<0){st+=360;}

return st;

//return st*Math.PI/180.0;

}

License under CC-BY-SA with attribution

Content dated before 7/24/2021 11:53 AM

barrycarter 6 years ago

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.