Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...