Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
690 views
in Technique[技术] by (71.8m points)

c++ - Find size of rectangles to fill area

I got trouble need your help:

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Let rectangle height is h (unknown yet), width is w = C * h

Every row of grid contains

 nr =  Floor(Width / (C * h))   // rounding down

Every column contains

nc = Floor(Height / h)

Write inequality

n <= nc * nr
n <=  Floor(Width / (C * h)) * Floor(Height / h)

and solve it (find maximal possible h value) for unknown h

For real values of parameters h might be found getting initial approximate value:

 h0 = Ceil(Sqrt(Width * Height / (n * C)))

and decrementing h value until inequality becomes true


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...