Calculating Rotation from centroid I have a polygon as such:

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

Rotated from what?  Are we to assume that the lower left edge of the rectangle was initially at or parallel to the lower edge of the "extent"?  If so then:
Set up a coordinate system with $(0, 0)$ at the lower left corner of the "extent", the $x$-axis along the lower edge, and the y-axis along the left edge.  Let the $x$-coordinate where the rectangle touches the lower edge be $x_0$ and the $y$-coordinate where the rectangle touches the left edge be $y_0$.  Then angle is given by $\operatorname{arccot}\left(\frac{y_0}{x_0}\right)$.
