查找矩形的大小以填充区域 [英] Find size of rectangles to fill area

查看:103
本文介绍了查找矩形的大小以填充区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到麻烦需要您的帮助:

I got trouble need your help:

我正在开发一个程序,该程序以平铺模式显示n视频(又名视频墙,c列和r行). n是任意的,视频具有相同的大小(W x H),并且我们具有W / H的比例,墙的大小是固定的,我该如何最好地设置crWHn更改时?最佳定义为WH是最大值,视频会填满墙壁的最大面积.

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!

推荐答案

据我所知,您要在给定WidthHeight

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