What is the best way to create a solid 3D object with holes from some given contours(closed polylines)



I have a set of points representing the contours of an object. The structure is List<List<Point3d>> where each List<Point3d> is a contour of an object. The goal is to have a 3d object where every contour has been subtracted from the first contour in the list and then extruded to a 3d object

The image shows how the desired result, where the lightning and the arrow has been subtracted from the outter most shape, please note that the outermost shape is no a product of subtracting a circle from a square, but that outer most shape is like that originally


I was wondering if there is a better solution than the one I currently have implemented RhinoExporter.cs (3.5 KB).

I have both tried to make each contour a polyline, then extrude them and then using boolean difference, but that has originally caused some problems with the extrution, since one of the contours was not solid. I got around that by making a function that remove small indents that would cause the shape to not be solid when made into a brep.

I also had to import the shapes to rhino and then retrieve them again before doing the boolean difference, since rhino apparently does something to the shapes that is needed for boolean difference. I looked at the attributes and suspect something with the solid orientation, since that seem to change when added and retrieved from Rhino.

I also tried Brep.CreatePlanarBreps(curveList)[0]; which makes a planar surface with the correct shape with holes, but I could not find a method in Rhinocommon that does the same as ExtrudeSrf in Rhino.



If you get brep(s) as result of Brep.CreatePlanarBreps() method you can use BrepFace.CreateExtrusion() method to create extrusion from any brep face that is part of your brep - the same as ExtrudeSrf Rhino command.

If you import shapes and if some of them are not closed curves than you will have problem if you expect to get closed brep (solid) as result of extrude operation of such not-closed-curve.

Generaly if you have closed curves/polylines following aproach should work

  • create breps as result of extrusion method(s) from curves/polylines, brep should be solid
  • from outer brep you substract (boolean difference) inner breps
  • maybe inner breps should be little ‘higher’ (longer extrusion) to ensure boolean difference not fail



Thanks for your response, Radovan.

I got it to work with Brep.CreatePlanarBrep and then extruding the faces. The only problem I have is that while the curves are closed as seen on this picture

There is a little overlap as seen on this picture. (which is a zoomed in version of the first picture)
This is a problem when I want to use CreatePlanarBrep as it won’t work when there is an overlapping piece as shown. What happens when using CreatePlanarBrep with a overlapping piece is that only the outer Brep is created, without the holes.

So what I do now is to go through each curve, and remove duplicate points to avoid this.
Do you know of a good way to make an “approximate” curve that avoids this in a good way?

Regarding the BooleanDifference method:
Here I also need to remove duplicate points, or the resulting brep will not be solid.

I did also not get it to work without adding them to document and retrieving them again. What I noticed is that on the documentation of BooleanDifference it says that solid orientation matters when calling the method. http://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Brep_CreateBooleanDifference.htm

In my test example I have three breps, one outer and two holes. When I create them the outer brep has an inward solid orientation, while the two others are outward. After adding and retrieving from doc they are all outward. Could this be the problem? And if so, can I ensure that they will have a certain solid orientation?

Also, I set tolerance for the boolean difference to be doc.ModelAbsoluteTolerance, Incase that can be a problem.


Hi Jeper

I guess that your curve/polyline is not closed and if it is not closed then it can not produce “hole”.
It would be good if you can upload such curve/polyline to try to locate “problem” and suggest solution.
At the begining of your post you write that you have List<List> where each List represents “contour of an object”. It means that from List you can create Polyline and use all capabilities that Polyline Class has to achieve closed and valid polyline…



Hi Radovan,

Sorry for the late response.
Here is the 3d file Test File.3dm (67.4 KB)
where the lightning has 2 intersections highlighted in this image.

As you can see in the 3d file, Rhino describes the lightning as a closed curve, but as soon as you extrude the curve it warns you that the lightning is self-intersecting, and if you extrude anyways, the small intersecting pieces are “cut” from the lightning to make their own open poly surface

If you want to mess around with the List<List> just say so, and i will write provide a file and a program that can load the file into C#

Best regards,
Jesper Ravn-Nielsen

(Dale Fugier) #6

Hi @Jesper_Ravn-Nielsen,

Rather than creating a Polyline from a raw point list, you might first run the points through the Point3d.SortAndCullPointList function. Perhaps this will help prevent segments that double back.

And you really don’t need the NURB form of the polyoline. So instead of doing this:

var curve = new Polyline(Contour).ToNurbsCurve();

Do this:

var polyline = new Polyline(Contour);
var curve = new PolylineCurve(polyline);

On a side note, the curves in your model are incredibly poor. For example, the lightening bolt curve has 813 control points when it should only have 12. Poor curves create poor surfaces.

– Dale


Hi Jesper

After extracting points from your polyline you can se that there are duplicate points:

If we explode line then there are duplicate lines(segments of polyline):

So it is obvious that your list of points is source of problems. So as Dale sugested prior to cosntructing polyline you should “clean up” your list of points.
And there is so many points/segments for such a simple shape. If you can not control “quality” of points, maybe you could implement some algorithm to simplify polyline if your solution allows altering polyline.



I understand you want to work through this in Rhino, however, the root cause of the problem is the raster to vector conversion.

Do you know the origin of the file?


Sorry for the late response.

i have digged further into the requirrements of what i’m building and it turns out that i didn’t need the exported contours to be 3 dimensional after all. so what I ended up doing was to cull duplicates and then just creating polylines from the contours.

@dale, regarding the curves being very poor, there is no good way to change that, since the contours are generated from image files and thus will be jagged no matter what. However I am trying to combat that by using the smoothing function on the polyline.