Physics Stack Exchange is a question and answer site for active researchers, academics and students of physics. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been looking for a program to convert from RA/dec into Alt/Az; having used a couple of online versions I haven't seemed to find one yet that works reliably. I've tried to do it myself and half the numbers end up spot on, but the other half are way off. It's not something I can plug in completely by hand, I need to convert about 300 images.

Is there good code, a program, etc. that will honestly always give back the right coordinates? Failing that, is it a common slip-up messing up the values?

share|cite|improve this question
I should add this would most helpfully be something that works in IDL/linux or a ready-made spreadsheet – Tan Apr 25 '12 at 21:33

Did you convert RA to Hour Angle before converting it to Azimuth?

HA = LST - RA (see here for a description on how to do it)

If you need a program to do it, then you should look up The IDL Astronomy User's Library specifically the HADEC2ALTAZ (Convert Hour Angle and Declination to Horizon (alt-az) coordinates) subroutine. Have included the code below. I haven't personally used this and thus cannot verify the reliability and I don't use IDL any more. However, the source is very trustworthy :)

Let us know if you any problems in its implementation. Good luck!

PRO hadec2altaz, ha, dec, lat, alt, az, WS=WS

;  NAME:
;      Converts Hour Angle and Declination to Horizon (alt-az) coordinates.
;      Can deal with NCP/SCP singularity.    Intended mainly to be used by
;      program EQ2HOR
;      HADEC2ALTAZ, ha, dec, lat ,alt ,az [ /WS ]
;     ha -  the local apparent hour angle, in DEGREES, scalar or vector
;     dec -  the local apparent declination, in DEGREES, scalar or vector
;     lat -  the local latitude, in DEGREES, scalar or vector
;     alt - the local apparent altitude, in DEGREES.
;     az  - the local apparent azimuth, in DEGREES, all results in double
;           precision
;      /WS - Set this keyword for the output azimuth to be measured West from 
;            South.    The default is to measure azimuth East from North.
;     What were the apparent altitude and azimuth of the sun when it transited 
;     the local meridian at Pine Bluff Observatory (Lat=+43.07833 degrees) on 
;     April 21, 2002?   An object transits the local meridian at 0 hour angle.
;     Assume this will happen at roughly 1 PM local time (18:00 UTC).
;     IDL> jdcnv, 2002, 4, 21, 18., jd  ; get rough Julian date to determine 
;                                       ;Sun ra, dec.
;     IDL> sunpos, jd, ra, dec
;     IDL> hadec2altaz, 0., dec, 43.078333, alt, az
;       ===> Altitude alt = 58.90
;            Azimuth  az = 180.0

;      Written  Chris O'Dell Univ. of Wisconsin-Madison May 2002

if N_params() LT 4 then begin
     print,'Syntax - HADEC2ALTAZ, ha, dec, lat ,alt ,az [ /WS ]'

d2r = !dpi/180.

sh = sin(ha*d2r) & ch = cos(ha*d2r)
sd = sin(dec*d2r) & cd = cos(dec*d2r)
sl = sin(lat*d2r) & cl = cos(lat*d2r)

x = - ch * cd * sl + sd * cl
y = - sh * cd
z = ch * cd * cl + sd * sl
r = sqrt(x^2 + y^2)
; now get Alt, Az

az = atan(y,x) /d2r
alt = atan(z,r) / d2r

; correct for negative AZ
w = where(az LT 0)
if w[0] ne -1 then az[w] = az[w] + 360.

; convert AZ to West from South, if desired
if keyword_set(WS) then az = (az + 180.) mod 360.

share|cite|improve this answer
great, thanks :) pointed me in the right direction to a slightly different version – Tan Apr 26 '12 at 6:42

Your Answer


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