How does Brep split work?

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.

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

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.

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.

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;
}

Hi Srujan,

I think you could just use the SubSrf IsoTrim Component 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:

.

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

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

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.