Divide Closed Curve into Cells with Python or Efficient Method

Hello,

I’m looking for a Grasshopper method to divide a closed curve into distinct cells, ideally using a Python script. If not possible with a script, an efficient interface solution would also work.

Input requirements:

  1. A single closed curve (boundary, polygon or smooth free-form shape).
  2. Multiple lines inside the boundary. These lines intersect the boundary at exactly two points each without overlapping.

I have attached an illustration showing the boundary in red and the internal lines in blue:

Desired output:

Distinct cells (closed curves) generated from this division, not baked into Rhino.

Another illustration is attached to show the expected output.

The solution should be flexible enough to handle free-form inputs without specific shape assumptions, following the constraint of two-point intersections inside the boundary without overlap. I prefer not to bake the results into Rhino directly (e.g., avoiding the use of rhinoscriptsyntax.SplitCurve) to allow clean further manipulation.

Any suggestions, even if it requires combining multiple script components or approaches, would be greatly appreciated.

Thank you!
-Y

I honestly wonder why people start threads like this without posting a GH file with internalized geometry, if nothing else? Why should people have to create this thing from scratch?

3. Attach minimal versions of all the relevant files

That said, you could create a circular surface and then split it with the blue curves, giving four surface fragments whose edges define the areas.

1 Like

HETEROPTERA

3 Likes

Thanks for sharing this example Quan! This looks super useful!

1 Like

Thank you, both @Quan_Li @Joseph_Oster!

@Joseph_Oster, you are right. I’ll try to pay attention next time and attach some example files.

Here’s a native RhinoCommon/GHPython solution, using Curve.CreateBooleanRegions:


240215_BooleanRegions_GHPython_00.gh (7.8 KB)

I’m guessing that is what the Heteroptera plugin is using.

4 Likes

And yet you still didn’t post a GH file with internalized geometry.

There is no comfort in being right when so many don’t follow the guidelines.

@AndersDeleuran, such an elegant solution! Thank you very much! I appreciate it!

1 Like

Hi Anders! This is a great example!

I wonder if this could work as an indirect way to find the minimum cycle basis of a graph, like throwing a set of vertical and horizontal lines on a region and getting the individual (smallest) grid areas. e.g. returning the four 口s in 田,but not the 日,which is not minimum cycle basis(its made of two 口s i.e. cycles)

1 Like

Ah that’s a really interesting approach. As far as I know there is no purely topological method for finding such graph cycles, but I might well be wrong here, it’s been a while. Anywho, it looks like the RhinoCommon method indeed might work for that purpose:

240216_BooleanRegions_GHPython_01.gh (11.1 KB)

3 Likes