# Fill a surface with rectangle of a certain size. Grasshopper or other language?

Hello,

I’m trying to solve this problem and i don’t know if it’s a good idea to make it in grasshopper or if I rather should use VBA (excel), or processing, or any other programmation language.

I want to generate a shelf, depending on variable height and width. I want to fill the surface with square of predetermined size : height and width of 1,2,or 3 units (see image below).

The logic i’m thinking of is to first randomly fill the surface with 3x3 square (with a number determined by a percentage of the area of the total surface), then 3x2, then 2x2, … and finally fill the remaining holes by 1x1 square.

This kind of task seems to be more about algorithmic than 3D modeling, is it possible (and smart) to make this in grasshopper ? What about recursion, for(), while, … in grasshopper ? or can I program with an other language and export the data and grasshopper generate the 3D model ?

Thanks

I have exactly what you want (done for some other purposes using C#). But is a bit “abstract” since returns a Matrix (or a DataTree of type int if you insist) … meaning that I must spend some minutes more to add some visual stuff:

1. Either Rectangle3d modules sampled in branches (where main dim is the num shown in the Matrix). This could be the demo mode.

2. Or divide a Surface List in pieces sampled in a Tree .This could be the real thing (rather requires proportional to size divisions in order to get “equal looking modules”, mind [easy]).

In any case notify if you want a 100% code based solution like this (BTW: I have no idea if this is doable with native components).

5 minutes found: this is going from the matrix to a Rectangle3d tree. For the other thing 10 minutes more are required.

Thanks for the answer ! If you have a code to share it will be great.
Also, I found some similar topic that give some answers to this :

Found some 10 minutes more for the matrix to surf division thingy. However that’s far from perfect:

1. What if you have BrepFaces?
2. What if you have Lists with things that differ greatly in U/V size ? (meaning that the divisions should be proportional, say, to min U (for some item) and to min V (for some other item).
3. What if you want the “union” and not the individual pieces sampled in a given branch?
4. What if you want to “hide the seam” completely? (case closed in U or V).

So I must find some time more (I have already Methods for all the above from other cases) to copy paste some code.

BTW: Do you speak C#?

I would use the nesting function of CAM software to do this. As long as you want to apply to flat sheets it would probably do what you want very easily. I use Rhinocam from MecSoft. You can download and try free.

Here is the sequence to set this in Rhinocam.

KSayxwlgkIoKkMIp8P5n0X8n.png) m

Well … the bad news are that I had plans to do that in w/e … but this w/e is the mother of all things: F1 race in Mexico (where Lewis can win his 5th title). But the altitude (2K m) makes things complicated and tire life is a big issue. Lewis was 8th !!! in Q2 (life sucks).

So nothing from the things promised is done … but IF Lewis wins … you’ll get the hot cakes this Monday.

Anyway get the state of things as they are right now.

NOTE: this is NOT a packing thingy by any means. It just fits randomly regions (with a maxW/H [user controlled]) in some sort of grid [user controlled]. Anyway that’s what the matrix does … then a little translation is required for more pragmatic stuff (Rectangles, Surface pieces etc etc). Pieces are sampled in a tree (obviously) - see the numbers in the matrix (i.e. branches in the tree).

Controlled_unevenSurfDiv_V1A.gh (132.6 KB)
Controlled_unevenSurfDiv_V1.3dm (887.7 KB)

I probably just misunderstand the question. Looking forward to your solution.

It’s not a big deal, mind (and again: NOT a packager) . But it could be a bit more challenging IF you want to “hide” the seam in surfaces closed in U/V. Plus the matrix solving Method requires some remake for respecting trim (i.e. dividing first the BrepFace, get nulls where required and then marking accordingly the matrix cells ).

An impressive piece of code Peter