<p>You need to normalize the sidereal time <span class="math-container">$theta0$</span> into the range 0...360 because the second term is hundreds or thousands of days ahead of or behind 2000 Jan 1.5 (JD 2451545.0) multiplied by 360.98.. degrees. (It's basically counting the number of revolutions of the Earth relative to the &quot;fixed&quot; stars). When I renormalize your -1136448.30186661, I get the 71.698 degrees as given in the worked example.</p>
<p>Edit for details of normalization:
I specifically used the <a href="http://star-www.rl.ac.uk/docs/sun67.htx/sun67ss56.html#Q1-60-350" rel="nofollow noreferrer">sla_dranrm</a> routine from the <a href="http://star-www.rl.ac.uk/docs/sun67.htx/sun67.html" rel="nofollow noreferrer">SLALIB</a> astronomy library as that's what I &quot;grew up using&quot;... The underlying code however is not complicated and can be implemented in any language that has a modulus operator, here's a Python example (<code>%</code> is the modulus operator in Python):</p>
<pre><code>def normalize_to_360(value):
    norm_value = value % 360.0
    if norm_value &lt; 0.0:
        norm_value += 360.0
    return norm_value

theta0 = -1136448.30186661
print(normalize_to_360(theta0))
71.69813338993117
</code></pre>

CC BY-SA 4.0
2024-06-04T13:59:02.503Z
Thanks for your answer @astrosnapper, I edited the question with the new value, but can you tell me how did you normalize **_theta0_**? And there is something wrong with **_theta_** value, I think I calculated it Incorrectly because of the **_longitude_** value that used to calculate it (**_theta_**).
Ahmed Dyaa
CC BY-SA 4.0
2024-06-04T17:27:01.903Z
What you have now agrees,  you get tau =-51,  as in the example,  but covert that to 309 since you want a value in the range 0 to 360, by adding 360 degrees, if necessary.  Presumably the rest of the calculation works out.  There's nothing wrong with the theta value.
James K
CC BY-SA 4.0
2024-06-04T20:24:20.507Z
Also it's fairly common to have West longitudes as positive numbers in astronomy so 10deg East is `longitude=-10`. My copy of Meeus is in another country but I remember there being a bit of a rant in a box at the bottom of a page as to why Earth (didn't) needed to be different to the other planet's as to which direction is positive
astrosnapper
CC BY-SA 4.0
2024-06-04T10:12:01.937Z
2024-06-05T09:31:32.277Z
2024-06-05T09:31:32.277Z
astrosnapper
<p>I'm trying to calculate <strong>moon's altitude and azimuth</strong> and I followed this formula by <a href="http://www.geoastro.de/elevazmoon/basics/meeus.htm#jd" rel="nofollow noreferrer">geoastro.de Basics of Positional Astronomy and Ephemerides</a></p>
<p>There is an example to test the formula at the end of the page <a href="http://www.geoastro.de/elevazmoon/basics/index.htm" rel="nofollow noreferrer">geoastro.de Example</a>, I used the same values that ​​used in the example to compare the results of the example.</p>
<p>then I tried to calculate moon's altitude and azimuth with the same values But the results were different from the results of the example.</p>
<p>Is there a mistake in my results or a mistake in the formula itself?
or Are there any resources to help me?</p>
<p><strong>The formula:</strong></p>
<pre><code>1- Julian day = (365.25 * year) + (30.6001 * (month + 1)) - 15 + 1720996.5 + day + hour/24.0


2- T (number of Julian centuries since 2000/01/01 at 12 UT) = (JD - 2451545.0) / 36525.0


3- eps (obliquity of the ecliptic) = 23.0 + 26.0 / 60.0 + 21.448 / 3600.0 - (46.8150 * T + 0.00059 * T * T - 0.001813 * T * T * T) / 3600


4- delta (declination) = (180/PI) * arcsin[sin(eps) * cos(latitude) * sin(longitude) + cos(eps) * sin(latitude)]


5- RA (right ascension) = (180/PI) * arctan[(sin(longitude) * cos(eps) - tan(latitude) * sin(eps)) / cos(longitude)]
if arctan result is lower than zero add (PI) to arctan.


6- theta0 (sidereal time (degrees) at Greenwich) = 280.46061837 + 360.98564736629 * (JD - 2451545.0) + 0.000387933 * T * T - T * T * T / 38710000.0


7- theta (local sidereal time at longitude 10° E) = theta0 + longitude (eastern longitudes positive, western negative).


8- tau (local hour angle) = theta - RA


9- altitude = (180/PI) * arcsin[sin(latitude) * sin(delta) + cos(latitude) * cos(delta) * cos(tau)]


10- azimuth = (180/PI) * arctan2[- sin(tau) / (cos(latitude) * tan(delta) - sin(latitude) * cos(tau))]
</code></pre>
<p><strong>Note:</strong> I converted (eps, delta, RA, tau, latitude, longitude) to radians when it used with (sin, cos, tan).</p>
<p><strong>My results:</strong></p>
<ol>
<li>JD (Julian Day of 1991/ 5/19 at 13 UT) : <strong>2448396.04167 ✔</strong></li>
<li>T (number of Julian centuries since 2000/01/01 at 12 UT) : <strong>- 0.0862137805 ✔</strong></li>
<li>RA (Right ascension) : <strong>133.44° ✔</strong></li>
<li>delta (declination) : <strong>15.53° ✔</strong></li>
<li>theta0 (sidereal time (degrees) at Greenwich): <strong>71.698° ✔</strong></li>
<li>theta (local sidereal time at longitude 10° E): <strong>203.218137662858° ❌</strong></li>
<li>tau (local hour angle): <strong>69.775074599348° ❌</strong></li>
<li>altitude: <strong>18.9153392800018° ❌</strong></li>
<li>azimuth: <strong>-72.880594503826° ❌</strong></li>
</ol>

CC BY-SA 4.0
2024-06-04T17:05:15.873Z
Why do you have X's next to numbers that match?  Also, for the arctan, see if your language supports an "atan2" function that guarantees the answer will be in the correct quadrant.  Otherwise you have to do some quadrant conversions based on the signs of the numerator/denominator.  Also, this algorithm is going to be low precision, good enough for phases and rise and set times. If you want something more accurate have a look at https://github.com/gmiller123456/vsop87-multilang/
Greg Miller
CC BY-SA 4.0
2024-06-04T21:36:22.487Z
results are not the same now, I have edited the question. the previous result I put it by mistake. and I'm using c# so yes it support atan2 and I have edited the formula
Ahmed Dyaa
<the-moon><positional-astronomy><mathematics><algorithm><azimuth>
Wrong results of calculating moon's altitude and azimuth
Ahmed Dyaa
# Wrong results of calculating moon's altitude and azimuth

(Asked by: username_0 on 2024-06-04)

I'm trying to calculate moon's altitude and azimuth and I followed this formula by geoastro.de Basics of Positional Astronomy and Ephemerides
There is an example to test the formula at the end of the page geoastro.de Example, I used the same values that ​​used in the example to compare the results of the example.
then I tried to calculate moon's altitude and azimuth with the same values But the results were different from the results of the example.
Is there a mistake in my results or a mistake in the formula itself?
or Are there any resources to help me?
The formula:
1- Julian day = (365.25 * year) + (30.6001 * (month + 1)) - 15 + 1720996.5 + day + hour/24.0


2- T (number of Julian centuries since 2000/01/01 at 12 UT) = (JD - 2451545.0) / 36525.0


3- eps (obliquity of the ecliptic) = 23.0 + 26.0 / 60.0 + 21.448 / 3600.0 - (46.8150 * T + 0.00059 * T * T - 0.001813 * T * T * T) / 3600


4- delta (declination) = (180/PI) * arcsin[sin(eps) * cos(latitude) * sin(longitude) + cos(eps) * sin(latitude)]


