|
請用SORT這個運算器如圖
或是使用下列語法看看
Try this:
Sub RunScript(ByVal ptList As List(Of On3dPoint))
Dim tree As New DataTree(Of On3dPoint)
Dim pathNum As Int32 = 0
Dim j As Int32 = ptList.Count() - 1
nearTwo(ptList, tree, pathNum, j)
pOut = tree
End Sub
#Region "Additional methods and Type declarations"
Sub nearTwo (ByVal ptsIn As List(Of On3dPoint), ByRef tree As DataTree(Of On3dPoint), ByRef pathNum As Int32, ByRef j As Int32)
While (j > 3)
Dim path As New EH_Path(pathNum)
Dim d1 As Double = Double.MaxValue
Dim d2 As Double = Double.MaxValue
Dim min1 As Int32 = -1
Dim min2 As Int32 = -1
For i As Int32 = 1 To j - 1
Dim d As Double = ptsIn(0).DistanceTo(ptsIn(i))
If (d < d1) Then
d1 = d
min1 = i
Else If (d < d2) Then
d2 = d
min2 = i
End If
Next
tree.Add(ptsIn(0), path)
tree.Add(ptsIn(min1), path)
tree.Add(ptsIn(min2), path)
ptsIn(0) = Nothing
ptsIn(min1) = Nothing
ptsIn(min2) = Nothing
Dim tList As New List(Of On3dPoint)
For i As Int32 = 0 To j - 1
If (ptsIn(i) <> Nothing) Then
tList.Add(ptsIn(i))
End If
Next
j = tList.Count()
pathNum += 1
'calls recursive routine
nearTwo(tList, tree, pathNum, j)
End While
End Sub |
|