I have no idea why I needed to solve this problem. But I did, and for about an hour (and then a day later, four more hours...) I could focus on nothing else. This is the question: you have a specific triangle, no unknown factors about it. What is the largest rectangle you can inscribe within that triangle? The first instinct might be to say it's one that has an edge parallel to one side of the triangle, but to my analysis, that's not the case.

Looking at the problem, I wanted to be able to completely specify any rectangle within the triangle, and derive a function for its area in as few free parameters as possible. Starting with the understanding that we'll need at least one (though actually at least three, but we'll start with one) corner of the rectangle on a side of the triangle, we'll make the position of that point one of our determining variables. Call it x, distance from a chosen vertex of the triangle. To make computation more clean, let's pick for a given rectangle a corner which is adjacent to two other corners which touch the triangle.

Looking at the problem, I wanted to be able to completely specify any rectangle within the triangle, and derive a function for its area in as few free parameters as possible. Starting with the understanding that we'll need at least one (though actually at least three, but we'll start with one) corner of the rectangle on a side of the triangle, we'll make the position of that point one of our determining variables. Call it x, distance from a chosen vertex of the triangle. To make computation more clean, let's pick for a given rectangle a corner which is adjacent to two other corners which touch the triangle.

One thing we quickly notice is that we've not actually fully determined the rectangle yet, because the axis of the corner can be rotated to change where the sides intersect the edges of the triangle. We add a second parameter, ϴ, the inclination from the side to which the point is tied to the 'lower' side of the rectangle. If we then imagine constructing out perpendicular lines from the intersections of the previously drawn lines to the triangle:

Then we can see that we've managed, with the two parameters x and ϴ, and the constraint that the inner shape is a rectangle, to specify exactly an inscribed rectangle. Consequently, if we can write an expression for the area of such a rectangle, given x, ϴ, and the dimensions of the triangle, we need only to find a maxima in x and ϴ to have found the largest such rectangle.

When I approached this problem the first time, I was strongly inclined to use vectors to find the intersection points, but I quickly realized it was much easier to employ classical geometry. Let's set some x and ϴ abstractly within a triangle, and compute the area of the resultant rectangle.

Actually, let's label the triangle first, otherwise I'll start throwing out expressions and equations and things and it won't make a bit of sense until I clarify. So let's clarify before any of that:

When I approached this problem the first time, I was strongly inclined to use vectors to find the intersection points, but I quickly realized it was much easier to employ classical geometry. Let's set some x and ϴ abstractly within a triangle, and compute the area of the resultant rectangle.

Actually, let's label the triangle first, otherwise I'll start throwing out expressions and equations and things and it won't make a bit of sense until I clarify. So let's clarify before any of that:

x and ϴ are, naturally, our independent variables. l1 and the ϕs are known at the outset- they define the triangle. r1 and r2, as well as the γ, are unknown. We want to determine the r as the area, A is given by A = r1∙r2. We'll use the γ to find the r by proxy.

We're going to start with r1, since it's the most accessible side (we have the most information pertaining to it, anyway). Using the law of sines, we have:

We're going to start with r1, since it's the most accessible side (we have the most information pertaining to it, anyway). Using the law of sines, we have:

Which is just a direct insertion of known parameters. Directly, we we can compute the side from this:

Next up we need to get r2, but we have less in the way of angles to work with. So we're gonna use the γ to represent the other angles:

Not strictly necessary, but radically preferable to keeping track of it all at the outset.

From there, we can use the law of sines again to get an expression for r2:

From there, we can use the law of sines again to get an expression for r2:

Then, rearranging, we have the two expressions for the r:

Which, naturally, we throw right into the formula for the area of the rectangle:

Which turns out to be pretty clean- you'll notice that x and ϴ are separable under multiplication, which will be very important shortly. To keep everything relatively well organized, we're going to combine trigonometric functions and group constants under a few new variables: α β γ

Now, in this much more handy form, we'll set out to find the maximum area, by taking derivatives in the normal approach to finding extrema. We take the partial derivatives with respect to each controlled parameter:

This is the part where the variables being separable is useful. We set these derivatives equal to zero, and as a result, can vaporize the terms involving the alternate parameter, reducing the functions to one variable each. The two meaningful reductions occur when we reduce each partial derivative with respect to the differentiated variable. For x, we have:

Which is kind of neat, and intuitively makes sense that the largest would be in the middle.

Following this, we apply the same idea to the ϴ derivative:

Following this, we apply the same idea to the ϴ derivative:

