查找矩形的大小以填充区域 [英] Find size of rectangles to fill area
问题描述
我遇到麻烦需要您的帮助:
I got trouble need your help:
我正在开发一个程序,该程序以平铺模式显示n
视频(又名视频墙,c
列和r
行). n
是任意的,视频具有相同的大小(W x H
),并且我们具有W / H
的比例,墙的大小是固定的,我该如何最好地设置c
,r
,W
和H
当n
更改时?最佳定义为W
和H
是最大值,视频会填满墙壁的最大面积.
I'm working on a program that shows n
videos in tiling mode (aka, videos wall, c
columns and r
rows). The n
is arbitrary, the videos have same size (W x H
) and we have W / H
ratio, the size of wall is fixed, how can I get best set of c
, r
, W
and H
when n
changes? The best set defined as: W
and H
is maximum values and videos fill maximum area of the wall.
我看过包装问题,但仍然不能解决上面的问题,有人可以帮我吗?非常感谢你!
I have taken a look at Packing Problem but still can't solve my problem above, can someone help me this? Thank you very much!
推荐答案
据我所知,您要在给定Width
和Height
As far as I understand, you want to place n
rectangles with fixed C=W/H
ratio on the wall with given Width
and Height
让矩形的高度为h(未知),宽度为w = C * h
Let rectangle height is h (unknown yet), width is w = C * h
网格的每一行都包含
nr = Floor(Width / (C * h)) // rounding down
每个列都包含
nc = Floor(Height / h)
写不等式
n <= nc * nr
n <= Floor(Width / (C * h)) * Floor(Height / h)
并求解(找到最大可能的h
值)以获取未知的h
and solve it (find maximal possible h
value) for unknown h
对于参数h
的实际值,可能会得到初始近似值:
For real values of parameters h
might be found getting initial approximate value:
h0 = Ceil(Sqrt(Width * Height / (n * C)))
并递减h值,直到不等式变为真
and decrementing h value until inequality becomes true
这篇关于查找矩形的大小以填充区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!