Assign rectangular panel to surface


At the top of the picture, there are multiple groups of rectangles:
2 groups of 5 rectangles
2 groups of 4 rectangles
6 groups of 3 rectangles
9 groups of 2 rectangles
At the botton, there is a matrix consist of 54 rectangles(9 * 6) which is the same number as the total number of rectanglers above (2 * 5 + 2 * 4 + 6 * 3 + 9 * 2)

My question is how can I fit these group into the matrix randomly?

I had tried to assign them in several steps, but it wasn’t work well. you can see what I have on the picture, when i finished assign group of 5, 4 and 3, the rest of empty space coudn’t fit group of 2 i have left, for example, the row 0-8 has 9 rectanglers.

assign panels.gh (52.8 KB)

Order the rectangles (if they aren’t already) then just move/map/orient to matrix? Post a file so people can help you!

Hi, thanks for replying.
I just uploaded my gh file, it’s kind of messy.
What I was trying to do is to assign different groups at different times, group of 5, then group of 4, then group of 3.

It certainly is. I didn’t see any geometry that matched the groupings you described so wrote that first (white group). Then I baked the SUnion pieces and arranged them by hand. Added some bits to bake them with colors, which are visible only in ‘Rendered’ mode and did it again, by hand.


assign panels_2023Sep5a.gh (42.9 KB)

The first two rows are easy: one group of five and one group of four. The third row has three groups of three. Rows 4, 5 and 6 begin with groups of three, followed by three groups of two. (per row)

P.S. I don’t know how to code a solution (there is more than one) but can elaborate on the intuitive logic that guided me to solve it manually.

  1. Start with the largest pieces and place smaller ones later.

  2. You can’t have groups of 5 and 3 on the same row because that leaves only one space

  3. If you start a row with a group of three, it must be followed by two groups of 3 OR three groups of 2 OR one group of 4 and one group of 2. There can’t be just two groups of three on any row.

This might be useful? I adapted some Python code (somewhat blindly) that generates combinations of a list of values, from here:

The code generates 524K combinations in 3.5 seconds. Then I filter those that add up to 9.

5+4
5+2+2
4+3+2
3+3+3
3+2+2+2


assign panels_2023Sep5b.gh (33.1 KB)

Inserting CSet prior to Split (Text Split) was crucial to improving performance.
Split was producing ~five million results in 3.3 seconds but MA was taking 1.6 minutes :exclamation:

Thanks for replying, it looks great. According to your result, it ends up with 5 types of combinations at the end.

From the result you have, I get 3 combinations of matrix, and it seems like all types we can have. so, I think I can get a similar result by playing with the order of lists. It’s a tricky way.

I don’t have an algorithm to fully solve this puzzle, but for what it’s worth, I made a slight change to the Python code that allows the separator to be defined. The default “+” is used if there is no ‘sep’ input.

This makes it possible to get combinations of the “Valid Combos”, like this:

assign panels_2023Sep6a
assign panels_2023Sep6a.gh (34.4 KB)

The title of the large text panel is wrong, a copy/paste error. The only interesting output is the last one that shows all five “Valid Combos” combined… but we want six rows, not five, and the limits of how many 5s, 4s, 3s and 2s must be observed… :question:

Yeah, we need six rows, and the quantity of different groups needs to be controlled which is not easy to do. but it’s ok, I have got what I wanted by using the tricky way I mentioned.


partition 2.1.gh (22.6 KB)

And THANKS for your help !!

Obviously. My input was only five “Valid Combos” so five combinations is the maximum.

You didn’t explain your “tricky way” or post any code with it so I assume you did it by hand?

As to your partition 2.1.gh, this:

can be done more simply like this:

assign panels_2023Sep7a3

I followed your code for awhile but didn’t see the point of it since you started with three valid “solutions” as this code demonstrates:


assign panels_2023Sep7a.gh (15.4 KB)

I should have done it like this:


assign panels_2023Sep7b.gh (8.4 KB)

The purple group is redundant, from here: