BrepBrep Intersection Error

Hello, I try to get some curves from BrepBrep intersection. When I create a box and I try the code everything works fine, but when I try it with a pyramid I get this error: “Index was outside the bounds of the array”. Does anyone know how to fix it? My code is:

 Dim s As Surface = bbrep.Faces.Item(5)
             ot.Add(s)
            Dim sb As Brep = Brep.CreateFromSurface(s)
            ot.Add(sb)
            Dim supr As Boolean = Intersect.Intersection.BrepBrep(sb, brep, 0.001, crv, pts)
                      If crv(0) Is Nothing Then     ----- here I get the error for crv(0)
                RhinoApp.WriteLine("INVALID crv")
                Return Rhino.Commands.Result.Failure
            End If
            cd.AddCurve(crv(0))

Thanks.

Do not access the array before testing if any intersction occured. At that point in time (when you test on an element of the expected result array) you can no longer avoid an error, because you might not have received any array at all! (this is why you get an error sometimes)

And exactly that is what the Boolean on the row above is good for - namely for testing if you get any array at all in return from the intersection function.

Therefore try like this instead:

Dim IntersectWasFound As Boolean = Intersect.Intersection.BrepBrep(sb, brep, 0.001, crv, pts)
If Not IntersectWasFound Then
     ' Msg about the fact that no intersection occured.

// Rolf

I did it, but the error is the same.

Dim supr As Boolean = Intersect.Intersection.BrepBrep(sb, brep, 0.01, crv, pts)
If Not supr Then
RhinoApp.WriteLine(" No intersection")
Return Rhino.Commands.Result.Failure
End If

This is what I want to intersect:
pyramid
How can the pyramid not intersect those planes?

The planes are boundingbox faces , so there should be an intersection I think…

I have not tested it but there are more intersections kinds than BrepBrep (probably for a good reason) so I would suggest that BrepBrep with a zero (0) height BoundingBox would return unpredictable results…

You have also BrepSurface, and BrepPlane alternatives which probably gives more predictable results.

Here’s the entire list of intersect options. Try until it works as expected.

http://developer.rhino3d.com/5/api/RhinoCommonWin/html/Methods_T_Rhino_Geometry_Intersect_Intersection.htm

// Rolf

1 Like

Hi @catalin,

Can you post your geometry?

Thanks,

– Dale

I solved it, thanks.