# What is the formula to find the optimum width and height of given units that would fit in an area?

What is the formula to find the optimum width and the height of given units that would fit in an area? For example : I have 100 units that need to be placed in a rectangle that is 300 in height and 400 in width. How do I get the optimum width and height of a unit so that all 100 units can fit in the area?

• Well the longest distance line segment entirely in the rectangle is the diagonal. The diagonal cuts the rectangle into two right triangles. – fleablood Nov 21 '15 at 0:52
• You may want different units in your example. 100 < 300 so any shape will do. – fleablood Nov 21 '15 at 0:55
• I made some clarifications. – rastacide Nov 21 '15 at 0:56
• A mere suggestion: don't ask "what is the formula".Math is more interesting than that. Try to understand. – leonbloy Nov 21 '15 at 1:08

Your space has an area of $$300\times400=120,000$$ This is the same as the combined area of all 100 units. Therefore, you have $$120,000=100\times\text{Area of 1 unit}$$ Therefore, $$\text{Area of 1 unit}=\frac{120,000}{100}=1,200$$ Now, you have to figure out one thing: What am I optimizing the height and with in relation to? You know that $$\text{height}\times\text{width}=1,200$$ but you need to add another constraint to optimize the height and width. In this case, you want to optimize the perimeter (as you said in a now-deleted comment). You have $$P=2(\text{width}+\text{height})$$ You then can write $$\text{height}=\frac{1,200}{\text{width}}$$ and substitute that in to find $$P=2\left(\text{width}+\frac{1,200}{\text{width}}\right)$$ All you have to do is find the extrema of this function within the range of acceptable values (for example, the function admits 1,000 as a possible value for the width, but that clearly isn't a valid solution, because one unit would be wider than the total original area!).

Putting it in a simpler way, if $h$ is the height, $w$ is the width, $A$ is the area, and $P$ is the perimeter, then $$A=hw,\quad P=2w+2h$$ If you know either the perimeter or the area, you can optimize the other one.

The most efficient rectangle with maximum area per perimeter is a perfect square. (Basic calculus.) So if 1/4 of the units is less than the smaller side of the rectangle, that is best. The square will slide right in.

If on the other hand you can't do a perfect square because the smaller side of the containing rectangle is too small, The second best thing is a rectangle with the sides as near in length as possible. So do a rectangle with one side equal to the smaller side of the rectangle. That's as close to a square as you can get.

=====

So assuming 25 units is less than 300 inches. Put this into a 25 by 25 unit square. That gives you area of 625 square units.

If 25 units is more the 300 inches this is impossible. So put it into a rectangle that 300 inches by (100 units - 600 inches)/2. That's the best you can do.