Celestial Programming : Alt/AZ to Hour Angle and Declination

Given Latitude, and Alt/AZ coordinates. The Hour Angle and Declination can be computed. Further, given Greenwich Sidereal Time, the Hour Angle can be converted to Right Ascension. If the Alt/Az coordinates are from an observation, you will likely need to correct hh for refraction.




 Hour Angle = +01h 43m 15.95s
Declination = -26° 28' 57.33"

tanH=sinAtanhcosϕcosAsinϕsinδ=sinϕsinh+cosϕcoshcosA \begin{align*} \tan H &= \frac{-\sin A}{\tan h \cos \phi - \cos A \sin \phi} \\ \sin \delta &= \sin \phi \sin h + \cos \phi \cos h \cos A \end{align*} hh Alt (height)
AA Azimuth
ϕ\phi Latitude
δ\delta Declination
HH Hour Angle

//Greg Miller (gmiller@gregmiller.net) 2022
//Released as public domain
//www.celestialprogramming.com

//Converts Alt/Az to Hour Angle and Declination
//Modified from Meeus so that 0 Az is North
//All angles are in radians
function altAzToHADec(lat,alt,az){
    let H=Math.atan2(-Math.sin(az),Math.tan(alt)*Math.cos(lat)-Math.cos(az)*Math.sin(lat));
    if(H<0){H+=Math.PI*2;}
    const dec=Math.asin(Math.sin(lat)*Math.sin(alt) + Math.cos(lat)*Math.cos(alt)*Math.cos(az));
    return [H,dec];
}