Your work is excellent!
If , both rectangles are squares . . . and all bets are off.
. . Your derived formulas are not needed and do not apply.
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)
Hi, thanks for 1st reply!
For solving this in the general case (using a computer) I've obviously got to avoid the case where @=45, but I really also need to be careful with angles close to 45 because all the maths goes screwy with those tiny divisors! An input angle of 45.0001 is quite possible and will give a divisor of 3.5e-5, obviously the dividend also becomes unusable.
What I would really like is a quick test along the lines of:
Code:if angle < 40 or angle > 50: y = (Sw - Ch) / (SS - CC) else: y = ...