# Rotated rectangle

• Apr 22nd 2008, 07:42 AM
dave.lawrence
Rotated rectangle
Dear Forum,

Hoping someone can help me with a little trig and geometry

In the attached pic the grey rectangle has been rotated by @ degrees, the red dotted box is then constructed around it to exactly enclose it.

given the dimensions of the bounding box and the angle of rotation, I want to calucate the size of the original rectangle (and hence its coordinates)

i.e. given w, h and @, what are x, y (and therby a, b, c, d)?

sin @ = c / x = b / y = S
cos @ = a / x = d / y = C
tan @ = c / a = b / d = T

w = a + b
y = c + d

=>

w = xC + yS
x = (w - yS) / C

h = xS + yC
x = (h - yC) / S

=>

(w - yS) / C = (h - yC) / S
S(w - yS) = C(h-yC)
Sw - ySS = Ch - yCC
Sw - Ch = ySS - yCC
Sw - Ch = y(SS - CC)
y = (Sw - Ch) / (SS - CC)

The problem is that at @=45, SS-CC is 0!

So I've trying to find an alternative method of representing this equation.

plotting y against @ for 0-90 degrees, gives the graph in graph.png - which shows a nice smooth curve but with the asymptotic problem at 45 degrees.

Would be quite happy with an equivalent but alternate solution which works well for say, angles < 30 and > 60. (which is what i'm expecting, i.e. some equation dividing by sin or cos, given the /0 at 0 or 90degrees)

Thank you!
• Apr 22nd 2008, 09:14 AM
Soroban
Hello, Dave!

If $\theta = 45^o$, both rectangles are squares . . . and all bets are off.
. . Your derived formulas are not needed and do not apply.

$\text{We would have: }\;w \,= \,h\,\text{ and }\,x \,=\, y \,=\, \frac{w}{\sqrt{2}}$

• Apr 22nd 2008, 09:58 AM
dave.lawrence
if angle < 40 or angle > 50:   y = (Sw - Ch) / (SS - CC) else:   y = ...