Grasshopper

algorithmic modeling for Rhino

Hi all, 

 

I have a very simple question but can't find the answer:

how can i access the vertices of a brep within a vb script block? Now i'm using the brep components block but for the script I need to do this within the script itself.

 

Thnx

Views: 891

Replies to This Discussion

Hi Sander,

 

Brep.DuplicateVertices()

 

It creates a point array. There is no direct access to the vertices at present.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Is there any documentation on how to use this? I'm already stuck trying to get the Duplicate vertices into an array and loop it.

 

What I want to do is loop through the vertices of a brep and do an inclusion test with some other breps.

 

 

My goal is to make a more efficient inclusion test: instead of testing every point with every possible brep I want to do this one vertex of a brep at a time and stop the loop when one of the vertices is within a brep.

DuplicateVertices returns an array of Point3d structs. So if you want to loop over these points, you'll need to do something like:

 

For Each vertex As Point3d in myBrep.DuplicateVertices()

  'Do something with the vertex.

Next

 

To make it a bit less fuzzy, you could also store the vertices in a dedicated variable first:

 

Dim vertices As Point3d() = myBrep.DuplicateVertices()

For i As Int32 = 0 To vertices.Count - 1

  'Do something with vertices(i)

Next

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

 

Great It works! I managed to speed up the process by a lot!

I'll try to clean up the scripts and post them. Might be useful to others.

Out of curiosity, what are you trying to speed up exactly?

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

I have a set of breps (set A) which I want to place in a field of other Breps (set B). I'm looking for available places so that the new A breps dont intersect with the B breps. Therefor I do a brep-brep intersection between each element in setA and all elements in set B. This takes an awful long time to calculate (4mins and up). So I figured that I could reduce this by first checking if one of the corners of element A is inside one of the elements in set B. This already made a tremendous difference. But since it is still checking each corner of element A against all elements in set B I figured thus could be optimized some more since I'm not interested in the actual intersection itself but just any case where it would happen. So in the script I stop the loop when one of the corners is in one brep instead of first doing everything and then searching for the intersection event ( by looking if a corner of A is inside one of B).
The whole script now runs in 23sec instead of the initial 4mins.

Hope this makes it more clear. Any suggestions are more than welcome.

How about you test the BoundingBoxes of Set A and B for intersections first? BoundingBoxes are cached and it's very easy (and fast) to test for intersections. 

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

That is exactly what I'm working right know. After that I also want to integrate the physical intersection test so that the loop will also stop when a intersection is detected.

 

Take object from set A

Test for BBox intersection

Test for point inside

Test for physical intersection.

 

 

Another possible speed-up, though this one might not be measurable. You could 'sort' the order of intersections with all breps in set B from nearest to furthest. This way hopefully any intersections will happen early in the loop and you can abort quicker. There's a method on BoundingBox called ClosestPoint(), which should allow you to quickly compute the distance between the center of every brep in Set A and the bounding boxes of all breps in set B.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

 

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service