How does one find the coordinates of the 4 corners of a bounding box of a square of width w
and height h
that is rotated theta
degrees and is offset from the origin x
in the x direction and y
in the y direction?
Here is a visual example of what I mean:
Here is some python3 code that I came up with, but it only works in the right quadrants except when theta = 0 or 360 or etc.:
import math
def bounds(x,y,w,h,theta):
theta = theta * math.pi / 180
A = ( x, y+round((math.sin(theta)*w), 2) )
B = ( x+round((w/math.sin(theta)), 2), y+round((math.sin(theta)*w), 2) )
C = ( x+round((w/math.sin(theta)), 2), y+round((math.cos(theta)*h), 2) )
D = ( x, y+round((math.cos(theta)*h), 2) )
print(A)
print(B)
print(C)
print(D)
I was reading this but I could not figure it out for my specific problem.
Any help is much appreciated. Next time I will use matrices to store all the transformation data because this would be so much easier that way.