Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>(I'm assuming, perhaps wrongly, that your rectangles are infinitely divisible rather than being made up of discrete pixels.)</p> <p>You can always get exactly the correct aspect ratios, at some cost in wasted rectangles, by letting m = ceil(sqrt(n)) and using m pieces on each side.</p> <p>Otherwise, you're looking for p,q close to sqrt(n) such that pq >= n and p,q are close to one another. The best choice of p,q will of course depend on how willing you are to trade off waste against inaccuracy. It doesn't seem likely that you'll ever want to take p,q very far from sqrt(n), because doing so would give you a large error in shape. So I think you want something like this:</p> <pre><code>p = ceiling(sqrt(n)) best_merit_yet = merit_function(p,p,0) best_configuration_yet = (p,p) for p from floor(sqrt(n)) downward: # we need pq &gt;= n and q as near to p as possible, which means (since p is too small) as small as possible q = ceiling(n/p) if max(merit_function(n/p,n/q,0), merit_function(n/q,n/p,0)) &lt; best_merit_yet: break n_wasted = p*q-n merit1 = merit_function(n/p,n/q,n_wasted) merit2 = merit_function(n/q,n/p,n_wasted) if max(merit1,merit2) &gt; best_merit_yet: if merit1 &gt; merit2: best_configuration_yet = (p,q) best_merit_yet = merit1 else: best_configuration_yet = (q,p) best_merit_yet = merit2 </code></pre> <p>and hopefully the fact that very wrong shapes are very bad will mean that you never actually have to take many iterations of the loop.</p> <p>Here, <code>merit_function</code> is supposed to embody your preferences for trading off shape against waste.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload