# [Tutor] Angles

Carlos carloslara at web.de
Tue Nov 28 22:59:06 CET 2006

```Hello to All:

I'm trying to write a sun positioning system with the help of python.
The idea is that you give the program a location, date and hour and it
returns the position of the sun.

I found a webpage that details the math behind this
(http://www.usc.edu/dept/architecture/mbs/tools/vrsolar/Help/solar_concepts.html)
, it was fairly trivial to translate this to python until I got to the
azimuth equation. It looks like this:

x_azm 	= sin(hour_R) * cos(decl_R)
y_azm 	= (-(cos(hour_R))*cos(decl_R)*sin(lat_R))+(cos(lat_R)* sin(decl_R))
azimuth	= atan(x_azm/y_azm)*TODEGREE

where:

Alt 		= Altitude
Azm 		= Azimuth
Decl 		= Declination
HAngle 		= Hour angle
hour_R 		= Hour angle in radians
x_azm 		= x component of azimuth
y_azm 		= y component of azimuth
TODEGREE 	= Constant equal to 180/p

My python code for this particular equation:

from math import *

def Az(Lat, Dec, H_Ang):

x_azm     = sin(hour_r) * cos(decl_r)
y_azm     = (-(cos(hour_r)) * cos(decl_r) * sin(lat_r)) +
(cos(lat_r) *  sin(decl_r))

Azimuth    = degrees(atan(x_azm/y_azm))
Azimuth = Azimuth *(-1)
return Azimuth

I was never very good at trigonometry, but looks like my translation of
the equation is ok and the problem is some kind of python behavior,
because whenever the results exceed 100° (deg) Python returns the
complementary angle, it is possible to avoid this? Or I'm overlooking
somethig?

You can check this by yourself:

If you use Az(34, -21.67, -150) you will get 72.79, the result in the
webpage tool will be 107.21. And 72.79 + 107.21 = 180
but if you use Az(34, -21.67, -150) you will get 54.88 in both, my
script and the webpage tool.

If you want to take a look at the webpage tool this is the link:
http://www.usc.edu/dept/architecture/mbs/tools/vrsolar/frameset.html