Grasshopper

algorithmic modeling for Rhino

hi all,
i have a simple question. i have a list of points going into my vb.net and i need to extract them one at a time to get the distance from that point to all of the other points in the list. what is the process for looking at one case in an array at a time? this is something that could probably be done easier without scripting but im trying to learn stuff i already know how to do to learn the potentials here.
I assume it starts:

For i=0 As New Integer To list.Count() -1
Dim pt As New On3dPoint(list(i))  ......

pretty new to scripting so any help is very welcome.

thanks

Views: 296

Replies to This Discussion

Hi Nels,

here's a simple loop that runs over all the points and creates a new list with distances from all those points to an anchor point:

Dim distances As New List(Of Double)
For Each pt As Point3d in points
   distances.Add(pt.DistanceTo(anchor)
Next


Here's a for loop that does the same thing:

Dim distances As New List(Of Double)
For i As Integer = 0 To points.Count-1
   distances.Add(points(i).DistanceTo(anchor)
Next


Finally, two nested for loops to find the distance from every point in the set to it's closest neighbour:

Dim distances As New List(Of Double)
For i As Integer = 0 To points.Count-1
   Dim mindist As Double = Double.MaxValue
   For j As Integer = 0 To points.Count-1
     If (i = j) Then Continue For
     mindist = Math.Min(mindist, points(i).DistanceTo(points(j)))
   Next
   distances.Add(mindist)
Next


--
David Rutten
david@mcneel.com
Seattle, WA
ps, you'll notice I use Point3d instead of On3dPoint. On3dPoint is the point class in the old SDK, Point3d is the RhinoCommon type. I'd highly recommend you use RhinoCommon (i.e. Grasshopper 0.7 or above) as it is a much cleaner SDK.

--
David Rutten
david@mcneel.com
Seattle, WA
thank you much!
David this was great information, actually answered a lot of questions i didnt have yet. All i'm really looking for though is the correct syntax to reference one point in a list of points. something similar to the button in GH where you input a list and set an integer and are able to alter that one point from the list. thanks again!

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service