closest point sorting, seeking points after the first index - Grasshopper2024-03-29T05:02:35Zhttps://www.grasshopper3d.com/forum/topics/closest-point-sorting-seeking?commentId=2985220%3AComment%3A446989&feed=yes&xn_auth=noHere's a python version that…tag:www.grasshopper3d.com,2011-10-08:2985220:Comment:4470092011-10-08T21:30:17.732ZSteve Baerhttps://www.grasshopper3d.com/profile/SteveBaer
<p>Here's a python version that sorts the input points based on their distance from a single point and the returns the first 'n' of these. The entire script is<br/> <code><br/>
def sortfunc(a,b):<br/>
....return cmp( a.DistanceTo(the_point), b.DistanceTo(the_point) )<br/>
a = sorted(points, sortfunc)<br/>
a = a[0:int(closest_count)]<br/>
</code></p>
<p>Here's a python version that sorts the input points based on their distance from a single point and the returns the first 'n' of these. The entire script is<br/> <code><br/>
def sortfunc(a,b):<br/>
....return cmp( a.DistanceTo(the_point), b.DistanceTo(the_point) )<br/>
a = sorted(points, sortfunc)<br/>
a = a[0:int(closest_count)]<br/>
</code></p> Just came across this closest…tag:www.grasshopper3d.com,2011-10-08:2985220:Comment:4469892011-10-08T18:45:02.745ZDaniel Kautzhttps://www.grasshopper3d.com/profile/DanielKautz
<p>Just came across this closest point sorting solution. Brilliant Vicente! Thanks.</p>
<p>Just came across this closest point sorting solution. Brilliant Vicente! Thanks.</p> I tried this definition, but…tag:www.grasshopper3d.com,2011-10-01:2985220:Comment:4414822011-10-01T14:46:08.402ZKhizer Ishtiaqhttps://www.grasshopper3d.com/profile/khizerishtiaq
I tried this definition, but it gives me the one list of 2nd or 3rd closest if i replace 1 with 2 or 3, if i want the 3 most closest point, should i be using the range component??
I tried this definition, but it gives me the one list of 2nd or 3rd closest if i replace 1 with 2 or 3, if i want the 3 most closest point, should i be using the range component?? Hi Dirk
can U explain your sc…tag:www.grasshopper3d.com,2010-03-30:2985220:Comment:564692010-03-30T12:31:03.482ZAlexander Kalachevhttps://www.grasshopper3d.com/profile/AlexanderKalachev
Hi Dirk<br />
can U explain your script because the result I'm having is really strange.and I dont really understand what is a problem//<br />
<br />
Thnx<br />
Alex
Hi Dirk<br />
can U explain your script because the result I'm having is really strange.and I dont really understand what is a problem//<br />
<br />
Thnx<br />
Alex thanks for that!tag:www.grasshopper3d.com,2009-07-13:2985220:Comment:139042009-07-13T23:36:42.658ZGabrielhttps://www.grasshopper3d.com/profile/Gabriel
thanks for that!
thanks for that! or this:
tag:www.grasshopper3d.com,2009-07-13:2985220:Comment:138992009-07-13T19:09:34.089ZVicente Solerhttps://www.grasshopper3d.com/profile/VicenteSoler
or this:<br />
<p style="text-align: left;"><img src="http://storage.ning.com/topology/rest/1.0/file/get/2768588795?profile=original" alt="" width="512" height="173"/></p>
or this:<br />
<p style="text-align: left;"><img src="http://storage.ning.com/topology/rest/1.0/file/get/2768588795?profile=original" alt="" width="512" height="173"/></p> Try this:
Sub RunScript(ByVal…tag:www.grasshopper3d.com,2009-07-13:2985220:Comment:138812009-07-13T16:59:56.682ZDirk Andersonhttps://www.grasshopper3d.com/profile/DirkAnderson
Try this:<br />
<b>Sub RunScript(ByVal ptList As List(Of On3dPoint))</b><br />
<br />
Dim tree As New DataTree(Of On3dPoint)<br />
Dim pathNum As Int32 = 0<br />
Dim j As Int32 = ptList.Count() - 1<br />
<br />
nearTwo(ptList, tree, pathNum, j)<br />
<br />
pOut = tree<br />
<br />
<b>End Sub</b><br />
<br />
<b>#Region "Additional methods and Type declarations"</b><br />
Sub nearTwo (ByVal ptsIn As List(Of On3dPoint), ByRef tree As DataTree(Of On3dPoint), ByRef pathNum As Int32, ByRef j As Int32)<br />
While (j > 3)<br />
Dim path As New EH_Path(pathNum)<br />
<br />
Dim d1 As Double =…
Try this:<br />
<b>Sub RunScript(ByVal ptList As List(Of On3dPoint))</b><br />
<br />
Dim tree As New DataTree(Of On3dPoint)<br />
Dim pathNum As Int32 = 0<br />
Dim j As Int32 = ptList.Count() - 1<br />
<br />
nearTwo(ptList, tree, pathNum, j)<br />
<br />
pOut = tree<br />
<br />
<b>End Sub</b><br />
<br />
<b>#Region "Additional methods and Type declarations"</b><br />
Sub nearTwo (ByVal ptsIn As List(Of On3dPoint), ByRef tree As DataTree(Of On3dPoint), ByRef pathNum As Int32, ByRef j As Int32)<br />
While (j > 3)<br />
Dim path As New EH_Path(pathNum)<br />
<br />
Dim d1 As Double = Double.MaxValue<br />
Dim d2 As Double = Double.MaxValue<br />
Dim min1 As Int32 = -1<br />
Dim min2 As Int32 = -1<br />
<br />
For i As Int32 = 1 To j - 1<br />
Dim d As Double = ptsIn(0).DistanceTo(ptsIn(i))<br />
<br />
If (d < d1) Then<br />
d1 = d<br />
min1 = i<br />
Else If (d < d2) Then<br />
d2 = d<br />
min2 = i<br />
End If<br />
Next<br />
<br />
tree.Add(ptsIn(0), path)<br />
tree.Add(ptsIn(min1), path)<br />
tree.Add(ptsIn(min2), path)<br />
ptsIn(0) = Nothing<br />
ptsIn(min1) = Nothing<br />
ptsIn(min2) = Nothing<br />
<br />
Dim tList As New List(Of On3dPoint)<br />
For i As Int32 = 0 To j - 1<br />
If (ptsIn(i) <> Nothing) Then<br />
tList.Add(ptsIn(i))<br />
End If<br />
Next<br />
<br />
j = tList.Count()<br />
pathNum += 1<br />
<br />
'calls recursive routine<br />
nearTwo(tList, tree, pathNum, j)<br />
<br />
End While<br />
End Sub