A simple algorithm is to split vertically into n bands of equal size h and width w / n.
If you assume that the original rectangle has angles (0,0) and (w, h), then using this algorithm, the rectangle i th would have the center (w / n * (i + ½), h / 2), for 0 <= i <n.
Update: try to find all factorizations of the number n into pairs of factors (i, j), such that I * j = n, and find pairs of factors so that the ratio of factors is closest to the ratio of the sides of the rectangle. Then use two factors to create a regular grid of smaller rectangles.
For example, when n is 10, you can choose between (1, 10), (2, 5), (5, 2) and (10, 1). The following is an example of a grid using coefficients (5, 2):
------------------------------------
| | | | | |
| | | | | |
------------------------------------
| | | | | |
| | | | | |
------------------------------------
If your initial rectangle has a width of 60 and a height of 20, then using a pair of factors (5, 2) will give ten rectangles of size (60/5, 20/2) = (12, 10) that are close to the square.
source share