Generating all possible geometries having specific constraints


I a new newbie and wonder if Rhino script (in python) could achieve what I want:

I have a 2d polygon surface (generally 4, 5 sides) and I would like to generate all the possible rectangles having a set of constraints:

  • that fil within the surface of the area
  • having a mininum width/height
  • that touch one or several sides.
  • rendering/visualizing the K generated possibilities?

Is Rhino Script the right tool for that?

Thanks in advances


It doesn’t really matter which programming language you pick, the hard bit is coming up with the algorithm itself. If the algorithm requires a lot of geometric iteration and you want this to be fast, perhaps python or C# or VB.NET are better suited.

Thanks David

yes, while we can use any general langage, I thought Rhino was used in particular for “parametric design” and had an engine enabling to generate geometries with a set of constraints. but I am newbie and I maybe misunderstood the features of Rhino or Grasshooper maybe.

(for me the tool/langage does matter => Rhino script might be an interesting high level langage facilitating the expression of such constraints ? )

am I right to go to Rhino / Parametric design eco-system?

  • let me reformulate the constraints:

I would like to generate all the possible rectangles meeting the following constraints:

  • that fall within the surface of the area
  • with a fixed amount of surface (heigh x width of the rectangle = constant K)
  • one or several sides of the rectangle should be parallel/touch one or several sides of the polygon
    having a minimum width and a minimum height (h_min , w_min) and given resolution steps (resolution_h, resolution_w)

Rhino itself is certainly not known for its parametricism. Quite the opposite in fact. Grasshopper does add some of that, but mostly it allows for the automation/formalization of specific steps. It’s not inherently good at iterating over a set of logical rules (I concede the different is subtle).

However both Rhino and Grasshopper do allow you to program algorithms using a number of programming languages. Rhino allows for RhinoScript, Python, VB.NET, C# (well, any language which can compile MSIL assemblies) and C++. Grasshopper is similar but doesn’t support RhinoScript and C++.

The constraints you describe are (I think) fit for formalization in Grasshopper. Though the approach would necessarily have to be:

  • Create all possible rectangles, based on all edges.
  • Remove those that violate the constraints.

If you were to do it using -say- VB.NET you could probably make it a lot faster.

Incidentally, your constraints are contradictory. Width and height resolution constraints may not ever result in the desired area. You’ll have to drop one of the resolution rules.

Also rectangles that are shorter than a polygon edge could be placed anywhere along that edge (unless I misunderstood and the placement is also tied to the resolutions), resulting in an infinite amount of answers.

Thanks a lot David !

1 .yes if the area is smaller than min_width x min_height that would be impossible. however let assume that the surface is greater.

  1. resulting in an infinite amount of answers.
    let assume there is a notion of resolution (atomic unit) to move or inscrease the size of width /height.

  2. (I think) fit for formalization in Grasshopper.
    could you point me to some ressources or examples in Grasshooper ?

I started with a file that generates these rectangles, but got stuck at the conflicting constraints. I can do some more on this tomorrow (it’s getting quite late here in Central Europe). Incidentally for Grasshopper discussions the Grasshopper Ning forum is better. I realize you probably haven’t installed this plugin yet and it’s a bit early, but if you choose to go down this way registering on would be the smart thing to do.

So I made a VB.NET component in Grasshopper which generates all rectangles along the edges of a polygon with a specific exact area using fixed increments along the edge. I didn’t add any logic yet that removes rectangles that intersect with the polygon. That’s potentially a very slow process unless I can be smart about it. (5.6 KB)

(just read a lot !)