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?

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?

$$ 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} $$
The solution of Jiri results in negative sizes for angles in the third and fourth quadrant.
This calculation, using the absolute sine and cosine values, works for all angles:
$$ wh(d) = h \; |\cos(d)| + w \; |\sin(d)| $$
$$ ww(d) = h \; |\sin(d)| + w \; |\cos(d)| $$