Rhinocommon pick polysurface and find intersection with plane

Hi!
I’m very new to Rhino common and VB.net but I do have a lot of C programming experience.

I’m trying to pick a polysurface and find the intersection curve(s) with another planar surface. How do I do that? I managed to pick one surface and intersect it using Intersection.SurfaceSurface. That works great. I can also pick the polysurface but the intersection fails. Is there a trick to intersect a polysurface or do I first have to divide the polysurface into its component surfaces and then intersect one after the other?

Thanks

1 Like

A polysurface is known in RhinoCommon as a Brep (Boundary Representation). You can intersect a polysurface with a plane as follows.

protected Result RunCommand(RhinoDoc doc, RunMode mode) {
ObjRef bRef;
Result res = RhinoGet.GetOneObject("Select BREP", false, ObjectType.PolysrfFilter, out bRef);
if (res != Result.Success)
    return res;

Plane p = Plane.WorldXY; // as an example

using (Brep b = bRef.Brep())
{
    Curve[] curves;
    Point3d[] points;
    if (Intersection.BrepPlane(b, p, doc.ModelAbsoluteTolerance, out curves, out points))
    {
        if (null != curves)
        {
            foreach (Curve crv in curves)
            {
                if (null == crv || !crv.IsValid) continue;
                doc.Objects.AddCurve(crv);
            }
        }
        if (null != points)
        {
            foreach (Point3d pt in points)
            {
                if (pt.IsValid)
                    doc.Objects.AddPoint(pt);
            }
        }
    }
}
}
doc.Views.Redraw();
return Result.Success;

Thanks a lot! The hint that a polysurface is a brep was great. Below is my code that works:

        Dim gs As New Rhino.Input.Custom.GetObject()
        gs.SetCommandPrompt("Please select the hull surface")
        gs.GeometryFilter = Rhino.DocObjects.ObjectType.PolysrfFilter And DocObjects.ObjectType.Surface
        gs.SubObjectSelect = True
        gs.DeselectAllBeforePostSelect = False
        gs.OneByOnePostSelect = True
        gs.Get()
        If gs.CommandResult() <> Rhino.Commands.Result.Success Then
            Rhino.RhinoApp.WriteLine("Can't get Object")
            Return gs.CommandResult()
        End If

        Dim objref As Rhino.DocObjects.ObjRef = gs.[Object](0)

        Dim brep As Rhino.Geometry.Brep = objref.Brep()
        If brep Is Nothing Then
            Rhino.RhinoApp.WriteLine("Can't get brep")
            Return Rhino.Commands.Result.Failure
        End If

        Dim plane As Plane = plane.WorldXY

        If Not Rhino.Geometry.Intersect.Intersection.BrepPlane(brep, plane, doc.ModelAbsoluteTolerance, waterlines, Pts) Then
            Rhino.RhinoApp.WriteLine("No intersection found.")
            Return Rhino.Commands.Result.[Nothing]
        End If

Is this code possible in Python? I’ve gotten this far and stalled. I want to plot the curve:

filter = Rhino.DocObjects.ObjectType.PolysrfFilter
rc, objrefs = Rhino.Input.RhinoGet.GetMultipleObjects(“Select first set of polysurfaces”, False, filter)

in_breps0 =
for objref in objrefs:
brep = objref.Brep()
if brep: in_breps0.append(brep)

tolerance = scriptcontext.doc.ModelAbsoluteTolerance
plane = Rhino.Geometry.Plane.WorldXY
curve = Rhino.Geometry.Intersect.Intersection.BrepPlane(brep,plane,tolerance)

Thanks

Hi @eric.bunn, see if below helps:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def IntersectBrepWithPlane():
    brep_id = rs.GetObject("Brep", 8+16, True, False)
    if not brep_id: return
    
    brep = rs.coercebrep(brep_id, True)
    plane = Rhino.Geometry.Plane.WorldXY
    tolerance = scriptcontext.doc.ModelAbsoluteTolerance
    rc, crvs, pts = Rhino.Geometry.Intersect.Intersection.BrepPlane(
                                                                    brep,
                                                                    plane,
                                                                    tolerance
                                                                    )
                                                                    
    if not rc: return

    for crv in crvs: scriptcontext.doc.Objects.AddCurve(crv)
    scriptcontext.doc.Views.Redraw()
    
IntersectBrepWithPlane()

_
c.

1 Like

This works, thank you.

Eric