# Boundary trim of curves in Grasshopper

Hi, is there a way in Grasshopper to do boundary trimmings like in the second picture?
I’m trying to use the circles as a boundary shapes to trim of delauney triangles.
In the second picture I used a python script in Rhino but I would prefer to do this in Grasshopper.
It can also be a 3D boolean if 2D curves are not possible as in the 3rd picture
Thanks

Circle_Pack_Triangles.gh (1.2 MB)

I guess you’re looking for TrimWithRegions:

TrimWithRegions.gh (1.1 MB)

1 Like

Alternatively, you can do it with ghpython. It’s still slow, but according to Grasshopper’s profiler it’s still faster (4.9s on my super old machine) than TrimWithRegions (15s).

EDIT: Note, that it only will work with lines and circles. Furthermore, only lines which start or end at the center of a circle are considered. So it won’t account for lines which are going through the circle but have no ‘connection’ to the circle’s center point. The script does not actually trim the lines, it rescales them to the respective circle’s radius. This is probably also the reason it’s faster because it does not need to check for actual intersections like TrimWithRegions.

Code for ghpython component:

``````"""
'Trims' a bunch of lines with some circles.
Inputs:
Circles: the circles to use as boundaries for the lines.
Lines: The lines to trim with the circles.
Output:
TrimmedLines: The 'trimmed' lines.
"""

from ghpythonlib import treehelpers as th
import Rhino

TrimmedLines = [[] for x in Circles]

for i, circle in enumerate(Circles):
if circle == None:
continue
for j, ln in enumerate(Lines):
if ln.From == circle.Center:
new_line = Rhino.Geometry.Line(ln.From, ln.To)
TrimmedLines[i].append(new_line)
elif ln.To == circle.Center:
new_line = Rhino.Geometry.Line(ln.To, ln.From)