optimized grid for rectangular items

Posted by peterchen on Stack Overflow See other posts from Stack Overflow or by peterchen
Published on 2010-03-19T10:02:31Z Indexed on 2010/03/19 10:11 UTC
Read the original article Hit count: 228

I have N rectangular items with an aspect ratio Aitem (X:Y).
I have a rectangular display area with an aspect ratio Aview

The items should be arranged in a table-like layout (i.e. r rows, c columns).

what is the ideal grid rows x columns, so that individual items are largest? (rows * colums >= N, of course - i.e. there may be "unused" grid places).

A simple algorithm could iterate over rows = 1..N, calculate the required number of columns, and keep the row/column pair with the largest items.

I wonder if there's a non-iterative algorithm, though (e.g. for Aitem = Aview = 1, rows / cols can be approximated by sqrt(N)).

© Stack Overflow or respective owner

Related posts about mathematical-optimization

Related posts about math