 View Question
Q: Formula for fitting a smaller, rotated rectangle inside a bigger rectangle ( No Answer,   12 Comments ) Question
 Subject: Formula for fitting a smaller, rotated rectangle inside a bigger rectangle Category: Science > Math Asked by: joshuac-ga List Price: \$20.00 Posted: 07 Oct 2006 04:42 PDT Expires: 06 Nov 2006 03:42 PST Question ID: 771496
 ```Hi, let's say I have a rectangle, 10 by 20. I wish to be able to fit a smaller rectangle inside it, at an angle, with the 4 corners of the smaller rectangle touching the 4 sides of the larger rectangle. I have the following information: -Length of the larger rectangle -Width of the larger rectangle -Width of the smaller rectangle From this information I would like to find: -Length of the smaller rectangle -"Coordinates" locating the corners of the smaller rectangle on the sides of the larger rectangle Sorry my description is odd and using simplistic language, it's 4am and not my area of expertise at all :) A simplified real world example: Large Rectangle Length and Width == 1 (a square) Small Rectangle Length == 0.707106781 Defining the corners of the larger rectangle as a,b,c,d I would know the the small rectangle corners would intersect the large rectangle in this example at .5 from a,b,c, or d (since the bigger rectangle is a aquare in my example and my smaller rectangle is rotated 45 degrees in my example the distance of a,b,c,d from a,b,c,d of the larger rectangle are all the same). With my limited knowledge of geometry I thought perhaps a lead was to break the smaller rectangle into two right triangles and calculate it that way; I didn't get very far. Again, sorry my language in describing this is so bad. Feel free to ask any questions for clarification.``` There is no answer at this time. Subject: Re: Formula for fitting a smaller, rotated rectangle inside a bigger rectangle From: harrysnet-ga on 07 Oct 2006 11:31 PDT
 ```There are infinitely many solutions to the problem, as you describe it. The problem is that you don't know how to 'fit' your given width to the two rectangle sides. To use your example you don't have to place the smaller side that you give exactly in the middle of the two points it can be (say) at position 0.4 in line ab, closer to a. Then it would touch (ad) at point .5831 from a to d (that is it is closer to d). Unless you specify where it touches you can't have a specific answer.```
 Subject: Re: Formula for fitting a smaller, rotated rectangle inside a bigger rectangle From: myoarin-ga on 08 Oct 2006 06:56 PDT
 ```I disagree with the above. The definition of the dimensions of the outer rectangle and the width of the inscribed rectangle give a unique solution. Let the length and width of the outer rectangle be A and B, and the width and length of the inscribed rectangle be W and L. The corners of the inscribed rectangle will touch the outer one at points that that make a smaller triangle, the hypotenuse of which has the length W. Let's call the other sides "a" and "b", being portions of A and B. These two triangles will have the same proportions as the the larger triangles with sides L, A-a, B-b. From Pythagoras: 1: A-a/B-b = b/a 2: W^2 = a^2 + b^2 3: L^2 = (A-a)^2 + (B-b)^2 And the sum of the area 4: AB = (A-a x B-b) + ab + LW Shouldn't it be possible to solve for a, b and L with these equations?```
 Subject: Re: Formula for fitting a smaller, rotated rectangle inside a bigger rectangle From: harrysnet-ga on 08 Oct 2006 14:29 PDT
 ```Well, myoarin you are right. The relations you derive make perfect sense, and should all be true. In order to avoid confusing joshuac I should say that the construction I gave, placing the W line arbitrarily as a first step, produces a parallelogram, and not necessarilly a rectangle (a parallelogram is a sort of tilted rectangle, with pairs of sides being parallel, but the angles are not necessarily right). With the relations that myoarin gave it is possible to solve the problem easily. First relations 1 and 2 can be used to solve for a and b, and then relation 3 can solve for L (there are probably some conditions on A, B and W, so that a, b and L come out as positive integers). Relation 4 must also be true, so it must somehow follow from the other three using algebra, but I cannot see how, as the relations get complicated really fast sincve they are not linear. Maybe someone else can see how to do that. In any case sorry joshuac, that my comment pointed in the wrong direction. The answer seems to exist, in the direction myoarin indicated.```
 Subject: Re: Formula for fitting a smaller, rotated rectangle inside a bigger rectangle From: myoarin-ga on 08 Oct 2006 14:55 PDT
 ```Thanks, Harry. I'm fine on simple geometry, but copped out on the algebra. ;-) Myoarin```
 Subject: Re: Formula for fitting a smaller, rotated rectangle inside a bigger rectangle From: berkeleychocolate-ga on 10 Oct 2006 20:01 PDT
 ```Continuing the development of myoarin above, let theta be the angle between the hypotenuse of length w and the side of length a in the triangle he refers to. Then theta appears in several other places in the figure. It is not hard to see that [A - w*cos(theta)]/sin(theta) and [B - w*sin(theta)]/cos(theta) both represent the length L we want to find. Setting these two expressions equal we get an equation for theta (and so for L). Let x = sin(theta) and so sqrt(1-x^2)=cos(theta). Eliminating all the radicals, we get a 4th degree equation in x. There are formulas for the general equation of degree 4, but they are messy. The equation I got was: 4w^2*x^4 - 4 A w x^3 + (A^2 + b^2 - 4w^2) x^2 + 2a w x + w^2 - b^2 = 0.```
 Subject: Re: Formula for fitting a smaller, rotated rectangle inside a bigger rectangle From: berkeleychocolate-ga on 10 Oct 2006 21:40 PDT
 ```Correction to the formula I gave above: 4w^2*x^4 - 4*A*w*x^3 + (A^2 + B^2 - 4w^2)*x^2 + 2*A*w*x + w^2 - B^2 = 0.```
 Subject: Re: Formula for fitting a smaller, rotated rectangle inside a bigger rectangle From: myoarin-ga on 11 Oct 2006 04:22 PDT
 ```Berkeley, Theta is only known after we have the length of L - and also a or b - so that we can place the inscribed rectangle correctly. Cheers, Myoarin```
 Subject: Re: Formula for fitting a smaller, rotated rectangle inside a bigger rectangle From: berkeleychocolate-ga on 11 Oct 2006 11:08 PDT
 ```Myoarin, The formula I presented gives theta as a function of the three known lengths: A, B and w. The unknown L is a simple function of theta, also presented above. (Actually each is a function of the other.) Find theta according to the formula and then find L. So I don't agree that "theta is only known after we have L".```
 Subject: Re: Formula for fitting a smaller, rotated rectangle inside a bigger rectangle From: myoarin-ga on 11 Oct 2006 13:35 PDT
 ```Sorry, Berkeley, I stand corrected. Congratulations! Myoarin```
 Subject: Re: Formula for fitting a smaller, rotated rectangle inside a bigger rectangle From: mathtalk-ga on 13 Oct 2006 06:08 PDT
 ```A few geometric observations about what dimensions of the smaller rectangle are feasible, given dimensions L x W of the larger rectangle. Let the "larger" rectangle be centered at the origin, sides parallel to the coordinate axes, say with length L in the x-direction greater than (or equal to) width W in the y-direction. The four corners of this rectangle are then: (�L/2,�W/2) and they lie on a circle of radius R = SQRT(L�+W�)/2 centered at the origin. The "smaller" rectangle will also be centered at the origin, though without sides parallel to the coordinate axes. Its radius r must be less than or equal to R, but at least L/2 in order for the corners of the smaller rectangle to touch each of the four sides of the larger rectangle. When L/2 < r < R the circle of radius r at the origin intersects the larger rectangle in eight points. Any opposing pair of points (symmetric wrt the origin) forms a diameter of the circle, and any two of these diameters can be taken as diagonals of a smaller rectangle. Provided that the two diagonals intersect different pairs of opposing sides of the larger rectangle, we get a smaller rectangle "on an angle" to the larger one, as desired. Thus for radius r strictly between L/2 and R, we get four different smaller rectangles, which correspond by symmetry to two different possible smaller widths (if by width we mean the lesser of the smaller rectangle's dimensions). The eight points are these: (�u,�W/2) and (�L/2,�v) where u = SQRT(r� - W�/4) and v = SQRT(r� - L�/4). The two possible smaller widths w are then: w = dist( (L/2,v),(u,W/2) ) OR dist( (L/2,v),(u,-W/2) ) There is the limiting case when r = L/2 when the circle is tangent to one pair of sides of the larger rectangle. Then w takes only one value as v = 0, and the two distances above are the same: u = SQRT(L� - W�)/2 w = SQRT( (L/2 - u)� + (W/2)� ) But this doesn't give a lower bound for the width of the smaller rectangle. Instead the widths for cases L/2 < r < R exist as one value above this and one value below it. Thus any "smaller" width w is feasible between 0 and W. regards, mathtalk-ga```
 Subject: Re: Formula for fitting a smaller, rotated rectangle inside a bigger rectangle From: myoarin-ga on 13 Oct 2006 07:26 PDT
 ```Yes, well, that seems almost too obvious, just a bit complicated in "mathspeak". Can't someone solve the equations for L?```
 Subject: Ferrari's method: solving the quartic equation From: mathtalk-ga on 04 Nov 2006 17:43 PST
 ```Ferrari's method: solving the quartic equation ============================================== Wikipedia has a good article here: [Quartic equation -- Wikipedia] http://en.wikipedia.org/wiki/Quartic_equation We will present a tailored treatment of the present problem with an overriding aim of keeping algebraic expressions as simple as possible. As we shall see, the gist of Ferrari's method is almost as elementary as completing the square is in the context of solving the general quadratic. However the method requires the solution of a cubic equation as an intermediate step, much as Cardano's solution to the cubic equation requires solving an auxiliary quadratic equation. Formulation of the quartic equation =================================== Let the larger rectangle be centered at the origin with sides parallel to the axes. Vertices will be of the form (�a,�b). Without loss of generality, we may scale the rectangle so that b = 1 and choose an orientation so that a > 1, provided the width w which we seek to impose on the smaller rectangle is also scaled (divide all linear dimensions by b). Width w is bounded above by the diagonal length of the larger rectangle, 2 sqrt(a^2 + 1). The smaller rectangle is here understood to have a vertex incident with each side of the larger, so let these vertices be (x,1), (a,y), (-x,-1), (-a,-y), where: -a < x < a and -1 < y < 1  The symmetry of the smaller rectangle's vertices with respect to the origin may be deduced from the larger rectangle's vertices and the equal length of parallel sides of the smaller rectangle. The diagonals of any rectangle are equal in length and mutually bisecting. As applied to the smaller rectangle this means: x^2 + 1 = y^2 + a^2  since its diagonals intersect at the origin. We may assume that the side from (x,1) to (a,y) has length w. For if instead (-x,-1) to (a,y) were of the prescribed length, then reflecting the smaller rectangle in the x-axis would redress this. Thus: (x - a)^2 + (y - 1)^2 = w^2  Together the inequalities , the hyperbola , and the circle  determine the existence of a solution (x,y) generating the smaller rectangle for specified parameters a and w. While  and  may be used directly to eliminate one variable and give a resulting quartic equation for the other, the form of the expressions will be significantly simpler if we restate the problem in terms of two new variables: u = x + y and v = x - y  In particular we can revise  as follows: uv = x^2 - y^2 = a^2 - 1  Furthermore  can always be inverted to provide the corresponding values of x,y from u,v: x = (u + v)/2 and y = (u - v)/2  so that  can be rewritten and simplified to: / u+v \^2 / u-v \^2 ( --- - a ) + ( --- - 1 ) = w^2 \ 2 / \ 2 / (u - (a+1))^2 + (v - (a-1))^2 = 2w^2  Multiplying both sides by u^2 and applying , we get the following quartic equation for u: (u^2 - (a+1)u)^2 + (uv - (a-1)u)^2 = 2w^2*u^2 u^4 - 2(a+1)u^3 + 2(a^2 + 1 - w^2)u^2 - 2(a-1)(a^2 - 1)u + (a^2 - 1)^2 = 0  We now come to Ferrari's idea of expressing the quartic equation P(u) = 0 as the difference of two perfect squares, P(u) = Q(u)^2 - L(u)^2, with Q(u) second-order & L(u) first-order polynomials. This factors P(u) = (Q(u) + L(u))(Q(u) - L(u)) and consequently reduces the problem to solving a pair of quadratic equations. It is the constant term of Q(u) which gives rise to the "nested" cubic equation we want to solve: Q(u) = u^2 - (a+1)u + d  as the leading terms of Q(u) are dictated by . Now from: Q(u)^2 = u^4 - 2(a+1)u^3 + ((a+1)^2 + 2d)u^2 - 2d(a+1)u + d^2 subtract zero as expressed by LHS of : Q(u)^2 = (2d - (a-1)^2 + w^2)u^2 - 2(a+1)(d - (a-1)^2)u + d^2 - (a^2 - 1)^2 For the trinomial on the right hand side to be a perfect square L(u)^2 requires that the product of the leading coefficient and the constant term be the square of half the middle coefficient. Thus: (2d - (a-1)^2 + w^2)(d^2 - (a^2 - 1)^2) = (a+1)^2(d - (a-1)^2)^2 Collecting terms gives us a cubic equation in d: 2d^3 + (w^2 - 2(a^2+1))d^2 - (a^2 - 1)^2 w^2 = 0  in which helpfully the d term already has a zero coefficient. Note that whatever the sign of the d^2 coefficient, by Descartes' Rule of Signs there will be exactly one positive root d of eqn. . In my next post I will apply Cardano's method for solving such a cubic. regards, mathtalk-ga``` 