Grasshopper

algorithmic modeling for Rhino

 

Hello,

I'm looking for an example with intersection.Brep.Brep.

Thanks for help!!!!

Views: 3899

Replies to This Discussion

I try that but...

 

Private Sub RunScript(ByVal L_Brep As List(Of Brep), ByRef A As Object)
    Dim intCirc As New Circle


    Dim j As BrepBrepIntersection = Rhino.Geometry.Intersection.BrepBrep(L_Brep(1), L_Brep(2), intCirc)

    A = IntCirc

So difficult to understand the RhinoCommon SDK....sniff

Hi RG,

 

instead of just giving the answer, allow me to try and explain how this function works, maybe it will clarify the general logic of the SDK a bit.

 

According to this page, the BrepBrep() method has the following signature:


Public Shared Function BrepBrep( _
  brepA As Brep, _
  brepB As Brep, _
  tolerance As Double, _
  ByRef intersectionCurves As Curve(), _
  ByRef intersectionPoints As Point3d()) _
  As Boolean

This function takes three bits of information and it returns three as well. The first three parameters (brepA, brepB and tolerance) allow you to specify the details for this specific function call. Obviously you need to supply two Breps, otherwise the function wouldn't know what geometry to work on. You also need to specify a tolerance, since we don't provide a default one.

 

The three bits of information that come out of this function are a bit more complex. The return value of this function is a single Boolean, indicating success or failure. If the function fails, it could mean the input was invalid geometry, or it could mean the given tolerance did not allow for a solution, or it could just mean our intersector algorithm is not good enough and it choked on something that should have worked.

 

The other two "outputs" are disguised as function parameters. When you intersect two breps, you can end up with any amount of curves and/or points. We return these lists of curves and points using the last two parameters in the signature (intersectionCurves and intersectionPoints). We require that you supply placeholders for this data, but not the data itself (that is after all raison d'etre for this function).

 

So when we ask for a ByRef intersectionCurves As Curve() and a ByRef intersectionPoints As Point3d()

 

You need to supply exactly that. You are currently not providing anything for intersectionPoints and instead of an array of Curves you supply a single Circle. Neither of these transgressions is acceptable and therefore the compiler will not play ball. You'll need to fix both these issues before your code will compile and run.

 

As you can imagine, when two breps intersect, you only very rarely end up with a single circle. You'll need to provide an array of Curves and an array of Point3ds, but you won't have to 'construct' or 'instantiate' them. Like so:

 

Dim crvs As Curve() = Nothing

Dim pts As Point3d() = Nothing

If (Rhino.Geometry.Intersection.BrepBrep(L_Brep(0), L_Brep(1), crvs, pts)) Then

  If (crvs Is Nothing OrElse crvs.Length = 0) Then

    Print("Intersection returned no results")

  Else

    A = crvs

    'Or, if you only care about the first curve, then do:

    'A = crvs(0)

  End If

Else

  Print("Intersection failed")

End If

 

The first two lines declare the placeholders which will be filled out by the BrepBrep() function. I used the = Nothing assignment to pacify the compiler. It sometimes get itchy when you pass data into a function that is null. By specifically assigning Nothing to the two arrays we convince the compiler we know what we are doing. This will not fail to compile, but there probably will be a warning.

 

I check the return code of BrepBrep() and take affirmative action if False is returned. I didn't really need to do this, if the function failed then the crvs and pts arrays should be null, which I also check for, but this does provide more detailed information to the end user. There is after all a big difference between two breps really not intersecting and Rhino not being able to find the intersection.

 

A last word on data conversions. Grasshopper is pretty clever about converting data into different types. If you plug a circular nurbs-curve into a Circle parameter, it will get automatically converted to an actual circle. If you plug a flat, closed curve into a Surface parameter, it will automatically create a trimmed planar surface. When you are writing code this will not happen. You need to be very specific about the types of data you use and whether or not it's an array, or a list, or a collection, or a datatree or just a single instance. VB.NET and C# do not try to second guess your intentions as Grasshopper does.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Hi David,

Thanks so much for the explication about the logic of SDK.

This's a lot more clear now.

Your answer is a gift.

 

Best regards,

 

Renaud Ganière

Private Sub RunScript(ByVal L_Brep As List(Of Brep), ByRef A As Object)

    Dim L_Crv As New List (Of Object)
    Dim crvs As Curve() = Nothing
    Dim pts As Point3d() = Nothing

    For i As Integer = 0 To L_Brep.Count() - 2

      If (Rhino.Geometry.Intersect.Intersection.BrepBrep(L_Brep(i), L_Brep(i + 1), 0.001, crvs, pts)) Then

        If (crvs Is Nothing OrElse crvs.Length = 0) Then

          Print("Intersection returned no results")

        Else

          L_Crv.Add(crvs)

        End If

      Else

        Print("Intersection failed")

      End If


    Next

    A = L_Crv

Is it possible to run a BrepBrep boolean test so that it simply returns True/False if two breps intersect? within Rhinocommon of course

No, you have to run the full intersection. I'll ask if it makes sense to add a set of collision methods if they can be made significantly faster than the intersectors.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service