Rotating a rectangle

Lets say we have a rectangle with height h and width w. If we rotate it by d degrees, what would be the width and height of the window to display it without any clipping? I mean what is the formula to calculate wh and ww?

• How much trigonometry do you know? Do you know how to calculate the short sides of a right-angled triangle given the length of the hypotenuse and one of the acute angles? That's all you need here (after you split $ww$ and $wh$ into their two parts). Jul 2 '11 at 12:16
• Looking at the picture, $wh$ would be $w \sin(d) + h \cos(d)$. This holds when $0^\circ \le d \le 90^\circ$. Jul 2 '11 at 12:17
• @TonyK - Next to none ;) Jul 2 '11 at 12:18
• @J.J. - Thanks. Why don't you put that as an answer? Jul 2 '11 at 12:21
• @Majid: Someone else might, I'm a bit busy. And it's not complete: You got to be careful if $d$ doesn't lie in the range I gave. I suspect there will be four cases. Jul 2 '11 at 12:31

$$wh(d) = \begin{cases} h \cos(d) + w \sin(d), & \mbox{if} \;\; 0^\circ \le d \le 90^\circ \;\; \mbox{or} \;\; 180^\circ \le d \le 270^\circ \;\; \\ w \cos(d-90) + h \sin(d-90), & \mbox{if} \;\; 90^\circ \le d \le 180^\circ \;\; \mbox{or} \;\; 270^\circ \le d \le 360^\circ \;\; \end{cases}$$
$$ww(d) = \begin{cases} h \sin(d) + w \cos(d), & \mbox{if} \;\; 0^\circ \le d \le 90^\circ \;\; \mbox{or} \;\; 180^\circ \le d \le 270^\circ \;\; \\ w \sin(d-90) + h \cos(d-90), & \mbox{if} \;\; 90^\circ \le d \le 180^\circ \;\; \mbox{or} \;\; 270^\circ \le d \le 360^\circ \;\; \end{cases}$$
$$wh(d) = h \; |\cos(d)| + w \; |\sin(d)|$$
$$ww(d) = h \; |\sin(d)| + w \; |\cos(d)|$$