Sphere Packing on a Complex Surface

This RhinoScript packs a layer of spheres on a bowl shaped surface starting from the lowest possible sphere and working  its way upwards in order to partially simulate physically placing balls in a bowl.

Sphere Packing on a Complex Surface
Option Explicit
‘Script written by <Ayodh Kamath>
‘Script copyrighted by <Ayodh Kamath>
‘Script version Thursday, June 17, 2010 11:32:09 AM
Call Main()
Sub Main()
Dim strSrf, arrSpheres, strSphere1, strSphere2, arrTanSpheres, arrCullSpheres, intSphereNum, arrSortSpheres
Dim arrCentre1, arrCentre2, strTextDot
Dim i, j, k
strSrf = Rhino.GetObject(“Select surface”, 8 )
arrSpheres = Rhino.GetObjects(“Select initial spheres starting with the two seed spheres”, 8 )
strSphere1 = arrSpheres(0)
strSphere2 = arrSpheres(1)
intSphereNum = UBound(arrSpheres)
‘Call Rhino.EnableRedraw(False)
arrTanSpheres = TangentSpheres(strSrf, strSphere1, strSphere2)
arrCullSpheres = OverlapEliminate(arrTanSpheres, arrSpheres)
For i = 0 To UBound(arrCullSpheres)
If Rhino.IsObject(arrCullSpheres(i)) Then
intSphereNum = intSphereNum + 1
ReDim Preserve arrSpheres(intSphereNum)
arrSpheres(intSphereNum) = arrCullSpheres(i)
End If
Next
arrSortSpheres = SphereSort(arrSpheres)
arrSpheres = arrSortSpheres
For i = 0 To UBound(arrSpheres)
arrCentre1 = SphereCentre(arrSpheres(i))
strTextDot = Rhino.AddTextDot(CStr(i), arrCentre1)
For j = 0 To UBound(arrSpheres)
arrCentre2 = SphereCentre(arrSpheres(j))
If Rhino.Distance(arrCentre1, arrCentre2) < 4 And Rhino.Distance(arrCentre1, arrCentre2) > 0.1 Then
arrTanSpheres = TangentSpheres(strSrf, arrSpheres(i), arrSpheres(j))
arrCullSpheres = OverlapEliminate(arrTanSpheres, arrSpheres)
For k = 0 To UBound(arrCullSpheres)
If Rhino.IsObject(arrCullSpheres(k)) Then
intSphereNum = intSphereNum + 1
ReDim Preserve arrSpheres(intSphereNum)
arrSpheres(intSphereNum) = arrCullSpheres(k)
Call Rhino.MessageBox(“Number of spheres = “&CStr(intSphereNum+1))
arrSortSpheres = SphereSort(arrSpheres)
arrSpheres = arrSortSpheres
End If
Next
End If
Next
Next
‘Call Rhino.EnableRedraw(True)
End Sub
Function TangentSpheres(strSrf, strSphere1, strSphere2)
End Function
Function JoinCurve(arrCrvs)
End Function
Function OverlapEliminate(arrSpheres1, arrSpheres2)
End Function
Function SphereSort(arrSpheres)
End Function
Function SphereCentre(strSphere)
End  Function
Advertisements

3 thoughts on “Sphere Packing on a Complex Surface

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s