The end result of which is a little less obviously intuitive, but on thought, seems to be similarly reasonable- the angle is half the difference of the two triangle corners bracketing it, plus 45 degrees. Sensible, because it's natural that the angle would be towards the middle orientation, and the exact placement would depend on the tilt of the triangle as a whole.

So that looks like us finished- an expression to identify a fully determined maximal inscribed rectangle inside a triangle. To verify, let's try is out on a case that's relatively easy to compute, an equilateral triangle. We're going to compare two different approaches to the maximum rectangle- the rotated version we computed, and the 'typical' inscribed triangle, tied to one wall:

So that looks like us finished- an expression to identify a fully determined maximal inscribed rectangle inside a triangle. To verify, let's try is out on a case that's relatively easy to compute, an equilateral triangle. We're going to compare two different approaches to the maximum rectangle- the rotated version we computed, and the 'typical' inscribed triangle, tied to one wall:

Interestingly, perhaps, we can deduce that 'rectangle' in the leftmost figure generated by our equation is actually a square, too. Because the angles in the bottom corners are equal, as are the partitions of the bottom triangle side, and the angles created by the bottom of the rectangle are the same (ϴ is 45 degrees, and the interior angle is 90, leaving 45 for the other side of the square), they form identical triangles in the bottom right and left of the figure. Consequently, we need only calculate one side to figure the area (which is easier than plugging in the x and ϴ to the unwieldy original formula for a).

From this figure, we can directly pull an expression for s: s = l∙sin(60°)/2∙sin(75°), which works out to about 0.4483∙l. A, then, is given by:

Now, for the comparison case, we can't assume that it'll be a square, so we need to compute the optimal rectangle's sides, which we'll call h and w. We'll pick an x as an offset, which for this case is sufficient to determine the rectangle entirely.

Remembering that all the triangle's interior angles are 60, we can get h pretty easily as h = x tan(60). w requires a little more effort, as we will need to subtract x and y from l to get it. Intuition suggests that the two triangles on either side of the square will be equal, and thus y = x, but we really ought to determine that for certain. Fortunately, that turns out to be simple. We know that the side of the right triangle formed by the rectangle is of length h, that it contains a right angle, and that the angle shared with the main triangle is 60°. We can thus deduce the remaining angle to be 30°, which gives us all three angles and a side identical to the other triangle, thus they are identical.

That lets us write an expression for w: w = l - 2∙x. From that, we can get the area: A = x∙tan(60°)∙(l - 2∙x). Finding the maximum x follows the same procedure as before, with A' = tan(60°)∙(l - 4∙x) = 0, resulting in x = l/4, which is another very nice, tidy result, giving w = l/2.

The actual area of interest, by substitution, is A = tan(60°)∙(l/4)∙(l/2):

The actual area of interest, by substitution, is A = tan(60°)∙(l/4)∙(l/2):

Which is obviously larger than the one we computed before. Damn.

So where did we go wrong? Trust me when I say it's not computational, I triple checked when I encountered this the first time. It appears to be a conceptual problem, so do we have to say that locking an edge to a side is the better way to inscribe a rectangle? That seems to be a common assumption. Hang on, though, I'd say, look at the sides of the triangle! They look like they fit our model of a rotated rectangle, and sure enough, they're intersecting the side at l/2, so shouldn't our approach catch that?

To get a better feel for whats going on, let's shift from the equilateral triangle to an arbitrary isosceles triangle. If we let the base angles of this triangle be ϕ, then we can co-opt the expression we used before, A = x∙tan(ϕ)∙(l - 2∙x). This is fine, because we have the same layout for h, and the precise logic we applied to determine that y was equal to x works, with the replacement of 60° with ϕ. Furthermore, taking the derivative with respect to x results in the same formal expression from which the angular component disappears, and so x = l/4 remains the optimal solution. Therefor, we can write out an expression for the area in terms of ϕ and l:

So where did we go wrong? Trust me when I say it's not computational, I triple checked when I encountered this the first time. It appears to be a conceptual problem, so do we have to say that locking an edge to a side is the better way to inscribe a rectangle? That seems to be a common assumption. Hang on, though, I'd say, look at the sides of the triangle! They look like they fit our model of a rotated rectangle, and sure enough, they're intersecting the side at l/2, so shouldn't our approach catch that?

To get a better feel for whats going on, let's shift from the equilateral triangle to an arbitrary isosceles triangle. If we let the base angles of this triangle be ϕ, then we can co-opt the expression we used before, A = x∙tan(ϕ)∙(l - 2∙x). This is fine, because we have the same layout for h, and the precise logic we applied to determine that y was equal to x works, with the replacement of 60° with ϕ. Furthermore, taking the derivative with respect to x results in the same formal expression from which the angular component disappears, and so x = l/4 remains the optimal solution. Therefor, we can write out an expression for the area in terms of ϕ and l:

