Hi, I’m creating a plugin to parametrically create a 3D hull form using rhinocommon. I do this but drawing two views, extruding them into breps and then I attempt to intersect these two breps however it always returns null. The frustration comes with that I can perform the intersection just fine within rhino so it is not an issue of the geometry. If I prompt the user to select the 2 breps from the screen and pass those to Createbooleanintersection it works just fine as well. I have experimented with the tolerance, face orientation, and many other things but can’t seem to get it to work.
make sure you’re capping the extrusion, and that you’re setting the extrusion planes correctly - the normal of the plane should point to the direction of the extrusion. to make sure, after extrusion check if the resulting extrusion is a solid. You might also want to add them to the rhino doc so that you can visually inspect them.
you can try an alternative route, which is to create a planar surface from each curve (assumes the curves are closed and planar) and extrude those surfaces, then passing the resulting solids to the boolean function
let me know if i misunderstood what you were trying to accomplish
edit: might as well paste the code here
private void RunScript(Curve x, Curve y, double z, ref object a)
{
// Write your logic here
// x = first curve; y = second curve; z = extrusion distance
// create the plane for each planar curve
Plane px = new Plane(), py = new Plane();
x.TryGetPlane(out px);
y.TryGetPlane (out py);
//check to see if the plane is pointing the right direction -> flip plane if not
var orig_px = px.Origin;
var norm_px = px.Normal;
var orig_py = py.Origin;
var norm_py = py.Normal;
//flip plane normals if necessary. this only works under the assumption that the curves lie on perpendicular planes AND they could hypothetically be placed on adjacent faces of a box
if (orig_px.DistanceToSquared(orig_py) < (orig_px + norm_px).DistanceToSquared(orig_py) ) {px.Flip();}
if (orig_py.DistanceToSquared(orig_px) < (orig_py + norm_py).DistanceToSquared(orig_px) ) {py.Flip();}
//extrude the curves and cast to brep
var ex = Brep.TryConvertBrep( Rhino.Geometry.Extrusion.Create(x, px, z, true) );
var ey = Brep.TryConvertBrep( Rhino.Geometry.Extrusion.Create(y, py, z, true) );
//get model tolerance
var tol = RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;
//perform boolean intersection
var ix = Rhino.Geometry.Brep.CreateBooleanIntersection( ex, ey, tol, true);
//return the object
a = ix;
}
Hi Menno, I think I agree with you. I have tried extending the longer edges of the smaller object past the larger which made no difference. I don’t believe there is an easy way for me to extend the shorter edges however I will try.
There are a number of things that need to be tuned before performing a boolean intersection.
Ensure that all breps are solid and have their solid orientation outwards
Split faces along kinks
Use a sensible tolerance
bool PerformIntersection2Breps(List<Brep> list) // list of breps to intersect
{
if (list.Count != 2) return false;
foreach(Brep brep in list)
{
if (!brep.IsSolid) return false; // ensure solid
if (brep.SolidOrientation == BrepSolidOrientation.Inward) // ensure solid orientation is outwards
{
brep.Flip();
}
brep.Faces.SplitKinkyFaces(); // remove kinks from the faces
brep.Compact(); // remove any unsused data from the Brep
}
// perform the intersection at the document tolerance
Brep[] intersection = Brep.CreateBooleanIntersection(list[0], list[1], RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, false);
if (intersection != null)
{
foreach (Brep brep in intersection)
{
RhinoDoc.ActiveDoc.Objects.AddBrep(brep, new ObjectAttributes { Name="Result from Boolean Intersection"});
}
}
return true;
}