# How does Brep split work?

**URL:** <https://discourse.mcneel.com/t/how-does-brep-split-work/177228>\
**Category:** Grasshopper\
**Tags:** windows, rhinocommon, csharp, brep-edge\
**Created:** [March 5, 2024, 8:04am UTC](https://discourse.mcneel.com/t/how-does-brep-split-work/177228 "2024-03-05T08:04:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![srujan.v16](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/srujan.v16/32/573710_2.png) [@srujan.v16](https://discourse.mcneel.com/u/srujan.v16)\
**Post date:** [March 5, 2024, 8:04am UTC](https://discourse.mcneel.com/t/how-does-brep-split-work/177228/1 "2024-03-05T08:04:49Z")

</div>

Hi,  
Thanks in advance

**Problem statement:**  
Brep.Split() returns a list of breps(in this case _surfaces_) where each brep/surface has randomly ordered edge list when compared to other breps/surfaces.

**Workflow:**  
I am attempting to split a curve with other curves so that I can extract some regions in between.  
I am trying to get closed curves of region 0, 1 and 2 as show in image.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/6/d/d/6dd0a982ee34b933e13e13f2130388eeb7d74738.png)

Next step is to perform contour and split on these extracted regions.  
I would prefer to align this second step from one side for all regions. Say from left going to right

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/0/1/2/01275a1bf7357dec2ba14ccdc05f035fbd2822a7.png)

When I looked at the edges of these split surfaces, I realised that the first edge is not always ordered in a specific way. Green ones in the image below are the first edge of each surface after splitting.

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/9/d/c/9dcc4bd500ad760ea6b8b75a1c0ab6f08e891575.png)

**Conclusion:**  
I wanted to understand how brep.split() works and if there is something obvious I am missing where it can return the split surfaces where all first edges align.

```auto
private void RunScript(Curve boundary, List<Curve> curveList, ref object A)
{
    double tol = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;
    //creating planar surface from boundary
    Brep[] surfaceArray = Brep.CreatePlanarBreps(boundary, tol);
    Brep planarBrep = new Brep();
    if(surfaceArray != null && surfaceArray.Length == 1)
    {
      planarBrep = surfaceArray[0];
    }

    //splitting surface and creating a new curve list of surface edges
    Brep[] splitSurfaces = planarBrep.Split(curveList, tol);

    List<Curve> splitSurfaceBoundaries = new List<Curve>();

    foreach(Brep brep in splitSurfaces)
    {
      Curve[] surfaceEdges = brep.DuplicateEdgeCurves();
      splitSurfaceBoundaries.AddRange(Curve.JoinCurves(surfaceEdges, tol, true).ToList());
    }

    A = splitSurfaceBoundaries;
}

```

---

<div class="post-metadata">

**Author:** ![tims.designs](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/tims.designs/32/620209_2.png) [@tims.designs](https://discourse.mcneel.com/u/tims.designs)\
**Post date:** [March 29, 2024, 7:34pm UTC](https://discourse.mcneel.com/t/how-does-brep-split-work/177228/2 "2024-03-29T19:34:04Z")

</div>

Hi Srujan,

> [@srujan.v16](#):
>
> if there is something obvious I am missing where it can return the split surfaces

I think you could just use the [SubSrf IsoTrim Component](https://grasshopperdocs.com/components/grasshoppersurface/isotrim.html) in this case, but there are other cases where this wouldn’t work (angled section curves) and your approach would be appropriate. I compared the results and besides the order of first and last, you end up with the same:

 ![GappedRegionSplit](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/3/e/b/3eb239e5de827d9adeaf1c91edb4640f10b9bb9d.png).

So with IsoSrf (if you want to use it in a component) you could work like this:

```csharp
private void RunScript(Curve Crv, Interval D, ref object S)
  {
    S = Brep.CreatePatch(new Curve[]{Crv}, 1, 1, RhinoDocument.ModelAbsoluteTolerance).Surfaces[0].Trim(new Interval(0, 1), D);
  }

```

and get the sort order correct (but only with patch congruence). With your version I guess you’d have to swap first and last before outputting.

I’m not so sure about performance though, since you are practically splitting 2d regions here, might be faster to use them instead.

Cheers Tim

---

<div class="post-metadata">

**Author:** ![adel.albloushi](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@adel.albloushi](https://discourse.mcneel.com/u/adel.albloushi)\
**Post date:** [March 29, 2024, 8:28pm UTC](https://discourse.mcneel.com/t/how-does-brep-split-work/177228/3 "2024-03-29T20:28:10Z")

</div>

The brep ordering is a known issue. Asside from the devs, noone knows how that works

However, you can use some geometric principles to select the desired brep faces. For example, if they are the top of a box, they will have the centroids with the highest z values.

You can also order edges by proximity.
