Boolean Failure in RhinoCommon

I am going crazy to understand why this boolean operation fails
Using the RhinoCommon routine

Brep[] plate_with_holes = Brep.CreateBooleanDifference(Plate_w_holes, BoltList[brp], baseService.intersection_tolerance);

bool_failed.3dm (179.2 KB)

If the breps are baked into Rhino ( I am inside grasshopper) and then perform the boolean operation
it works fine

Tollerance is set to 0.001 (on mm , working in meters )

Is there anyway to understand why the boolean difference returns a boolean union ?

Hi @gerryark,

I assume the geometry in the file is “baked” from Grasshopper and, thus, not the actual input to the function above? What we probably need is a .gh file that isn’t working.

– Dale

Hi Dale
Well it’s a bit more complex than that. I am writing some custom components
in grasshopper , these objects are the result of custom code written in C# , I will see if able to make a small
gh file.
I am quite sure there is something wrong with the plate, if the object is exploded , after deleting
the unwanted parts and rebuilding the surface edge tolerances it has a weird behavior in Rhino.
I am investigating this object to see where the problem is, basically it is built from a line and a extrusion path.
The line is offset in a plane to generate a closed profile (top and bottom lines added to the left-right offset) then transformed into final position and extruded along the path.

gerry

bool_failed_2.3dm (39.3 KB)

Hi Dale
In this file I was able to get the parts involved.
If the rectangle is extruded into a solid using the “Extrude planar curve along curve” and the line as the extrusion path we get a plate.
Boolean subtract the cylinder from the plate fails with a “breps do not intersect message”

gerry

Forget the previous message
The failure is due to a bad tolerance value in options
Setting it to 0.001 fixed the issue , so I am back to my original problem

I think that I have found the source of the problem. In this example the plates are built out of a closed profile
and extruded along a path. The boolean operation becomes a union or a subtraction if the polyline orientation is flipped from ccw to cw. So it seems that I have to check orientation of the profile based on the extrusion direction to get a valid oriented brep ?

any hint ?
Gerry

Hi @gerryark,

After building your plate, you should do this:

// The profile curve is a degree=1 curve. Thus, the extruded surface will
// have kinks. Because kinked surface can cause problems down stream, Rhino
// always splits kinked surfaces when adding Breps to the document. Since
// we are not adding this Brep to the document, lets split the kinked
// surfaces ourself.
brep.Faces.SplitKinkyFaces(RhinoMath.DefaultAngleTolerance, true);

// The profile curve, created by the input points, is oriented clockwise.
// Thus when the profile is extruded, the resulting surface will have its
// normals pointed inwards. So lets check the orientation and, if inwards,
// flip the face normals.
if (BrepSolidOrientation.Inward == brep.SolidOrientation)
  brep.Flip();

...

– Dale

Hi Dale
thanks for the hint. Unfortunately it does not solve the issue
I have solved using this code

CurveOrientation orientation = mProfile.ClosedCurveOrientation();
if (orientation == CurveOrientation.CounterClockwise && local_ex_dir.Z<0 || orientation == CurveOrientation.Clockwise && local_ex_dir.Z > 0)
mProfile.Reverse();

This is done in the local World X-Y plane and the local_ex_dir is the unit vector of the extrusion line

I had a similar problem of using Boolean operations on solids in RhinoCommon and getting inconsistent results. The orientation check did the trick.

Thank you Dale :slight_smile: