Different result when calling BooleanDifference vs Brep.CreateBooleanDifference in a plug-in

Hello!

Attached is a 3dm file with 2 breps - a large and a small one. When I call BooleanDifference in the regular Rhino (v5) UI to subtract the small from the large one, it works well, as I expect.

However, when I use the same objects in a Brep.CreateBooleanDifference call in my plug-in (code is attached), it doesn’t work - a Brep object is returned but IsValid = false.

Does anyone know why this is so? Am I incorrect to assume that both of those commands should result in the same outcome?

Cheers

Nic

TestBooleanDifference.3dm (159.9 KB)
TestBooleanDifference.zip (238.0 KB)

The brep created by _BooleanDifference is also invalid. I don’t know if there is a way to add invalid breps via RhinoCommon.

Steve

Hi @spb

This is the result when I use BooleanDifference. I would assume this is valid - or am I missing something?

Cheers

Nic

The Rhino result is not valid either. Try the SelBadObjects command - it selects the boolean result…
But you can see it is not valid just by looking at it - first the inner insets (the ones from the stock part) flipped their rendermesh normals - you can see through it, but even more - the operation created a non-valid geometry. Not sure how to explain it properly - if you think of solids, you created an area with zero volume on the cutline - where two outward looking surfaces meet without being connected…

edit: more clearly put: Any planar section of a Solid Brep can not have any self intersections, crossing or touching

Hi @atair

I indeed see that Rhino recognises the result as a bad object.

It’s interesting because the area where two outward-looking surfaces meet is zero - yes they meet but only for a single line. Therefore I thought that, mathematically, this could be seen as a valid surface. Certainly if the object represented the surface of wood, it would be valid.

I understand the Rhino definition you gave about what it considers a valid brep. Based on that it seems Rhino is slightly more restrictive than reality for cases like these, where relevant surfaces touch but don’t cross and where they touch but the area of contact is mathematically zero.

Cheers

Nic