0

First of all, sorry if this is a simple question. I am programmer and facing a problem about calculation.

I have rectangle surface ($x_{s}$) with height $h_{s}$ and width $w_{s}$ and I want to put $n$ rectangles ($x_{n}$) with same height $h_{n}$ and width $w_{n}$ in the surface like a grid. $x_{n}$ can scale up or down but they must keep the aspect ratio. The problem is how can I get the maximize the area $x_{n}$? I need to calculate scaled $h_{n'}$ and $w_{n'}$, and how many column and row will be used?

Here is an example picture

enter image description here

Joshua
  • 101
  • It is not entirely clear what you are asking to me. Are $h_{n'}$ and $w_{n'}$ required to be integer multiples of $h_{n}$ and $w_{n}$? ie $\frac{h_{n'}}{h_n} = \frac{w_{n'}}{w_n} \in \mathbb{Z}$. Is there only one $x_n$? If so, all you need to do is pick the largest multiple that doesn't exceed your box size, which would be $min(\lfloor{h_s/h_n}\rfloor,\lfloor{w_s/w_n}\rfloor)$. Have I understood correctly? – rtpax Dec 12 '16 at 03:00
  • @rtpax Yes, there is only one aspect ratio for all $x_n$ and make it as large as possible. – Joshua Dec 12 '16 at 03:28

0 Answers0