<p><code>lat2</code> = 0 and <code>lmst</code> = 0 place the vernal equinox at the zenith, so most points on the ecliptic <em>should</em> have azimuth either <code>obliq</code> degrees north of east or <code>obliq</code> degrees south of west. Try other values for <code>lat2</code> or <code>lmst</code> and see if the resulting azimuths make sense.</p>

CC BY-SA 3.0
2016-05-27T19:34:19.813Z
When I try actual data like `lmst` = 184.18° (12h16m); `obliq` = 23.44° to get the azimuth for Venus on May 27th 2016 19 h UT for Berlin (`lat2` = 52.52°; `lon2` = 13.41667°) the function returns 127.38° but the Astronomical Almanac says it should be 307.366°. `δ`, `α` and `h` are according to the Almanac.
atarax42
CC BY-SA 3.0
2016-05-27T21:24:07.203Z
Aha, the azimuths in your table are also off by 180$^\circ$. Negate both arguments of atan2.
Mike G
CC BY-SA 3.0
2016-05-27T17:48:11.073Z
2016-05-27T17:48:11.073Z
Mike G
<p>I try to get the azimuth of an object from its equatorial coordinates using this formula:</p>

<p>$a = \arctan2(\sin(θ - α), \sin φ * \cos(θ - α) - \cos φ * \tan δ)$</p>

<p>Where<br>
φ = geographic latitude of the observer (here: 0°)<br>
θ = sidereal time (here: 0°)<br>
δ = declination<br>
α = right ascension</p>

<p>I made two JavaScript functions to implement this calculation:</p>

<pre><code>  obliq = deg2rad(23.44);  // obliquity of ecliptic
  lat2  = deg2rad(0);  // observer's latitude
  lmst  = deg2rad(0);  // siderial time

  function equatorial(lat, lon) {
    // returns equatorial from ecliptic coordinates
    dec = Math.asin( Math.cos(obliq) * Math.sin(lat) + Math.sin(obliq) *
          Math.cos(lat) * Math.sin(lon));
    ra  = Math.atan2(Math.cos(obliq) * Math.sin(lon) - Math.sin(obliq) * Math.tan(lat),
          Math.cos(lon));
    ra += 2 * Math.PI * (ra &lt; 0);
    return [dec, ra];
  }

  function horizontal(lat, lon) {
    // returns horizontal from ecliptic coordinates
    coords = equatorial(lat, lon);
    dec = coords[0];  // δ
    ra  = coords[1];  // α
    alt = Math.asin(Math.sin(lat2) * Math.sin(dec) + Math.cos(lat2) *
          Math.cos(dec) * Math.cos(lmst - ra));
    azm = Math.atan2(Math.sin(lmst - ra), Math.sin(lat2) * Math.cos(lmst - ra) -
          Math.cos(lat2) * Math.tan(dec));
    azm += 2 * Math.PI * (azm &lt; 0);
    return [alt, azm];
  }
</code></pre>

<p>I cannot see any error, but I get strange results for azimuth (a) as can be seen in this table (the other values seem correct):</p>

<pre><code>   λ       δ         α         h         a
    0    0.0000    0.0000   90.0000    0.0000
   15    5.9094   13.8115   75.0000  246.5600
   30   11.4723   27.9104   60.0000  246.5600
   45   16.3366   42.5357   45.0000  246.5600
   60   20.1510   57.8186   30.0000  246.5600
   75   22.5962   73.7196   15.0000  246.5600
   90   23.4400   90.0000    0.0000  246.5600
  105   22.5962  106.2804  -15.0000  246.5600
  120   20.1510  122.1814  -30.0000  246.5600
  135   16.3366  137.4643  -45.0000  246.5600
  150   11.4723  152.0896  -60.0000  246.5600
  165    5.9094  166.1885  -75.0000  246.5600
  180    0.0000  180.0000  -90.0000  248.3079
  195   -5.9094  193.8115  -75.0000   66.5600
  210  -11.4723  207.9104  -60.0000   66.5600
  225  -16.3366  222.5357  -45.0000   66.5600
  240  -20.1510  237.8186  -30.0000   66.5600
  255  -22.5962  253.7196  -15.0000   66.5600
  270  -23.4400  270.0000   -0.0000   66.5600
  285  -22.5962  286.2804   15.0000   66.5600
  300  -20.1510  302.1814   30.0000   66.5600
  315  -16.3366  317.4643   45.0000   66.5600
  330  -11.4723  332.0896   60.0000   66.5600
  345   -5.9094  346.1885   75.0000   66.5600
  360   -0.0000  360.0000   90.0000   68.3079
</code></pre>

<p>Does anyone see the error? Thank you.</p>

CC BY-SA 3.0
2016-05-27T15:51:27.247Z
This is debugging more than astronomy, perhaps better suited for stackoverflow? I'm not getting your values in a quick test in the Chrome console; I suggest you print out the intermediate values to see what's happening.
j-g-faustus
CC BY-SA 3.0
2016-05-27T17:09:13.513Z
Depends on where the error is. I guess it is in the original formula and not in  the code. But I don't know if the formula is correct or not, that's why I ask. If anyone can confirm the formula should yield the correct values then I would look for the error in my implementation. The code example is only to document my approach.
atarax42
<fundamental-astronomy><coordinate><azimuth>
Calculating azimuth from equatorial coordinates
atarax42
# Calculating azimuth from equatorial coordinates