Then, we can do likewise for our original version. The net expression for area in that case was fairly complex, but for this case, we have the advantage that we're looking at an isosceles triangle, and so the ϕ2 - ϕ3 term will be 0, thus the angle ϴ will be fixed at π/4, or 45°, which makes sense in the symmetric context. Injecting these values, and the standard l/2 for x, we can get a more simple expression for the area in this special case:

Note that we can compare these two functions readily in terms of ϕ, because both are identically proportional to l squared. With that in mind, we can compare the two functions to see which is greater over small angle ranges (note that the denominator expression in sin(2ϕ) is simplified below):

So this graph tells us that in angle ranges from 0 to somewhere around 0.8, the sine expression dominates, while after that point, the tangent expression is greater (up to π/2, which it the actual upper limit of the base angles for an isosceles triangle). Wolfram|Alpha helpfully volunteers the information that the crossover occurs at a base angle of π/4- 45°. Sure enough, if we put this angle in, the areas are equal, and below this angle, the original calculation is good.

So, the side-locked version isn't always optimal... but is sometimes. What's going on? I'm ashamed to admit it took me a while to get it, but when I did, I had to shake my head. Consider this. The ϴ from our original expression is bounded, if you push it too far in either direction, you can't have a right angle at the intersection point:

So, the side-locked version isn't always optimal... but is sometimes. What's going on? I'm ashamed to admit it took me a while to get it, but when I did, I had to shake my head. Consider this. The ϴ from our original expression is bounded, if you push it too far in either direction, you can't have a right angle at the intersection point:

The boundaries on either side, then, are naturally the angles at which one side of the rectangle is flush with a side of the triangle.

Now, this leads us into a subtlety of the derivative method for finding extrema. The thing is, when you use the derivative, you are actually looking for plateaus on the function, like so:

Now, this leads us into a subtlety of the derivative method for finding extrema. The thing is, when you use the derivative, you are actually looking for plateaus on the function, like so:

Basically looking for the tops and bottoms of humps. And, you could imagine that, in the above image, that curve carries off elsewhere and has a higher hump someplace else. So the derivative method only finds

Now, this is ok if we have a whole curve, because the mathematics will find all the humps- if that green curve has a higher one, it would show up when we use the derivative method as an additional choice, we just have to check all the options. So why didn't the side-locked rectangles appear above, well...

Imagine a function like this:

*local*maximums and minimums, ones that are higher or lower than the curve as it is nearby.Now, this is ok if we have a whole curve, because the mathematics will find all the humps- if that green curve has a higher one, it would show up when we use the derivative method as an additional choice, we just have to check all the options. So why didn't the side-locked rectangles appear above, well...

Imagine a function like this:

