# MS-Find Your Partners

Ulimatly, this script will group a field of points in sets of three based on distance. Right now it only finds the point farthest from the point cluster’s center, then finds its closest neighbors. Option Explicit
‘Script written by <mathew staudt>
‘Script copyrighted by <no>
‘Script version Wednesday, October 01, 2008 1:47:11 PM

Call Main()
Sub Main()
Dim ObjPoints, arrPoints(), i, j, k, L,p
Dim arrBBox, arrCntrPt
Dim DblDistTest, WinningDist, WinnerPt, lineTest
Dim WinnTri, WinnTriLength, lineTestLength, WinTriPoints

”Get Points
ObjPoints = Rhino.GetObjects (“Select Your Shit Slinging Robots”, 1)
For i=0 To Ubound(ObjPoints)
ReDim Preserve arrPoints(i)
arrPoints(i)= Rhino.PointCoordinates (ObjPoints(i))
Next

”Find Center Of Points

arrBBox = Rhino.BoundingBox(ObjPoints)
arrCntrPt = array((((arrBBox(2)(0)) + (arrBBox(0)(0))) / 2), (((arrBBox(2)(1)) + (arrBBox(0)(1))) / 2), (((arrBBox(0)(2)) + (arrBBox(4)(2))) / 2))

”Find Point Furthest From Center

For p=0 To Ubound(arrPoints)
DblDistTest = Rhino.Distance (arrCntrPt, arrPoints(p))
If DblDistTest > WinningDist Then
WinningDist = DblDistTest
WinnerPt = arrPoints(p)

End If
Next

”Find Smallest Triangel From Winning Point
WinningDist = 500
WinnTriLength = 500

For j=0 To Ubound (arrPoints)
If Rhino.PointCompare (WinnerPt, arrPoints(j)) = False Then
For k=j To Ubound (arrPoints)
If k<>j And Rhino.PointCompare (WinnerPt, arrPoints(k)) = False Then
If j = 0 Then
WinnTri = Rhino.AddPolyline (Array(WinnerPt,arrPoints(j), arrPoints(k),WinnerPt))
WinnTriLength = Rhino.CurveLength(WinnTri)
Else
lineTest = Rhino.AddPolyline (Array(WinnerPt, arrPoints(j), arrPoints(k),WinnerPt))
lineTestLength = Rhino.CurveLength(lineTest)
If lineTestLength < WinnTriLength Then
‘Rhino.DeleteObject (WinnTri)
WinnTriLength = lineTestLength
WinnTri = lineTest
Else
‘Rhino.DeleteObject (lineTest)
End If
End If
End If
Next
End If
Next

WinTriPoints = Rhino.PolylineVertices (WinnTri)
For i=0 To Ubound (WinTriPoints)-1