How to generate Surface from Points (Planar Closed Polyline) c#

We are struggling to generate a surface from Planar Closed Polyline. Currently, for more than 4 edges shape is not correct. How should we improve it? Any help really appreciated

//Create surfaace from planar polyline points
public static Rhino.Geometry.Brep ToBrep(this IEnumerable<Rhino.Geometry.Point3d> points)
{
    List<Rhino.Geometry.Point3d> pointList = new List<Rhino.Geometry.Point3d>(points);

    //---Not necessary---
    Rhino.Geometry.Plane plane = new Rhino.Geometry.Plane(pointList[0], pointList[1], pointList[2]);
    points = pointList.ConvertAll(x => plane.ClosestPoint(x));
    //-------------------

    List<Rhino.Geometry.LineCurve> lineCurves = new List<Rhino.Geometry.LineCurve>();

    // Create Line Curve
    for (int i = 1; i < pointList.Count; i++)
        lineCurves.Add(new Rhino.Geometry.LineCurve(pointList[i - 1], pointList[i]));

    lineCurves.Add(new Rhino.Geometry.LineCurve(pointList.Last(), points.First()));

    //Ceate Surface
    return Rhino.Geometry.Brep.CreateEdgeSurface(lineCurves);
}

GH approach



Our approach

Have a look at https://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Brep_CreatePlanarBreps_1.htm
As the description says edge surface does not support more than 4 edges.
You should be able to do it like this:

 Brep[] bf = Brep.CreatePlanarBreps(new Polyline(points).ToNurbsCurve());

thanks a lot @Baris your help is really appreciated :clap:

everything is working now :slight_smile:

2 Likes