Grasshopper

algorithmic modeling for Rhino

Hi
I'm looking for conceptual advice - I have problem that I think I can solve with a nested two part search for closest points but I'm wondering if there is already a way to do this in one fell swoop.

I have a curve and a collection of points. I want to get the parameter along a curve of the closest point to the curve from that collection. I could see that you might get the closest point on the curve for each in the collection and then sort that for the lowest - but this seems complicated. Just wondering if anyone has a quicker way...

Views: 424

Replies to This Discussion

Gabriel,

you can check closest point and corresponding distances within one loop, sending the nearest point to either a list or directly out of the component.

Sub RunScript(ByVal inPts As List(Of On3dPoint), ByVal crv As OnCurve)

Dim d1 As Double = Double.MaxValue
Dim min1 As Int32 = -1

For i As Int32 = 1 To inPts.Count() - 1
Dim t As New Double
crv.GetClosestPoint(inPts(i), t)
Dim cPt As New On3dPoint
cPt = crv.PointAt(t)
Dim d As Double = inPts(i).DistanceTo(cPt)

If (d < d1) Then
d1 = d
min1 = i
End If

Next

A = inPts(min1)

End Sub
thanks alot. works like a charm
Dirk

What do you input into A and B for the vb.net component?

and is there any output component necessary to achieve successful results?

cheers!

benjamin
Hi, Dirk:

Your code works great. Thx. However, in the following code, tt seems the intelligence don't have distanceTo() method but if I put it in, it works. Do you know why?

Dim d As Double = inPts(i).DistanceTo(cPt)
Probably because the intellisense in the GH editor sucks compared to what you get in VS. If you do a bunch of things in one line (like declare a variable and access a list) then it gets confused and doesn't show up. It also doesn't like doing a lot of nested stuff either.
I see. Thx, Damien.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service