Grasshopper

algorithmic modeling for Rhino

Hi. Although I'm not new to grasshopper but I am to the VB.NET component/scripting. I am taking an intro class right now in VB but it's very different than what I saw in the LIFT Primer! I am really hoping that you can help me out.. I feel like what I am looking to do is very easy (I don't think it's doable with just GH though? If I'm wrong please tell me !!!)

The specific situation is I have a field of say 20 points randomly assorted. For each point, I want to find its nearest point (through drawing a vector to each point and calculating the minimum?) and then draw a line between the two. The way I have been doing this has been to make a separate GH function for each point while shifting the list of items 1 per function, but when I have over 20, over 100! items this becomes extremely tedious (to say the least..)

Thank you very much for any help you can give.. If you need any more information or a sample file please let me know.

Thanks

Nick

EDIT: What I'm actually looking to do at this point, because I've already gone through manually and done all 115 of these with their unique functions is find the SECOND nearest point. In making an individual GH function per point it means creating a vector to each point, sorting the results, extracting the second solution, making a line of that vector. I am thinking that whether it is the first closest or second closest point wouldn't make that much of a difference within the script... I hope I am right, because I have a feeling I need to do this many different times!!

Views: 1120

Replies to This Discussion

Are you more interested in getting it done or getting it done efficiently? The reason why I ask is that you seam to be pretty much on the right track in regards to getting this done, although I think your actual approach is a little off. If you want to get this done efficiently (something that's probably not worth if for less than a few hundred points), your better off creating some sort of space divisioning structure (bsd tree, quadtree, octtree) and use that to more effectively search your points.

For less then 3-400 points, I'd just stick to the easy way, but there are a few things I would suggest. First of all, you just need a double For...Loop on this one rather than "shifting" the list. Just check and see if your counter from the first loop is equal to the count of your second loop before testing (because you know that that will be the same point). Secondly, I wouldn't go about "making" vectors. Creating a new object has a certain amount of overhead as well as some unmanaged calls to C++ so that has the potential to slow things down. All your looking for is the number that represents the distance and the index of the point for that distance. Just keep the shortest one (or two) of those around and that's all you need. Thirdly, you can speed up this by cutting a few corners with the distance function. The distance between two points in 3D space is just the pythagorean therom with an extra variable for the added dimension (so sqr(x^2 + y^2 + z^2) instead of just x & y). The other thing is that because you are only looking for the relative distance (ie you just care which one is closer, not HOW close it is), then you can get away from squaring the result and just using the therom in its unsquared form. Since taking the square root is the most expensive part of that equation, that should help keep things speedy without needing some spatial division.

Also, this can be done relatively easily directly in GH. See attached. Note this will create double lines in some cases.
Attachments:
I think you can avoid 3 components by directly connecting the points to the A input of the sort component.
yea, I guess I just have the habit of looking for things via index....
In case you'd like to automatize what you where doing by hand (shifting the list) use something like this:

Wow. It looks like I seriously need to learn how to use trees. I knew the answer was somewhere in there (and even in graft) but I just wasn't sure how (and where) to use it. It turns out that I only needed to do it about 10 times (though it would be interesting to see it truly grow over the whole 115 points). I've been doing a bunch of stuff similar to this recently; these responses serve as a fantastic guide on how to learn about how both trees and VB.NET work!

Thank you, sincerely.
Hi guys
does anyone know a reference, or a way to write it in VB.net,to make it work a bit faster?

I would need this kin of function but as a recursive one...

Thnx

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service