Why do my Booleans work in Rhino but fail in Grasshopper?

Every so often a question like this comes up:

BooleanIntersection gives me nothing in Grasshopper. If I bake the same two shapes and run the Rhino BooleanIntersection command, it works fine. What is Grasshopper doing wrong?

Grasshopper isn’t doing anything wrong. Rhino is doing something extra — and it happens at a moment you might not expect.

Adding an object to the document is not a passive act

When a Brep (a surface or polysurface) is added to the Rhino document, Rhino quietly cleans it up first. Two things happen:

  1. Kinked surfaces are split. A single surface that has a crease in it — an extruded rectangle, for example, is one surface with four creases — gets split into smooth (G1) pieces. Kinked surfaces cause trouble for downstream operations, so by default Rhino divides them along their creases as they come into the document. (This is the Split creased surfaces setting in Options > General.)

  2. Inside-out solids are flipped. If a closed solid’s face normals point inward, Rhino flips them so they point outward.

Neither of these happens in Grasshopper, because your geometry never goes into the document. It lives in the definition. So the Brep that reaches Brep.CreateBooleanIntersection in Grasshopper is the raw one you built, while the Brep that reaches the BooleanIntersection command has already been tidied up on its way in.

Bake, and you get the tidy version. That’s the whole mystery.

Why orientation matters so much

The inside-out case is worth dwelling on, because the symptom is nastier than a plain failure. Booleans use face normals to decide which side of a surface is “solid.” Give them a solid whose normals point the wrong way and they will often still return an answer — just not the answer you wanted.

Here is a box from (0,0,0) to (10,10,10), flipped inside out, against a box from (5,5,5) to (20,20,20). The correct results are easy to work out by hand:

Operation Inside-out input Correct result
Intersection 3250 125
Union -875 4250
Difference -4250 875

Note the negative volumes: those results are themselves inside out. Nothing failed, nothing reported an error, and every one of those answers is wrong. If you have ever chased a Grasshopper definition where the Boolean “works” but the shape is inexplicably the wrong region, this is a strong suspect.

Where do inside-out solids come from?

Usually from an innocent-looking construction. Extrude a closed profile curve and cap it, and whether the result points in or out depends on the direction your profile happens to run. A clockwise profile gives you inward normals — and nothing warns you.

This is the cleanup that construction needs:

// 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();

That is all the document does on your behalf. Two calls.

The same thing in Python, if that’s your scripting flavor:

import Rhino
import Rhino.Geometry as rg

brep.Faces.SplitKinkyFaces(Rhino.RhinoMath.DefaultAngleTolerance, True)
if brep.SolidOrientation == rg.BrepSolidOrientation.Inward:
    brep.Flip()

This isn’t an exotic practice, by the way — several Grasshopper 2 components, including the extrude components, already call SplitKinkyFaces on the Breps they produce.

Rhino 9: one call instead of two

Remembering to do this every time is the annoying part, so Rhino 9 adds a method that does exactly what the document does:

brep.PrepareForBooleans();

It splits the kinky faces, checks the solid orientation, flips it if it points inward, and returns true when the Brep is ready to use. Nothing more, nothing clever — just the document’s own cleanup, available without a document.

One caveat for Grasshopper authors: it modifies the Brep in place. If the Brep came in as a component input, duplicate it first, or you’ll be editing geometry that other components downstream are also looking at:

Brep brep = input.DuplicateBrep();
brep.PrepareForBooleans();

In lieu of the new Rhino 9 method, you can use this:

PrepareForBoolean.gh (14.1 KB)

The short version

If a Boolean behaves differently in Grasshopper than it does in Rhino, the difference is almost never the Boolean. It’s that one of the two inputs went through the document’s cleanup and the other didn’t. Split the creases, check the orientation, and the two paths agree again.

Cheers,

– Dale

Good Afternoon Dale.
Would this different in orientation justify a potential edge case using rhinoscriptsyntax that has been happening to me where rs.BooleanIntersection returns the union and rs.BooleanUnion returns the intersection of two breps defined trough rs.addbox() the points were given in a counter clock wise fashion.
I will try adding to my code your correction snippet to see if it was the cause.
Thank you for your time
Reis

Instead of extruding a planar curve and capping to make a solid, I always create a boundary surface from the planar curve and extrude that, which gives a solid and removes the need to cap.

Does it matter which method is used? Can extruding a boundary surface still create a solid with normals pointing the wrong way?

I find single curve revolved shapes that end up as (closed) single surface the most guilty for flipped normals. In this case the axis for the revolution is flipped to demonstrate the problem. The volume result is obviously wrong. The boolean operation actually works but if someone would blindly add volumes for multiple geometries this could be a problem.

single_curve_revolution_negative_volume.gh (22.0 KB)

I have tested the brep correction and it has switched back the booleanintersection and booleanunion to work as expected.

but its a very interesting edge case/error case that if both boxes have their normal inwards the booleans return valid objects but with their functionalities switched.

So again thank you so much Dale for this post it has helped a lot.
Reis

I doubt the issue I found is related to this topic, but I wanted you to be aware that I tried using your tool. Thanks for making it because I’m pretty sure I will run into this issue when preparing models for 3D printing.