5- RA (right ascension) = (180/PI) * arctan[(sin(longitude) * cos(eps) - tan(latitude) * sin(eps)) / cos(longitude)]
if arctan result is lower than zero add (PI) to arctan.


6- theta0 (sidereal time (degrees) at Greenwich) = 280.46061837 + 360.98564736629 * (JD - 2451545.0) + 0.000387933 * T * T - T * T * T / 38710000.0


7- theta (local sidereal time at longitude 10° E) = theta0 + longitude (eastern longitudes positive, western negative).


8- tau (local hour angle) = theta - RA


9- altitude = (180/PI) * arcsin[sin(latitude) * sin(delta) + cos(latitude) * cos(delta) * cos(tau)]


10- azimuth = (180/PI) * arctan2[- sin(tau) / (cos(latitude) * tan(delta) - sin(latitude) * cos(tau))]

Note: I converted (eps, delta, RA, tau, latitude, longitude) to radians when it used with (sin, cos, tan).
My results:

JD (Julian Day of 1991/ 5/19 at 13 UT) : 2448396.04167 ✔
T (number of Julian centuries since 2000/01/01 at 12 UT) : - 0.0862137805 ✔
RA (Right ascension) : 133.44° ✔
delta (declination) : 15.53° ✔
theta0 (sidereal time (degrees) at Greenwich): 71.698° ✔
theta (local sidereal time at longitude 10° E): 203.218137662858° ❌
tau (local hour angle): 69.775074599348° ❌
altitude: 18.9153392800018° ❌
azimuth: -72.880594503826° ❌

**Tags:** the-moon, positional-astronomy, mathematics, algorithm, azimuth
> **Comments:**
> **username_1**: Why do you have X's next to numbers that match?  Also, for the arctan, see if your language supports an "atan2" function that guarantees the answer will be in the correct quadrant.  Otherwise you have to do some quadrant conversions based on the signs of the numerator/denominator.  Also, this algorithm is going to be low precision, good enough for phases and rise and set times. If you want something more accurate have a look at https://github.com/gmiller123456/vsop87-multilang/  
> **username_0**: results are not the same now, I have edited the question. the previous result I put it by mistake. and I'm using c# so yes it support atan2 and I have edited the formula  

---

## 1 answers

### Answer by username_2 on 2024-06-04. Score: 4 | Accepted answer

You need to normalize the sidereal time $theta0$ into the range 0...360 because the second term is hundreds or thousands of days ahead of or behind 2000 Jan 1.5 (JD 2451545.0) multiplied by 360.98.. degrees. (It's basically counting the number of revolutions of the Earth relative to the "fixed" stars). When I renormalize your -1136448.30186661, I get the 71.698 degrees as given in the worked example.
Edit for details of normalization:
I specifically used the sla_dranrm routine from the SLALIB astronomy library as that's what I "grew up using"... The underlying code however is not complicated and can be implemented in any language that has a modulus operator, here's a Python example (% is the modulus operator in Python):
def normalize_to_360(value):
    norm_value = value % 360.0
    if norm_value < 0.0:
        norm_value += 360.0
    return norm_value

theta0 = -1136448.30186661
print(normalize_to_360(theta0))
71.69813338993117

> **Comments:**
> **username_0**: Thanks for your answer @astrosnapper, I edited the question with the new value, but can you tell me how did you normalize **_theta0_**? And there is something wrong with **_theta_** value, I think I calculated it Incorrectly because of the **_longitude_** value that used to calculate it (**_theta_**).  
> **username_3**: What you have now agrees,  you get tau =-51,  as in the example,  but covert that to 309 since you want a value in the range 0 to 360, by adding 360 degrees, if necessary.  Presumably the rest of the calculation works out.  There's nothing wrong with the theta value.  
> **username_2**: Also it's fairly common to have West longitudes as positive numbers in astronomy so 10deg East is `longitude=-10`. My copy of Meeus is in another country but I remember there being a bit of a rant in a box at the bottom of a page as to why Earth (didn't) needed to be different to the other planet's as to which direction is positive  

---

