<p>I have the answer to your question, in case you have not already worked it out! You have used the wrong value for the Longitude of the Sun in your calculation of GMST0. You used the Ecliptic Longitude,
lonsun = v + w  (using the symbols on the tutorial website you mentioned)
but you need the Sun's mean longitude,
Ls = M + w</p>
<p>It so happens that I had already written a program based on the tutorial you mentioned: <a href="http://www.stjarnhimlen.se/comp/ppcomp.html" rel="nofollow noreferrer">http://www.stjarnhimlen.se/comp/ppcomp.html</a> and have used it to check the results for your example. Using 'lonson' gives values very close to what you got:</p>
<p>Altitude = +26deg 33min 16sec,  Azimuth = 16hrs 35min 16sec = 248deg 49.0min</p>
<p>but using the correct 'Ls' gives the following results:</p>
<p>Altitude = +25deg 24min 57sec,  Azimuth = 16hrs 41min 24sec = 250deg 21.0min</p>
<p>which are very close to the Stellarium values.</p>
<p>Finally I must say that, in spite of the comments in previous answers, I would highly recommend that tutorial website, and get pretty accurate results using all of its calculation methods.</p>

CC BY-SA 4.0
2024-02-02T18:58:34.607Z
Wow, I did not expect someone to bother finding the solution to my problem over 5 years later, thank you!
Michael S
CC BY-SA 4.0
2024-01-29T12:36:03.720Z
2024-01-29T12:36:03.720Z
John H
<p>The algorithm on that page is very simplistic and is probably the source of a good portion of that error.  It's best to test your code using a very accurate ephemeris, even if your final goal is to have a much more simple ephemeris implementation.  DE405, or VSOP87 would be good alternatives.</p>

<p>A small error in GMST can have a big effect on Alt/Az computations, I would expect that the simplicity of the algorithm on the page produces a good sized error in GMST.</p>

<p>Another common source of error is differences in time scales.  You need to make sure you propperly account for things like leap seconds, which that page specifically says it ignores.  You need to convert UTC to Terrestrial Time by subtracting 37.0 + 32.184 (where 37 is the current number of leap seconds).</p>

<p>Also make sure you're not comparing different coordinate systems.  Like J2000 vs "Of Date", or coordinates adjusted for atmospheric refraction.</p>

CC BY-SA 4.0
2019-08-19T05:17:19.030Z
2019-08-19T05:17:19.030Z
Greg Miller
<p>I wrote a program based on this tutorial: <a href="http://www.stjarnhimlen.se/comp/ppcomp.html" rel="nofollow noreferrer">http://www.stjarnhimlen.se/comp/ppcomp.html</a> to calculate altitude and azimuth of a celestial object. When I compare the calculated RA/Dec values to the ones from Stellarium, they are very accurate. But when I compare the Alt/Az values to the ones from Stellarium, there is an error of about 2 degrees! I use the following method to calculate Alt, Az:</p>

<pre><code>GMST0 = Ls + 180_degrees # Ls = Sun's longitude
GMST = GMST0 + UT
LST  = GMST + local_longitude
HA = LST - RA

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) )
</code></pre>

<p><strong>Some specific example:</strong></p>

<p>Test date 15.09.2018, time 15:00 UT
Planet: Mercury</p>

<p>Coordinates: +47.55777777° +8.89888888</p>

<p><strong>What stellarium says:</strong></p>

<p>RA = 11h 18m 13.26s</p>

<p>Dec = +6°25'08.5"</p>

<p>Az = +250°21'13.2"</p>

<p>Alt = +25°25'00.1"</p>

<p><strong>What my program says:</strong></p>

<p>RA = 11h 18m 14s</p>

<p>Dec = 6° 25' 6.59"</p>

<p>Az = +248° 49' 6.9"</p>

<p>Alt = +26° 33' 16.43"</p>

<p>Thanks in advance!</p>