(Asked by: username_0 on 2016-05-27)

I try to get the azimuth of an object from its equatorial coordinates using this formula:

$a = \arctan2(\sin(θ - α), \sin φ \* \cos(θ - α) - \cos φ \* \tan δ)$

Where  
φ = geographic latitude of the observer (here: 0°)  
θ = sidereal time (here: 0°)  
δ = declination  
α = right ascension

I made two JavaScript functions to implement this calculation:

```
  obliq = deg2rad(23.44);  // obliquity of ecliptic
  lat2  = deg2rad(0);  // observer's latitude
  lmst  = deg2rad(0);  // siderial time

  function equatorial(lat, lon) {
    // returns equatorial from ecliptic coordinates
    dec = Math.asin( Math.cos(obliq) * Math.sin(lat) + Math.sin(obliq) *
          Math.cos(lat) * Math.sin(lon));
    ra  = Math.atan2(Math.cos(obliq) * Math.sin(lon) - Math.sin(obliq) * Math.tan(lat),
          Math.cos(lon));
    ra += 2 * Math.PI * (ra < 0);
    return [dec, ra];
  }

  function horizontal(lat, lon) {
    // returns horizontal from ecliptic coordinates
    coords = equatorial(lat, lon);
    dec = coords[0];  // δ
    ra  = coords[1];  // α
    alt = Math.asin(Math.sin(lat2) * Math.sin(dec) + Math.cos(lat2) *
          Math.cos(dec) * Math.cos(lmst - ra));
    azm = Math.atan2(Math.sin(lmst - ra), Math.sin(lat2) * Math.cos(lmst - ra) -
          Math.cos(lat2) * Math.tan(dec));
    azm += 2 * Math.PI * (azm < 0);
    return [alt, azm];
  }

```

I cannot see any error, but I get strange results for azimuth (a) as can be seen in this table (the other values seem correct):

```
   λ       δ         α         h         a
    0    0.0000    0.0000   90.0000    0.0000
   15    5.9094   13.8115   75.0000  246.5600
   30   11.4723   27.9104   60.0000  246.5600
   45   16.3366   42.5357   45.0000  246.5600
   60   20.1510   57.8186   30.0000  246.5600
   75   22.5962   73.7196   15.0000  246.5600
   90   23.4400   90.0000    0.0000  246.5600
  105   22.5962  106.2804  -15.0000  246.5600
  120   20.1510  122.1814  -30.0000  246.5600
  135   16.3366  137.4643  -45.0000  246.5600
  150   11.4723  152.0896  -60.0000  246.5600
  165    5.9094  166.1885  -75.0000  246.5600
  180    0.0000  180.0000  -90.0000  248.3079
  195   -5.9094  193.8115  -75.0000   66.5600
  210  -11.4723  207.9104  -60.0000   66.5600
  225  -16.3366  222.5357  -45.0000   66.5600
  240  -20.1510  237.8186  -30.0000   66.5600
  255  -22.5962  253.7196  -15.0000   66.5600
  270  -23.4400  270.0000   -0.0000   66.5600
  285  -22.5962  286.2804   15.0000   66.5600
  300  -20.1510  302.1814   30.0000   66.5600
  315  -16.3366  317.4643   45.0000   66.5600
  330  -11.4723  332.0896   60.0000   66.5600
  345   -5.9094  346.1885   75.0000   66.5600
  360   -0.0000  360.0000   90.0000   68.3079

```

Does anyone see the error? Thank you.

**Tags:** fundamental-astronomy, coordinate, azimuth

> **Comments:**
> **username_1**: This is debugging more than astronomy, perhaps better suited for stackoverflow? I'm not getting your values in a quick test in the Chrome console; I suggest you print out the intermediate values to see what's happening.  
> **username_0**: Depends on where the error is. I guess it is in the original formula and not in  the code. But I don't know if the formula is correct or not, that's why I ask. If anyone can confirm the formula should yield the correct values then I would look for the error in my implementation. The code example is only to document my approach.  

---

## 1 answers

### Answer by username_2 on 2016-05-27. Score: 1 | Accepted answer

`lat2` = 0 and `lmst` = 0 place the vernal equinox at the zenith, so most points on the ecliptic *should* have azimuth either `obliq` degrees north of east or `obliq` degrees south of west. Try other values for `lat2` or `lmst` and see if the resulting azimuths make sense.

> **Comments:**
> **username_0**: When I try actual data like `lmst` = 184.18° (12h16m); `obliq` = 23.44° to get the azimuth for Venus on May 27th 2016 19 h UT for Berlin (`lat2` = 52.52°; `lon2` = 13.41667°) the function returns 127.38° but the Astronomical Almanac says it should be 307.366°. `δ`, `α` and `h` are according to the Almanac.  
> **username_2**: Aha, the azimuths in your table are also off by 180$^\circ$. Negate both arguments of atan2.  

---

