sphere aggregation

Option Explicit
‘Script written by Shuang Xu
‘Script copyrighted by <insert company name>
‘Script version 2009年9月18日 5:14:36

Call Main()
Sub Main()
 Dim arrbasesphere,i
 For i =0 To ubound(arrbasesphere) Step 2
  Call packing(arrbasesphere(i),7)
End Sub

Function packing(basesphere,gens)
 Dim pt, center,sphere,radius,sphere1,radius1,pt1,deform, deform1
 If gens>1 Then
   If pt(2)>center(2)+radius/2 Then Exit Do
   If pt1(2)>center(2)+radius/2 Then Exit Do
  sphere1= newsphere(pt1,center,radius1)
  sphere= newsphere(pt,center,radius)
  Call rhino.ObjectLayer(deform,”deform”)
  ‘Call rhino.ObjectLayer(sphere1,”sphere2″)
  Call rhino.ObjectLayer(deform1,”sphere2″)
 Call packing(sphere,gens-1)
End If
End Function

Function ptonsrf (srf)
 Dim UDom : Udom = rhino.SurfaceDomain(srf, 0)
 Dim VDom : Vdom = rhino.SurfaceDomain(srf, 1)
 Dim Urnd : Urnd = Udom(0) + (Udom(1) – Udom(0)) * rnd
 Dim Vrnd : Vrnd = Vdom(0) + (Vdom(1) – Vdom(0)) * rnd
End Function

Function newsphere(pt,center,radius)
 Dim vector, newvector, newcenter
End Function

Function objectcenter(obj)

 Dim bbox
 ‘ get the bounding box
 bbox = Rhino.BoundingBox(obj) 
 ‘ return the center
 objectcenter = Array((bbox(0)(0) + bbox(6)(0)) / 2 , (bbox(0)(1) + bbox(6)(1)) / 2 ,  (bbox(0)(2) + bbox(6)(2)) / 2 )
End Function

Function squeeze(basesphere,squeezefactor1,squeezefactor2)
 Dim radius, center, pt, axis, plane, axisendpt, axisstartpt, midpt, param
 Dim circle, ptoncircle, ra, raend, rastart, Endraend, Endrastart, newcurve

 pt=ptonsrf (basesphere)
 plane= Rhino.CurvePerpFrame(axis, param)
 ra=rhino.scaleobject(ra,midpt, array(squeezefactor2,squeezefactor2,squeezefactor2))
 ‘ draw the curve profile
 ‘ draw revolve surface
 ‘Call rhino.DeleteObject(basesphere)
 ‘Call rhino.DeleteObjects(array(ra,axis,newcurve))
 squeeze=Rhino.AddRevSrf(newcurve, array(axisendpt,axisstartpt))
End Function

I started with packing spheres. But that is not my ultimate goal. The behavior of my machine is squeezing the material it ejected out. And the machine should detect the neighborhood and squeeze t different place and strength. The next image shows how one dimentianal squeezed geometry. (function squeeze above)

deformed geometry aggregation

I am now working on how they can react each other.

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 )

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