CC BY-SA 4.0
2018-09-15T14:42:44.087Z
The 2 degree error is not consistent, it's just the maximum error, but a lot of calculations (especially azimuth) were off by about 2°. I'll edit the question with some specific examples.
Michael S
CC BY-SA 4.0
2018-09-19T15:43:34.713Z
It says "Precession is computed in a simplified way, by a simple addition to the ecliptic longitude" on the website.
Michael S
CC BY-SA 4.0
2018-09-19T18:08:32.887Z
An interesting thing is that the azimuth always is about 1.5° under the expected value, except for the moon.
Michael S
<positional-astronomy><azimuth>
Error when calculating Alt/Az from Ra/Dec
Michael S
# Error when calculating Alt/Az from Ra/Dec

(Asked by: username_0 on 2018-09-15)

I wrote a program based on this tutorial: http://www.stjarnhimlen.se/comp/ppcomp.html to calculate altitude and azimuth of a celestial object. When I compare the calculated RA/Dec values to the ones from Stellarium, they are very accurate. But when I compare the Alt/Az values to the ones from Stellarium, there is an error of about 2 degrees! I use the following method to calculate Alt, Az:
GMST0 = Ls + 180_degrees # Ls = Sun's longitude
GMST = GMST0 + UT
LST  = GMST + local_longitude
HA = LST - RA

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) )

Some specific example:
Test date 15.09.2018, time 15:00 UT
Planet: Mercury
Coordinates: +47.55777777° +8.89888888
What stellarium says:
RA = 11h 18m 13.26s
Dec = +6°25'08.5"
Az = +250°21'13.2"
Alt = +25°25'00.1"
What my program says:
RA = 11h 18m 14s
Dec = 6° 25' 6.59"
Az = +248° 49' 6.9"
Alt = +26° 33' 16.43"
Thanks in advance!

**Tags:** positional-astronomy, azimuth
> **Comments:**
> **username_0**: The 2 degree error is not consistent, it's just the maximum error, but a lot of calculations (especially azimuth) were off by about 2°. I'll edit the question with some specific examples.  
> **username_0**: It says "Precession is computed in a simplified way, by a simple addition to the ecliptic longitude" on the website.  
> **username_0**: An interesting thing is that the azimuth always is about 1.5° under the expected value, except for the moon.  

---

## 2 answers

### Answer by username_1 on 2024-01-29. Score: 3 | Accepted answer

I have the answer to your question, in case you have not already worked it out! You have used the wrong value for the Longitude of the Sun in your calculation of GMST0. You used the Ecliptic Longitude,
lonsun = v + w (using the symbols on the tutorial website you mentioned)
but you need the Sun's mean longitude,
Ls = M + w

It so happens that I had already written a program based on the tutorial you mentioned: <http://www.stjarnhimlen.se/comp/ppcomp.html> and have used it to check the results for your example. Using 'lonson' gives values very close to what you got:

Altitude = +26deg 33min 16sec, Azimuth = 16hrs 35min 16sec = 248deg 49.0min

but using the correct 'Ls' gives the following results:

Altitude = +25deg 24min 57sec, Azimuth = 16hrs 41min 24sec = 250deg 21.0min

which are very close to the Stellarium values.

Finally I must say that, in spite of the comments in previous answers, I would highly recommend that tutorial website, and get pretty accurate results using all of its calculation methods.

> **Comments:**
> **username_0**: Wow, I did not expect someone to bother finding the solution to my problem over 5 years later, thank you!  

---

### Answer by username_2 on 2019-08-19. Score: 3

The algorithm on that page is very simplistic and is probably the source of a good portion of that error. It's best to test your code using a very accurate ephemeris, even if your final goal is to have a much more simple ephemeris implementation. DE405, or VSOP87 would be good alternatives.

A small error in GMST can have a big effect on Alt/Az computations, I would expect that the simplicity of the algorithm on the page produces a good sized error in GMST.

Another common source of error is differences in time scales. You need to make sure you propperly account for things like leap seconds, which that page specifically says it ignores. You need to convert UTC to Terrestrial Time by subtracting 37.0 + 32.184 (where 37 is the current number of leap seconds).

Also make sure you're not comparing different coordinate systems. Like J2000 vs "Of Date", or coordinates adjusted for atmospheric refraction.


---

