Every so often a question like this comes up:
BooleanIntersectiongives me nothing in Grasshopper. If I bake the same two shapes and run the RhinoBooleanIntersectioncommand, 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:
-
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 surfacessetting in Options > General.) -
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

