Search code examples
pythonastronomypyephem

Angle between two pairs of azimuth and altitude?


I have a solar panel pointing (it's normal vector) in some direction. I want to calculate the angle between that and the current position of the sun. I am using pyephem and I have this information in two pairs of azimuth and altitude.

panel_az = ephem.degrees('180')
panel_alt = ephem.degrees('45')
sun_az = ephem.degrees('245')
sun_alt = ephem.degrees('22')

What is the easiest way to find the angle between the panel's normal vector and the vector pointing towards the sun?


Solution

  • The library offers a separation() function that gives the angle between two spherical coordinates; look near the bottom of this section of the Quick Reference:

    http://rhodesmill.org/pyephem/quick.html#other-functions

    I think you will get the angle you are seeking if you run:

    a = ephem.separation((panel_az, panel_alt), (sun_az, sun_alt))
    print a
    

    Good luck!