Grasshopper

algorithmic modeling for Rhino

# rhinoscript of recursive box

Option Explicit
'Script written by <huhooya>
'Script version 2010年10月20日 0:47:36
Call recursivebox
Sub recursivebox()
Dim arrbox,nub,sbox
arrbox = rhino.GetBox
nub =rhino.GetInteger("input a generation then wait for a while(normally less than 2)")
Rhino.EnableRedraw False
Call boxarray(arrbox,nub,sbox)
Rhino.EnableRedraw True
End Sub
Function movepoints(ByVal arrpoints, ByVal x, ByVal y, ByVal z)
Dim i,pt()
For i = 0 To Ubound(arrpoints)
ReDim Preserve pt(i)
Next
movepoints = pt
End Function

Sub boxarray(ByVal arrbox, ByVal generation, ByVal Sbox)
If generation < 0 Then Exit Sub
rhino.DeleteObject Sbox
Dim scapt(7),vec,sp(7)
Dim z
For z = 0 To 7
sp(z)=rhino.PointScale(arrbox(z),1/3)
vec=rhino.vectorcreate(arrbox(0),sp(0))
Next
Dim aX,aY,aZ
aX=(1/3)*rhino.Distance(arrbox(0),arrbox(1))
aY=(1/3)*rhino.Distance(arrbox(0),arrbox(3))
aZ=(1/3)*rhino.Distance(arrbox(0),arrbox(4))
Dim i,j,k,pt,Mbox
For i=0 To 2
For j=0 To 2
For k = 0 To 2
If Not (i*i+j*j=2) And Not (i*i+k*k=2) And Not (k*k+j*j=2)Then
pt = movepoints(scapt,i*aX,j*aY,k*aZ)
boxarray pt,generation-1,Mbox
End If
Next
Next
Next
End Sub

Views: 915

Comment

Comment by huhooya on November 3, 2010 at 8:49am
Just a try of fractal shape.
Comment by huhooya on November 3, 2010 at 8:29am
I am really sorry.
I don't know about vb.net. Perhaps you can ask some experts for help.
Comment by Alexander on November 3, 2010 at 3:43am
I translate this to VB.Net.but there is a shortage that I can't delete the bigger box from the last generation.
Looks for help...

'''''''''''''''''''''''''''''''''''''''
Sub subD_box(ByVal box As box, ByVal generation As int32, ByRef allboxes As list(Of box))
If generation - 1 < 0 Then
Exit Sub
End If
Dim subboxes As New List(Of Box)

Dim corners As Point3d()=box.getcorners
Dim xvec As Vector3d = (corners(1) - corners(0)) / 3
Dim yvec As Vector3d = (corners(3) - corners(0)) / 3
Dim zvec As Vector3d = (corners(4) - corners(0)) / 3

box.transform(transform.Scale(corners(0), 1 / 3))
For m As int32=0 To 2
For n As Int32=0 To 2
For k As int32=0 To 2
If Not (m * m + n * n = 2) And Not (n * n + k * k = 2) And Not (k * k + m * m = 2) Then
Dim sub_box As Box = box
Dim transvec As Vector3d = xvec * m + yvec * n + zvec * k
sub_box.Transform(transform.Translation(transvec))
subD_box(sub_box, generation - 1, allboxes)
' all_boxes.remove(sub_box)
End If
Next
Next
Next

End Sub

'''''''''''''''''''''''''''''''''''''''''
Comment by Arthur Mamou-Mani on November 1, 2010 at 8:52am
Housing block ?
Comment by Maurizio A. Degni on November 1, 2010 at 7:04am
the sponge! Beautiful!