[Tutor] Angles

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Wed Nov 29 10:47:59 CET 2006


Carlos schreef:
> 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
> 
> My python code for this particular equation:
> 
> from math import *
> 
> def Az(Lat, Dec, H_Ang):
> 
>         lat_r     = radians(Lat)
>         decl_r     = radians(Dec)
>         hour_r  = radians(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?

I think the problem is with the atan() function: you divide x_azm by 
y_azm, which makes you lose the signs. There is an alternative, the 
atan2() function, which takes two parameters. Therefore it can use the 
signs of both x_azm and y_azm to work out the correct quadrant. So I'd try:

         Azimuth = degrees(atan2(x_azm, y_azm))


-- 
If I have been able to see further, it was only because I stood
on the shoulders of giants.  -- Isaac Newton

Roel Schroeven



More information about the Tutor mailing list