# How to calculate phase angle of a satellite?

I'm making a program for predicting satellite passes. I'm trying to find out if the satellite is illuminated by the Sun and not in Earth's shadow. I need to know its phase angle: the angle between the observer on Earth, the satellite and the Sun.

Please explain it in simple terms if possible.

(Inserted by reviewer, extension to question, posted originally as answer)

I have TLE data for the satellite (contains right ascension). From that I got ECI position, azimuth, elevation, altitude. For observer I have latitude and longitude and for the sun: elevation and azimuth.

You have horizontal coordinates for both bodies so the easiest way to go from there would be to look at the spherical triangle Zenith-Sun-Sat, the angle at zenith will be the difference between azimuths, and the Zenith-Sun and Zenith-Sat lengths will be $$90^{\circ}-h_{Sun}$$ and $$90^{\circ}-h_{Sat}$$, respectively. Now using the cosine formula for spherical triangles, one may obtain the following formula:
$$cos^{−1}(sin(h_{Sun})sin(h_{Sat})+cos(h_{Sun})cos(h_{Sat})cos(A_{Sun}−A_{Sat}))$$.
Now use the sine theorem to find the angle E-Sun-Sat (the sine of this angle divided by the sine of the one we calculated will be equal to the ratio of distances from the Earth to the satellite, and from the satellite to the Sun, respectively), and to find the third angle, subtract the two from $$180^{\circ}$$.