Making optim. use of w/h while placing squares into a rect

Math Help on Cosine (cos), Sine (sin), Tangent (tan), Cotangent (cot), Cosecant (cosec), Secant (sec), Arccos, Arcsin, Arctan, Hypotenuse, Angles, Formulas, Trigonometric Circle, Unit Circles, Quadrants, Rotations; Triangles, Rectangles, Squares, Parallelograms, Quadrangles, Lozenges, Lines, Perpendicular, Parallel, Perpendicular, Parallel Lines, Bisector, Median, Gravity Center, Circumcenter, Circles, Pythagorean Theorem, Thales, Height, Side, Length, Ruler, Compass, Constructions, Formulas; Quadratic equations (Second degree equations), Absolute Values, Inequalities; Events, Random, Mean, Variance, Expectation, Wins, Losses, Bernoulli, Newton's Binomial Formula, Multinomial Formula, Tests, Samples on My Math Forum.

Making optim. use of w/h while placing squares into a rect

Postby momesana » Thu Mar 11, 2010 4:09 pm

Hi,
I want to implement a flow layout in a given graphical toolkit and I am having some problems doing it.
I have a given rect - that I will henceforth refer to as container - whose sides have an aspect ratio of 1:n or n:1 (width/height rounded down to an integer). n is always a multiple of 1 so valid values may be 1:4, 3:1, 7:1 etc. but never something like 3:4. I have a number of squares - which I will refer to as elements - that need to be laid out on the container. I can freely resize the elements as long as I always adhere to the following constraints:
* The elements or even parts of them never go beyond the bounds of the container
* The elements do not overlap each other
* The elements always have the same size
Now, my question is ... with x elements and a given aspect ratio of n:1, how many rows and columns are needed to accommodate these elements? And of course how the formula looks like ;-). It doesn't necessarily need to be a formula, ... a comprehensible algorithm that I can then translate into c++ would be more than sufficient.
Here are a few examples:
Aspect ratio | elements | rows | col |
--------------------------------------------
1:1 | 4 | 2 | 2 |
2:1 | 4 | 2 | 1 | though only one rows is used
1:2 | 6 | 4 | 2 | two indexes remain vacant
1:1 | 8 | 3 | 3 | one index remains vacant
3:1 | 7 | 6 | 2 |
1:3 | 12 | 2 | 6 |

I hope you get what I mean. It's not that easy to verbalize.

Thanks in advance
momesana
momesana
Jack of Clubs
Jack of Clubs
 
Posts: 6
Joined: Thu Dec 03, 2009 6:21 pm

Return to Geometry, Trigonometry, Algebra, Probability and Statistics

Who is online

Registered users: Ask Jeeves [Bot], Google [Bot], MarkFL, Yahoo [Bot]