Dealing with Closed but Inside Out Polysurface (rhinocommon)

I am trying to join 3 breps. I make sure their normals point in directions such that when joined, they should form a closed brep (polysurface) with all normals pointing outwards. However, occasionally I end up with an inside out polysurface.

As a fix, I’ve tried using “IsPointInside” to see if it is inside out, and then using “flip”, but this does not seem to work. Another workaround I started trying was to explode the inside out brep, get the surfaces, convert these to breps, flip these breps, retrim them and then join it all back together but I wasn’t having any luck and there must be an easier way. Any suggestions?


p.s. I tried to upload an example but the progress percentage counter only seems to get up to 10% or something before giving up. Maybe 16mb is too big…

Hi Sam,

You can check for the brep solid orientation, then flip the orientation of the brep faces, in case you get “inward”:

import Rhino

joinedBrep = Rhino.Geometry.Brep.JoinBreps(listOfIndividualBreps, 0.01)[0]
if joinedBrep.IsSolid:
    if joinedBrep.SolidOrientation == Rhino.Geometry.BrepSolidOrientation.Inward:

It’s not so much a problem with logic for deciding to flip, but that the rhinocommon Flip() function doesn’t seem to worked on solid breps. Perhaps there is another way to flip and inverted solid?


BrepFaceList has a Flip method too.

I tried JoinedBrep.Faces.Flip but that doesn’t do it, so then I was trying to flip the faces and then use them to create a new brep, but then I have to deal with retrimming and I’m not having any luck…

I still can’t seem to upload my 3dm file with the inside out brep example I’m trying to do this for, so below is a drop box link instead. If someone could write a function to turn this thing right side out, I’d be grateful.


Hi Sam, the problem is that Rhino thinks this is not inside-out. You can see by exploding and joining in Rhino. The result still has normals facing inward, and that shouldn’t be the case. I’ll see if I can fix that.

There is a problem with one of your surfaces. See the attached. Your file tolerance is 0.001, but this surface has an edge that is out of tolerance by 800 times that much. The inside-out checker Does pretty much what you were doing. It picks a point outside of the bounding box of the solid, shoots a ray at the solid, takes the closest hit point on the solid and compares the normal of the hit surface to the ray direction.

In this case, by bad luck, the ray gets shot right through the gap along that edge and hits the side surface from the inside, rather than the top surface from the outside.

Here’s the file. Or maybe not. I can’t seem to upload anything. It is the small ruled surface on top.

Nice work, you nailed it. My plugin now retrims the ruled surface by the adjoining surface and voila, no more looking at its insides!