← Back to archive
Programming Notes

Calculating Planetary Azimuth and Altitude

天文
First you need a number called "sidereal time." Local Sidereal Time (LST) is simply the RA of the local meridian. Greenwich Mean Sidereal Time (GMST) is distinguished from LST at Greenwich. Greenwich time corresponding to 0 hours sidereal time UT (GMST0) is just the GMST at Greenwich midnight. Because one Earth rotation takes 23 hours 56 minutes 4 seconds—about 3 minutes 51 seconds more than a typical 24 hours—we extend the GMST0 concept here: let GMST0 match the conventional GMST0 at UT midnight, and allow GMST0 to be defined at any other time such that GMST0 increases by 3m51 per 24 hours. Then this formula is valid at any time: GMST = GMST0 + UT We also need the Sun's mean longitude Ls, which can be computed from the Sun's v and w as follows: Ls = v + w GMST0 is easily computed from Ls (divide by 15 if you want GMST0 in hours rather than degrees), then compute GMST by adding UT, and finally add your local longitude (east positive, west negative). Note that "time" is given in hours while "angles" are given in degrees. Because of Earth's rotation, the two are related to each other: one hour is equivalent to 15 degrees here. Before adding or subtracting "time" and "angles", be sure to convert them to the same unit—for example, degrees—by multiplying hours by 15 before adding/subtracting: GMST0 = Ls + 180 degrees GMST = GMST0 + UT LST = GMST + local_longitude The formulas above are written as if time is expressed in degrees. If we assume time is given in hours and angles in degrees, and explicitly write out the conversion factor of 15, we get: GMST0 = (Ls + 180 degrees) / 15 = Ls / 15 + 12 hours GMST = GMST0 + UT LST = GMST + local_longitude / 15 To find the equatorial coordinates (azimuth and altitude), first proceed by computing the object's HA (hour angle). But first we must compute LST (local sidereal time), as above. Once we know LST, we can easily compute HA: HA = LST - RA HA is usually given between -12 and +12 hours, or -180 and +180 degrees. If HA is zero, the object can be seen due south. If HA is negative, the object is east of south; if HA is positive, the object is west of south. If the computed HA should fall outside this interval, add or subtract 24 hours (or 360 degrees) until HA falls within the interval. Now convert HA and Decl to local azimuth and altitude. To do this, you must know the latitude—your local latitude. Then proceed as follows: x = cos(HA) * cos(Decl) y = sin(HA) * cos(Decl) z = sin(Decl) xhor = x * sin(lat) - z * cos(lat) yhor = y zhor = x * cos(lat) + z * sin(lat) az = atan2(yhor, xhor) + 180 degrees alt = asin(zhor) = atan2(zhor, sqrt(xhor * xhor + yhor * yhor)) This completes our computation of local azimuth and altitude. Note that azimuth is 0 for north, 90 degrees for east, 180 for south, and 270 for west. Altitude is of course 0 at the (mathematical) horizon, 90 degrees at the zenith, and negative below the horizon.

Written by Master Sanfu on November 18, 2016. Please credit the source if you share.

Translation Notice: This English version was translated with AI assistance. Specialized, historical, religious, or culturally sensitive terms may contain nuances, inaccuracies, or debatable wording. In case of ambiguity or discrepancy, the original Chinese text shall prevail.