where the green polygon is the rotated polygon and the purple is the extent of the polygon.
Is there a way to calculate the angle of rotation of the green polygon from the extent?
I am using python to do this as well, so if you have it in python code, that would be helpful too, but not needed.
I created the following code:
def distance(ptA, ptB):
""" calculates theta """
diffX = math.pow((ptB[0] - ptA[0]), 2)
diffY = math.pow((ptB[1] - ptA[1]), 2)
return math.sqrt((diffX + diffY))
def theta(p1, p2, p3):
"""
"""
radians = math.atan((distance(ptA=p2, ptB=p3)/distance(ptA=p1, ptB=p3)))
degree = radians * 360 / math.pi
return degree
p1,p2, and p3 are [X,Y] pairs.
Now I am using the following point:

The result doesn't seem to be the correct rotation value. Any suggestions?
Thank you

When the angles are 90 degrees.
Make sure that the left bottom co-ordinate is $(0,0)$.
Then you have $(x,0)$ and $(0,y)$ to form a triangle.
Then you have
thus
When you have arbitrary points of the triangle, say
$$ (x_0,y_0), \quad (x_1,x_1), \quad (x_2,y_2) $$
you have
thus
For the adjusted image.
Let
Then