Rhinocommon Trim brep with opposite effect

I want to trim off some objects using a sphere. The Trim method will trim off everything outside the cutter, but I want to discard everything INSIDE it. Is there a simple way to flip this around without having to Split and then try to figure out where the pieces lie?

Hi Jim,

Not in front of Rhino at the moment but I think you need to use the Sphere.ToBrep method to make a brep from your sphere, then Brep.Flip method to reverse the brep’s normals, giving you a cutter that will remove the inside.

I don’t think the sphere object supports a Flip method itself, but you might want to check that before going via a brep.

HTH
Jeremy

Flip the cutting surface using name.Flip()

Does RhinoCommon allow you to flip a closed brep or surface (even though Rhino does not)?

Just tried it, and it does, actually… Interesting. :smile:

Yes it does, glad I could help

Cheers,

It is a bit, lol yeah.

What is also interesting is you can’t add an inverted normal solid brep to the document, it automatically flips when added. So it’s useful as a cutter while still “virtual”, but apparently one can’t “trick” Rhino into writing an inverted normal solid object into the file directly that way.

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

sphere=Rhino.Geometry.Sphere(Rhino.Geometry.Point3d(0,0,0),25)
s_brep=sphere.ToBrep()
s_brep.Flip()
sc.doc.Objects.AddBrep(s_brep)
sc.doc.Views.Redraw()

You are correct that when you add an inverted normal solid BREP to a Rhino document using the Rhino.RhinoDoc.Objects.AddBrep() method, the normal direction of the BREP is automatically flipped. This is because in Rhino, a solid BREP is defined as a closed, oriented 3D region of space with a consistent normal direction. The normal direction is used to determine which side of the BREP is considered the “outside” and which is considered the “inside”.

This behavior can be useful when using the inverted normal solid BREP as a cutter for Boolean operations, as it will cut away the “inside” of the other BREP. However, it does make it difficult to save an inverted normal solid BREP to a file using Rhinocommon C#.

To save the inverted normal solid BREP to a file, you can try the following methods:

  1. First method is to use a command from commandline like BrepFlip command in Rhino, it can invert the normal of brep.
  2. Another method is to first use the Rhino.Geometry.Brep.Flip() method to change the normal direction of the BREP, then use the Rhino.RhinoDoc.Objects.AddBrep() method to add it to the document and save it to a file.

Hope this helps !

Yes, thank you, I’m quite aware of how Rhino works and how solids are defined and used.

Neither of these work. The native Rhino command Flip (there is no BrepFlip command in Rhino) will not flip closed surfaces or polysurfaces. And, as I stated above, scriptcontext.doc.Objects.AddBrep() - same as Rhino.RhinoDoc.Objects.AddBrep() - will add an inverted normal closed brep to the document, but the normals will automatically get flipped to the outside when doing so.

As inverted normal solids are specifically not desirable in Rhino, there are all sorts of mechanisms built-in to prevent them from being added to the document. The interesting takeaway from this is that they are allowed while the the geometry remains ‘virtual’ in RhinoCommon (I never actually tried that before), so it is possible to work with them there as temporary geometry.

It is certainly possible to add what look like ‘solid’ inverted normal objects to the document, but they need to be either non-manifold or have at least one unjoined edge, so they are still considered ‘open’.

1 Like