'Danzer's Tiles 'Notes: ignored scope of global variables option explicit Rhino.ClearCommandHistory() 'define global variables Dim n,f Dim index 'starting index of exposedSurfaceArr Dim newTile Dim tileType Dim allObjects Dim exposedSurfaceArr,allTilesArr Dim r,k ReDim newTileSurfaces(3) 'newTileSurfaces hold all 4 newSurface arrays (1 array for each surface) ReDim newSurface(4) 'newSurface(0) are the surface geometries 'newSurface(1) are the type (A,B,C,or K) 'newSurface(2) are the pts of that surface 'newSurface(3) are the face numbers (1,2,3,or 4) 'newSurface(4) are exposed or not (T/F) Dim Flag: Flag=true Dim currentExposedSurface ReDim pointsArr(3) 'array of the 4 pts of current tile Set exposedSurfaceArr = New DynamicArray ' Create an instance of DynamicArray Set allTilesArr = New DynamicArray 'array of ALL tiles added 'function createA------------------------------------------------------------------- Function createA() 'variables ReDim A(3) 'define A(0)=Array(-0.546,-0.459,0.000) 'A1 A(1)=Array(0.405,-0.459,0.000) 'A2 A(2)=Array(0.142,0.918,0.000) 'A3 A(3)=Array(-0.021,0.229,0.500) 'A4 pointsArr(0)=Rhino.AddPoint(A(0)) pointsArr(1)=Rhino.AddPoint(A(1)) pointsArr(2)=Rhino.AddPoint(A(2)) pointsArr(3)=Rhino.AddPoint(A(3)) tileType="A" createA=A End Function 'function createB------------------------------------------------------------------- Function createB() 'variables ReDim B(3) 'define B(0)=Array(-0.405,-0.459,0.000) 'B1 B(1)=Array(0.546,-0.459,0.000) 'B2 B(2)=Array(-0.142,0.918,0.000) 'B3 B(3)=Array(-0.142,-0.033,0.309) 'B4 pointsArr(0)=Rhino.AddPoint(B(0)) pointsArr(1)=Rhino.AddPoint(B(1)) pointsArr(2)=Rhino.AddPoint(B(2)) pointsArr(3)=Rhino.AddPoint(B(3)) tileType="B" createB=B End Function 'function createC------------------------------------------------------------------- Function createC() 'variables ReDim C(3) 'define C(0)=Array(-0.479,-0.459,0.000) 'C1 C(1)=Array(0.108,-0.459,0.000) 'C2 C(2)=Array(0.371,0.918,0.000) 'C3 C(3)=Array(-0.054,0.229,0.500) 'C4 pointsArr(0)=Rhino.AddPoint(C(0)) pointsArr(1)=Rhino.AddPoint(C(1)) pointsArr(2)=Rhino.AddPoint(C(2)) pointsArr(3)=Rhino.AddPoint(C(3)) tileType="C" createC=C End Function 'function createSmc------------------------------------------------------------------- Function createSmc() 'variables ReDim Smc(3) 'define Smc(0)=Array(-0.479,-0.459,0.000) 'c1 Smc(1)=Array(0.108,-0.459,0.000) 'c2 Smc(2)=Array(0.371,0.918,0.000) 'c3 Smc(3)=Array(-0.054,0.229,-0.500) 'c4 pointsArr(0)=Rhino.AddPoint(Smc(0)) pointsArr(1)=Rhino.AddPoint(Smc(1)) pointsArr(2)=Rhino.AddPoint(Smc(2)) pointsArr(3)=Rhino.AddPoint(Smc(3)) tileType="Smc" createSmc=Smc End Function 'function createK------------------------------------------------------------------- Function createK() 'variables ReDim K(3) 'define K(0)=Array(-0.405,-0.175,0.000) 'K1 K(1)=Array(0.546,-0.175,0.000) 'K2 K(2)=Array(-0.142,0.350,0.000) 'K3 K(3)=Array(-0.142,0.169,0.250) 'K4 pointsArr(0)=Rhino.AddPoint(K(0)) pointsArr(1)=Rhino.AddPoint(K(1)) pointsArr(2)=Rhino.AddPoint(K(2)) pointsArr(3)=Rhino.AddPoint(K(3)) tileType="K" createK=K End Function 'function addExposedSurfaces---------------------------------------------------------- 'Adding surfaces to ExposedSurfacesArr-- NOTE: Did not consider c3-K4 relationship Function addExposedSurfaces(newTileSurfaces) If (newTileSurfaces(0)(1)="A") Then If (newTileSurfaces(3)(4)) Then exposedSurfaceArr.Add (newTileSurfaces(3)) 'add A4 End If 'relationships A1-C1 and A4-B4 If (newTileSurfaces(0)(4)) Then exposedSurfaceArr.Add (newTileSurfaces(0)) 'add A1 End If ElseIf (newTileSurfaces(0)(1)="B") Then 'relationships B3-K4 and B3-Smc3 and B4-A4 If (newTileSurfaces(2)(4)) Then exposedSurfaceArr.Add (newTileSurfaces(2)) 'add B3 End If If (newTileSurfaces(3)(4)) Then exposedSurfaceArr.Add (newTileSurfaces(3)) 'add B4 End If ElseIf (newTileSurfaces(0)(1)="C") Then 'relationships C1-A1 and C1=Smc1, also C2-Smc2, C3-Smc3, C4-smc4 If (newTileSurfaces(0)(4)) Then exposedSurfaceArr.Add (newTileSurfaces(0)) 'add C1 End If If (newTileSurfaces(1)(4)) Then exposedSurfaceArr.Add (newTileSurfaces(1)) 'add C2 End If If (newTileSurfaces(2)(4)) Then exposedSurfaceArr.Add (newTileSurfaces(2)) 'add C3 End If If (newTileSurfaces(3)(4)) Then exposedSurfaceArr.Add (newTileSurfaces(3)) 'add C4 End If ElseIf (newTileSurfaces(0)(1)="Smc") Then 'relationships c3-B3 and C3-K4; also Smc If (newTileSurfaces(2)(4)) Then exposedSurfaceArr.Add (newTileSurfaces(2)) 'add Smc3 End If If (newTileSurfaces(0)(4)) Then exposedSurfaceArr.Add (newTileSurfaces(0)) 'add SmC1 End If If (newTileSurfaces(1)(4)) Then exposedSurfaceArr.Add (newTileSurfaces(1)) 'add SmC2 End If If (newTileSurfaces(3)(4)) Then exposedSurfaceArr.Add (newTileSurfaces(3)) 'add Smc4 End If ElseIf (newTileSurfaces(0)(1)="K") Then 'relationships K4-B3 and K4-c3 If (newTileSurfaces(3)(4)) Then exposedSurfaceArr.Add (newTileSurfaces(3)) 'add K4 End If End If Dim count: count=exposedSurfaceArr.Count() Rhino.print(count) End Function 'function to add new tiles----------------------------------------------------------------- Function placeTile(currentExposedSurface) Dim refArray Dim targetArray: targetArray=currentExposedSurface(2) 'rnd -1 'Randomize(9) Dim random:random=rnd() Dim face 'face of newly placed tile 'check which face it is If (currentExposedSurface(1)="A") Then If (currentExposedSurface(3)=1) Then 'A1-C1 newTile=createC() refArray=Array(Rhino.PointCoordinates(pointsArr(2)),Rhino.PointCoordinates(pointsArr(1)),Rhino.PointCoordinates(pointsArr(3))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=1 ElseIf (currentExposedSurface(3)=4) Then 'A4-B4 newTile=createB() refArray=Array(Rhino.PointCoordinates(pointsArr(1)),Rhino.PointCoordinates(pointsArr(0)),Rhino.PointCoordinates(pointsArr(2))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=4 End IF ElseIf (currentExposedSurface(1)="B") Then If (currentExposedSurface(3)=3) Then If (random<.5) Then 'B3-K4 newTile=createK() refArray=Array(Rhino.PointCoordinates(pointsArr(0)),Rhino.PointCoordinates(pointsArr(1)),Rhino.PointCoordinates(pointsArr(2))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=4 Else 'B3-C3 newTile=createC() refArray=Array(Rhino.PointCoordinates(pointsArr(0)),Rhino.PointCoordinates(pointsArr(3)),Rhino.PointCoordinates(pointsArr(1))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=3 End If ElseIf (currentExposedSurface(3)=4) Then 'B4-A4 newTile=createA() refArray=Array(Rhino.PointCoordinates(pointsArr(1)),Rhino.PointCoordinates(pointsArr(0)),Rhino.PointCoordinates(pointsArr(2))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=4 End If ElseIf (currentExposedSurface(1)="C") Then If (currentExposedSurface(3)=1) Then If (random<.5) Then 'C1-A1 newTile=createA() refArray=Array(Rhino.PointCoordinates(pointsArr(2)),Rhino.PointCoordinates(pointsArr(1)),Rhino.PointCoordinates(pointsArr(3))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=1 Else 'C1-Smc1 newTile=createSmc() refArray=Array(Rhino.PointCoordinates(pointsArr(1)),Rhino.PointCoordinates(pointsArr(2)),Rhino.PointCoordinates(pointsArr(3))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=1 End If ElseIf (currentExposedSurface(3)=2) Then 'C2-Smc2 newTile=createSmc() refArray=Array(Rhino.PointCoordinates(pointsArr(0)),Rhino.PointCoordinates(pointsArr(2)),Rhino.PointCoordinates(pointsArr(3))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=2 ElseIf (currentExposedSurface(3)=3) Then If (random<.5) Then 'C3-Smc3 newTile=createSmc() refArray=Array(Rhino.PointCoordinates(pointsArr(0)),Rhino.PointCoordinates(pointsArr(1)),Rhino.PointCoordinates(pointsArr(3))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=3 Else 'C3-B3 newTile=createB() refArray=Array(Rhino.PointCoordinates(pointsArr(0)),Rhino.PointCoordinates(pointsArr(3)),Rhino.PointCoordinates(pointsArr(1))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=3 End If ElseIf (currentExposedSurface(3)=4) Then 'C4-Smc4 newTile=createSmc() refArray=Array(Rhino.PointCoordinates(pointsArr(0)),Rhino.PointCoordinates(pointsArr(1)),Rhino.PointCoordinates(pointsArr(2))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=4 End If ElseIf (currentExposedSurface(1)="Smc") Then If (currentExposedSurface(3)=1) Then 'Smc1-C1 newTile=createC() refArray=Array(Rhino.PointCoordinates(pointsArr(1)),Rhino.PointCoordinates(pointsArr(2)),Rhino.PointCoordinates(pointsArr(3))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=1 ElseIf (currentExposedSurface(3)=2) Then 'Smc2-C2 newTile=createC() refArray=Array(Rhino.PointCoordinates(pointsArr(0)),Rhino.PointCoordinates(pointsArr(2)),Rhino.PointCoordinates(pointsArr(3))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=2 ElseIf (currentExposedSurface(3)=3) Then If (random<.5) Then 'Smc3-C3 newTile=createC() refArray=Array(Rhino.PointCoordinates(pointsArr(0)),Rhino.PointCoordinates(pointsArr(1)),Rhino.PointCoordinates(pointsArr(3))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=3 Else 'Smc3-K4 newTile=createK() refArray=Array(Rhino.PointCoordinates(pointsArr(0)),Rhino.PointCoordinates(pointsArr(2)),Rhino.PointCoordinates(pointsArr(1))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=4 End If ElseIf (currentExposedSurface(3)=4) Then 'Smc4-C4 newTile=createC() refArray=Array(Rhino.PointCoordinates(pointsArr(0)),Rhino.PointCoordinates(pointsArr(1)),Rhino.PointCoordinates(pointsArr(2))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=4 End If ElseIf (currentExposedSurface(1)="K") Then If (currentExposedSurface(3)=4) Then If (random<.5) Then 'K4-B3 newTile=createB() refArray=Array(Rhino.PointCoordinates(pointsArr(0)),Rhino.PointCoordinates(pointsArr(1)),Rhino.PointCoordinates(pointsArr(3))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=3 Else 'K4-Smc3 newTile=createSmc() refArray=Array(Rhino.PointCoordinates(pointsArr(0)),Rhino.PointCoordinates(pointsArr(3)),Rhino.PointCoordinates(pointsArr(1))) Call Rhino.OrientObjects(pointsArr, refArray, targetArray) face=3 End If End If End If newTile(0)=Rhino.PointCoordinates(pointsArr(0)) newTile(1)=Rhino.PointCoordinates(pointsArr(1)) newTile(2)=Rhino.PointCoordinates(pointsArr(2)) newTile(3)=Rhino.PointCoordinates(pointsArr(3)) placeTile=face End Function Function SelfIntersection(newTileSurfaces)'------------------------------------------------------------------------------------------- Dim i,j Dim count : count = allTilesArr.EndIndex() Dim SrfsIntersection Dim ExpSurf Dim flag For i = 0 To count 'Rhino.Print("number: " & count) ExpSurf = allTilesArr.data(i) 'Call Rhino.Print("ExpSurf is: " & ExpSurf) for j = 0 to 3 SrfsIntersection = Rhino.SurfaceSurfaceIntersection(ExpSurf(0),newTileSurfaces(j)(0)) 'Call Rhino.Print("intersection number " & SrfsIntersection(0)) 'Call Rhino.Print(" the intersection number type is: " & Rhino.ObjectType(SrfsIntersection(0))) If (IsArray(SrfsIntersection)) Then 'if there is an intersection dim q For q = 0 to UBound(SrfsIntersection) Select Case SrfsIntersection(0) Case 1 Rhino.Print "Transverse surface-surface intersection curve." Rhino.DeleteObjects(Array(newTileSurfaces(0)(0),newTileSurfaces(1)(0),newTileSurfaces(2)(0),newTileSurfaces(3)(0))) Call placeTile(currentExposedSurface) Case 2 Rhino.Print "Tangent surface-surface intersection curve." i = count + 1 j = 4 flag=false Case 3 Rhino.Print "Overlap surface-surface intersection curve." i = count + 1 j = 4 flag=false Case 4 Rhino.Print "Transverse surface-surface intersection point." i = count + 1 j = 4 flag=false Case 5 Rhino.Print "Tangent surface-surface intersection point." i = count + 1 j = 4 flag=false End Select Next Rhino.print("poo+++++++++++++++++++++++++++++++++") 'if the intersection is a transverse curve If(SrfsIntersection(0) = 2) Then 'if the intersection is a tangent curve i = count + 1 j = 4 flag=false ElseIf(SrfsIntersection(0) = 3) Then 'if the intersection is an overlap curve i = count + 1 j = 4 flag=false ElseIf(SrfsIntersection(0) = 4) Then 'if the intersection is a transverse point 'Call placeTile(currentExposedSurface) i = count + 1 j = 4 flag=false ElseIf(SrfsIntersection(0) = 3) Then 'if the intersection is a tangent point i = count + 1 j = 4 flag=false end if Else 'if there is no intersection Rhino.print("no intersections") i = count + 1 j = 4 flag=false End If Next Next SelfIntersection = flag End Function Function Tetrahedron'----------------------------------------------------------------------------------------------------------- dim tetra_1_triangles dim Tetra_area_A, Tetra_area_B dim A1_points dim LineTemp1, LineTemp2, LineTemp3, LineTempMid1,LineTempMid2,LineTempMid3 redim Tetra_Curves(3) ReDim Offset_Curves(3) Dim srf1 Dim srf2 Dim i tetra_1_triangles = Array(newTileSurfaces(0)(0), newTileSurfaces(1)(0),newTileSurfaces(2)(0),newTileSurfaces(3)(0)) for i = 0 to uBound(newTileSurfaces) A1_points = newTileSurfaces(i)(2) 'rhino.print "3z: " & rhino.pt2str (A1_points(3)) LineTemp1 = rhino.addline (A1_points(0),A1_points(1)) LineTemp2 = rhino.addline (A1_points(1),A1_points(2)) LineTemp3 = rhino.addline (A1_points(2),A1_points(0)) 'LineTemp1 = rhino.addline (A1_points(1),A1_points(2)) 'LineTemp2 = rhino.addline (A1_points(2),A1_points(3)) 'LineTemp3 = rhino.addline (A1_points(3),A1_points(1)) LineTempMid1 = rhino.curvemidpoint (LineTemp1) LineTempMid2 = rhino.curvemidpoint (LineTemp2) LineTempMid3 = rhino.curvemidpoint (LineTemp3) Tetra_Curves(i) = rhino.addcurve (array(A1_points(0), LineTempMid1, A1_points(1), LineTempMid2, A1_points(2), LineTempMid3, A1_points(0)),4) 'Surf_Normal(3) = Rhino.SurfaceNormal(tetra_1_triangles(i),0,0 'Call Rhino.OffsetCurve(Tetra_Curves(i), Rhino.CurveStartPoint(Tetra_Curves(i)),0.1, Surf_Normal(i))) Call Rhino.DeleteObjects(array(LineTemp1, LineTemp2, LineTemp3)) Next Call Rhino.AddLoftSrf (array(Tetra_Curves(0), Tetra_Curves(1))) srf1=Rhino.FirstObject() Call Rhino.AddLoftSrf (array(Tetra_Curves(2), Tetra_Curves(3))) srf2=Rhino.FirstObject() Call Rhino.SelectObjects (array (srf1,srf2)) If (newTileSurfaces(0)(1)="Smc") Then Call Rhino.BooleanIntersection (array(srf1),array(srf2)) 'only works for Smc Else Call Rhino.Command("_Boolean2Objects enter ") 'only works for everything else End If Call Rhino.DeleteObjects(Tetra_Curves) End Function 'MAIN PROGRAM------------------------------------------------------------------------ 'clears what's on the screen from before allObjects=Rhino.allObjects If IsArray(allObjects) Then Rhino.deleteObjects(allObjects) End If 'start adding new tiles For n=0 to 100 'create first random tile If (n=0) then 'Rnd -1 'Randomize(9) r=rnd() If (r<.20) Then newTile=createA() ElseIf (r<.4) Then newTile=createB() ElseIf (r<.6) Then newTile=createC() ElseIf (r<1) Then newTile=createSmc() Else newTile=createK() End If Else index=ExposedSurfaceArr.StartIndex() currentExposedSurface=ExposedSurfaceArr.Data(index) f=placeTile(currentExposedSurface) call ExposedSurfaceArr.Delete(index) End If 'delete the rhino points of the new added tile call Rhino.DeleteObjects(pointsArr) 'set Surface type as Tile Type Rhino.print(TileType) newSurface(1)=TileType newSurface(4)=True Do While (flag) 'create surfaces4 newSurface(0)=Rhino.AddSrfPt (Array(newTile(0),newTile(1),newTile(2),newTile(0))) newSurface(2)=Array(newTile(0),newTile(1),newTile(2)) newSurface(3)=4 newTileSurfaces(3)=newSurface 'create surface1 newSurface(0)=Rhino.AddSrfPt (Array(newTile(1),newTile(2),newTile(3),newTile(1))) 'store surface 1 newSurface(2)=Array(newTile(1),newTile(2),newTile(3)) 'store pts of surface newSurface(3)=1 newTileSurfaces(0)=newSurface 'create surface2 newSurface(0)=Rhino.AddSrfPt (Array(newTile(0),newTile(2),newTile(3),newTile(0))) 'Surface 2 newSurface(2)=Array(newTile(0),newTile(2),newTile(3)) newSurface(3)=2 newTileSurfaces(1)=newSurface 'create surface3 newSurface(0)=Rhino.AddSrfPt (Array(newTile(0),newTile(1),newTile(3),newTile(0))) 'Surface 3 newSurface(2)=Array(newTile(0),newTile(1),newTile(3)) newSurface(3)=3 newTileSurfaces(2)=newSurface 'set the overlapped surface to not exposed If Not(n=0) Then newTileSurfaces(f-1)(4)=False flag = SelfIntersection(newTileSurfaces) End If If (n=0) Then flag=false End If Loop call Rhino.HideObjects(Array(newTileSurfaces(0)(0), newTileSurfaces(1)(0),newTileSurfaces(2)(0),newTileSurfaces(3)(0))) call Tetrahedron() For k=0 to 3 call allTilesArr.Add(newTileSurfaces(k)) Next 'add all exposed surfaces to array list call addExposedSurfaces(newTileSurfaces) flag=true Next 'PSEUDOCODE 'create random tile 'add all exposed surfaces to surface array 'pick a surface 'reorient Cplane 'attach to that surface what's available in rule set 'remove surface that's been matched 'add all exposed surfaces to surface array 'move on to next exposed in array 'takes exposed surface 'maps onto unit that corresponds 'draws the unit, storing geometry of unit with pts/array ob 'orient3d 'grabs geometry (pts) ,restores 'update array '