Firstly, math
has a convenient function atan2(denominator, numerator)
. Usually you use atan2(dy,dx)
, but since Pygame flips the y axis relative to the Cartesian coordinates (as you know), you need to make dy
negative and then avoid negative angles. ("dy" simply means "change y".)
from math import atan2, degrees, pi dx = x2 - x1 dy = y2 - y1 rads = atan2(-dy,dx) rads %= 2*pi degs = degrees(rads)
degs
should be what you are looking for.
source share