It has two local maxima, indicated with the red bars (and a local minimum, but we're ignoring it). With a function describing the green line, we'd find these two points. But, let's say we chop off only a small section, as indicated below with blue lines:

Now, the curve is allowed to exist only between the blue lines, so there's no plateau areas! But there is still a maximum value:

The maximum value is

Savvy readers may have noticed one more flaw, however. In the above, we illustrated a bound region with no extrema within, but our equation doesn't say there are no extrema, it finds false ones! What's going on here?

There's two things: first, there's a kind of trick point that can also foul up the derivative test- it's called an inflection point, and they look like this:

*at*the boundary, which is the subtlety at play here- sometimes, the derivative method won't find the actual maximum because it's at the edge of the allowed space, but the function itself does not have a plateau at the boundary, so the derivative can't find it. When we look for extrema in bounded spaces, we have to check the edges, too, just in case.Savvy readers may have noticed one more flaw, however. In the above, we illustrated a bound region with no extrema within, but our equation doesn't say there are no extrema, it finds false ones! What's going on here?

There's two things: first, there's a kind of trick point that can also foul up the derivative test- it's called an inflection point, and they look like this:

You can see how the curve gets sort of flat, but doesn't really have a peak or trough. We could be finding these.

s

The other thing is that we could be looking at a local minima, or a maxima which is still lower than a boundary value. In general, maxima seem strange, because it means the function must go down a little and come back up, then dip again:

s

The other thing is that we could be looking at a local minima, or a maxima which is still lower than a boundary value. In general, maxima seem strange, because it means the function must go down a little and come back up, then dip again:

, Which could be reasonable, given that out angle solution is actually periodic- because it's computed from a cosine, you can set the result of arccos(0) to π/2 + n∙π, for any value of n, and get another valid solution. Whether or not this new solution is valid depends entirely on the triangle, and whether that angle is within the bounds discussed previously.

So, among all this, we have a conclusion- we've found an expression for a maximum area inscription of a rectangle within an arbitrary triangle. In general, we found that the common case of an edge-fixed inscription will sometimes be the optimal inscription, when the boundary values are greater than those of the area function within the legal inscription region, due to the limitation of requiring a right angle at each intersection of a rectangle corner with a triangle side, as per usual with extrema problems in bounded spaces. But, we also observed a certain region indicating that this is not always the case- in isosceles triangles with base angles less than 45°, the rotated rectangles are marginally larger.

Perhaps an interesting final annotation is to observe that, if one tries to drive the area of the rotated rectangle to infinity by tweaking the ϕ angles, as we can with the base locked version by making an isosceles triangle's base angles approach 90°, we find that we must have sin(ϕ2 + ϕ3) = -1, or rather, ϕ2 + ϕ3 = -π/2 + nπ for which we are permitted for n = 0, 1 or 2: ϕ2 + ϕ3 = -π/2, 3π/2, and 5π/2. The negative solution is of course irrelevant in this context, as are all solutions less than it, and 5π/2 and greater would violate the triangle inequality. 3π/2 would mean that the remaining angle was precisely π/2, a right angle. But, there's no constraints on the ϕs or l, and thus no implication that the other sides go to infinity, as in the isosceles case. We could create a finite triangle, for which this math suggests an infinite inscribed triangle!

However, if the opposing angle is 90°, then the only rotation that allows an inscribed rectangle to exist with both adjacent sides intersecting the triangle (as assumed above for the area expression to work), is the one which causes a corner of the rectangle to overlap the right angle of the triangle:

So, among all this, we have a conclusion- we've found an expression for a maximum area inscription of a rectangle within an arbitrary triangle. In general, we found that the common case of an edge-fixed inscription will sometimes be the optimal inscription, when the boundary values are greater than those of the area function within the legal inscription region, due to the limitation of requiring a right angle at each intersection of a rectangle corner with a triangle side, as per usual with extrema problems in bounded spaces. But, we also observed a certain region indicating that this is not always the case- in isosceles triangles with base angles less than 45°, the rotated rectangles are marginally larger.

Perhaps an interesting final annotation is to observe that, if one tries to drive the area of the rotated rectangle to infinity by tweaking the ϕ angles, as we can with the base locked version by making an isosceles triangle's base angles approach 90°, we find that we must have sin(ϕ2 + ϕ3) = -1, or rather, ϕ2 + ϕ3 = -π/2 + nπ for which we are permitted for n = 0, 1 or 2: ϕ2 + ϕ3 = -π/2, 3π/2, and 5π/2. The negative solution is of course irrelevant in this context, as are all solutions less than it, and 5π/2 and greater would violate the triangle inequality. 3π/2 would mean that the remaining angle was precisely π/2, a right angle. But, there's no constraints on the ϕs or l, and thus no implication that the other sides go to infinity, as in the isosceles case. We could create a finite triangle, for which this math suggests an infinite inscribed triangle!

However, if the opposing angle is 90°, then the only rotation that allows an inscribed rectangle to exist with both adjacent sides intersecting the triangle (as assumed above for the area expression to work), is the one which causes a corner of the rectangle to overlap the right angle of the triangle:

Now, what this means for the derivative is that the function, as we mentioned earlier,

You might ask about situations in which the sum of angles is very close to 3π/2, but not quite there, so that the multiplier is very large. It turns out that in cases where the angular term would drive the area of the rectangle too large, you're limited by the problem assumptions, because if you're too close to that limit, it turns out you're looking at a corner of the rectangle that doesn't satisfy the geometric assumptions underlying the original calculation:

*exists at exactly one point*. That means that, by definition, the derivative simply does not exist- it cannot, because there must be some change for you to measure the rate of change of the function. It turns out that the weird subtleties result in a very tidy resolution here.You might ask about situations in which the sum of angles is very close to 3π/2, but not quite there, so that the multiplier is very large. It turns out that in cases where the angular term would drive the area of the rectangle too large, you're limited by the problem assumptions, because if you're too close to that limit, it turns out you're looking at a corner of the rectangle that doesn't satisfy the geometric assumptions underlying the original calculation:

I wanted to address the infinite case, though, because it

*does*meet the geometric conditions. Just barely, but as we saw earlier, dealing with those special cases is an important part of good math.