# Finding original width and height of AABB

I have a rotated rectangle that I don't know the original width and height of. As the current width and height is just the bounding box encapsulating the rectangle, how would I find the actual width and height? I currently have the rotation, bounds of the bounding box, and the center point. Thanks.

-

If the current bounding box is $A$ wide by $B$ high and the original rectangle is $a$ wide by $b$ high, and the rotation angle is $\theta$, we have $B=b |\cos \theta| +a |\sin \theta|, A=a |\cos \theta|+b |\sin \theta|$. These are two equations in two unknowns. For simplicity, let $c=|\cos \theta|, s=|\sin \theta|$ Then the equations become $A=ac+bs, B=bc+as$ We can use substitution to get $$A=ac+bs \\ B=bc+as \\a=\frac 1c(A-bs)\\B=bc+\frac sc(A-bs) \\b=\frac{B-\frac scA}{c-\frac{s^2}c}\\a=\frac{A-\frac scB}{c-\frac{s^2}c}$$

-
Hi, thanks for the response, although it doesn't seem to work for me. I created a test example where I do know the before and after widths and heights and this formula doesn't equate to the known dimensions. –  Calender Man Feb 8 '13 at 21:22
@CalenderMan: Found a couple errors. Give it a try. –  Ross Millikan Feb 8 '13 at 21:27
Hmm, it gets within 1 when using 60 or 30 degrees but using something like 20 or 15 then it ends up being way out. Really appreciate the help, but I think I'll just try to find a way to not need the width and height. Thanks. –  Calender Man Feb 8 '13 at 21:58
@CalenderMan: I tried it with $a=13, b=5, s=\frac 5{13}$ and it was exact. Could you give the values that are a problem? –  Ross Millikan Feb 8 '13 at 22:04
Why is s = 5/13? I was just using s = sin of the angle. –  Calender Man Feb 8 '13 at 22:49