I have a rectangle width x height, and N squares of same unknown size. I must determine the maximum size of these squares and number of rows and columns to fit perfectly (UP
This problem came up recently in a project I was working on. Here is the solution that was determined:
int numItems; // the number of squares we need to pack in.
double rectWidth; // the width of the space into which we want to pack our squares.
double rectHeight; // the height of the space into which we want to pack our squares.
double tableRatio = rectWidth / rectHeight;
double columns = sqrt(numItems * tableRatio);
double rows = columns / tableRatio;
columns = ceil(columns); // the number of columns of squares we will have
rows = ceil(rows); // the number of rows of squares we will have
double squareSize = rectWidth / columns; // the size of each square.