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))
 ”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))
 Rhino.addsphere arrCntrPt, 5
 ”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
 Rhino.addsphere WinnerPt, 5
 ”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)
      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
       ‘Rhino.DeleteObject (lineTest)
      End If
     End If
    End If
  End If


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

End Sub

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s