(n)certainties – Columbia – Fall 2008

ML_Spicule Generator

Option Explicit
‘Script written by <Matthew Lutz>
‘Script version Monday, October 06, 2008 11:47:41 PM

Dim triangleCrv, vertexPts, endpt1, endpt2, endpt0, newSpicule, gens, origPt, origPtCoord

Call SpiculeGenerator()
Sub SpiculeGenerator()
 
 gens = Rhino.GetReal(“How many generations?”, 50)
 origPt = Rhino.GetObject(“choose a starting point”, 1)
 origPtCoord = Rhino.PointCoordinates (origPt)

‘This is just a quick bit to get the first three starting points (equilateral triangle)
 endPt0 = Rhino.AddPoint (Array(origPtCoord(0), origPtCoord(1) + 7, origPtCoord(2)))
 endPt1 = Rhino.RotateObject (endPt0, origPtCoord, 120.0, , True)
 endPt2 = Rhino.RotateObject (endPt1, origPtCoord, 120.0, , True)
  
 endPt0 = Rhino.PointCoordinates (endPt0)
 endPt1 = Rhino.PointCoordinates (endPt1)
 endPt2 = Rhino.PointCoordinates (endPt2)

Call RecursiveGrowth()

End Sub
 
Sub RecursiveGrowth()

 Dim i, currentType, arrTypes, Rand, RadS, RadM, RadL, RadXL, arrAllSpicules()
 Dim newEndPt0(), newEndPt1(), newEndPt2(), newEndPt3()
 Dim sphereTest(), ptOnBaseLine1(), ptOnBaseLine2(), ptOnBaseLine3(), ptOnTopLine1(), j
 Dim sphereCtrPt()
 
 For i = 0 To gens
  
  ’set up the dynamic array to add another unit each time
  ReDim Preserve arrAllSpicules(i)
 
  If i<2 Then
   arrAllSpicules(i) = AddNewSpicule(endPt0, endPt1, endPt2)
   
  Else
     ‘choose the current type – each holds a radius value
    ’type = (top leg, base leg) — There are 4 sizes of units to be placed
   
       RadS = 1.75
       RadM = 3.5
       RadL = 5.25
       RadXL = 7
       arrTypes = Array(RadS, RadM, RadL, RadXL)
      
     ‘a random Function To Select the currentType from an Array of all 4 possible
    Rand = Random(0,3)
    currentType = arrTypes(Rand)
   
   ReDim Preserve sphereTest(i)
   sphereTest(i) = Rhino.AddSphere (arrAllSpicules(i-1)(1)(4), currentType)
   
   ReDim Preserve ptOnBaseLine1(i)
   ReDim Preserve newEndPt0(i)
   ptOnBaseLine1(i) = Rhino.CurveSurfaceIntersection(arrAllSpicules(i-1)(0)(0), sphereTest(i))
   If IsArray(ptOnBaseLine1(i)) Then
     
       Call Rhino.AddPoint (ptOnBaseLine1(i)(0,1))
       newEndPt0(i) = Rhino.FirstObject
       newEndPt0(i) = Rhino.PointCoordinates (newEndPt0(i))
   
        Else
  
        Rhino.Print “Curve and surface do not intersect.”
        newEndPt0(i) = Rhino.AddPoint (arrAllSpicules(i-1)(1)(4))
        newEndPt0(i) = Rhino.PointCoordinates (newEndPt0(i))

   End If
   
 If currentType = 5.25 Then
  ReDim Preserve ptOnBaseLine2(i)
  ReDim Preserve newEndPt1(i)
  ptOnBaseLine2(i) = Rhino.CurveSurfaceIntersection(arrAllSpicules(i-1)(0)(2), sphereTest(i))
     If IsArray(ptOnBaseLine2(i)) Then
   
         Call Rhino.AddPoint (ptOnBaseLine2(i)(0,1))
         newEndPt1(i) = Rhino.FirstObject
         newEndPt1(i) = Rhino.PointCoordinates (newEndPt1(i))
        
         Else
        
         Rhino.Print “Curve and surface do not intersect.”
         newEndPt1(i) = Array(newEndPt0(i)(0), newEndPt0(i)(1), newEndPt0(i)(2)-7)
     End If
       
 Else
     
  ReDim Preserve ptOnBaseLine2(i)
  ReDim Preserve newEndPt1(i)
  ptOnBaseLine2(i) = Rhino.CurveSurfaceIntersection(arrAllSpicules(i-1)(0)(1), sphereTest(i))
    If IsArray(ptOnBaseLine2(i)) Then
   
       Call Rhino.AddPoint (ptOnBaseLine2(i)(0,1))
       newEndPt1(i) = Rhino.FirstObject
       newEndPt1(i) = Rhino.PointCoordinates (newEndPt1(i))
        
       Else
        
       Rhino.Print “Curve and surface do not intersect.”
       newEndPt1(i) = Array(newEndPt0(i)(0), newEndPt0(i)(1), newEndPt0(i)(2)+7)
    End If
   
  End If
  
   ReDim Preserve ptOnTopLine1(i)
   ReDim Preserve newEndPt2(i)
   ptOnTopLine1(i) = Rhino.CurveSurfaceIntersection(arrAllSpicules(i-1)(0)(3), sphereTest(i))
   If IsArray(ptOnTopLine1(i)) Then
              
       Call Rhino.AddPoint (ptOnTopLine1(i)(0,1))
       newEndPt2(i) = Rhino.FirstObject
       newEndPt2(i) = Rhino.PointCoordinates (newEndPt2(i))
       
        Else
       
        Rhino.Print “Curve and surface do not intersect.”
        newEndPt2(i) = Array(newEndPt0(i)(0), newEndPt0(i)(1)+7, newEndPt0(i)(2))
     
   End If
   
   ReDim Preserve ptOnBaseLine3(i)
  ReDim Preserve newEndPt3(i)
  ptOnBaseLine3(i) = Rhino.CurveSurfaceIntersection(arrAllSpicules(i-1)(0)(2), sphereTest(i))
  If IsArray(ptOnBaseLine3(i)) Then
   
         Call Rhino.AddPoint (ptOnBaseLine3(i)(0,1))
         newEndPt3(i) = Rhino.FirstObject
         newEndPt3(i) = Rhino.PointCoordinates (newEndPt3(i))
       
          Else
       
          Rhino.Print “Curve and surface do not intersect.”
          newEndPt3(i) = Array(newEndPt0(i)(0)+7, newEndPt0(i)(1), newEndPt0(i)(2))
     End If
   
   ’ptOnBaseLine3 = Rhino.CurveSurfaceIntersection (arrAllSpicules(i-1)(0)(2), sphereTest)
   ’newendPt1 = Rhino.AddPoint(ptOnBaseLine2(i,1))
   
   arrAllSpicules(i) = AddNewSpicule(newEndPt0(i), newEndPt1(i), newEndPt2(i))
   Rhino.DeleteObject (sphereTest(i))
   
   End If
   Next

End Sub

‘random function
Function Random(min, max)
 
 Randomize()
 Random = Int((max – min) * Rnd + min)
 
End Function
””””” This is the function that gets called each time
””””” It takes 3 starting points as inputs
””””” This one seems to be working OK because it builds the first one fine…
Function AddNewSpicule(startPt0, startPt1, startPt2)
 AddNewSpicule = Null
 
 Dim centerPt, newCenterPt, topCenterPt, strLabel
 Dim baseLine1, baseLine2, baseLine3, baseLine4Top, dblRadius, crvNormal
 Dim triangle, offTriangle, offTriangle2
 Dim strCircle, CirclePlane, offCirclePlane1, offCirclePlane2, offCircleCurve1, offCircleCurve2 

 strCircle = Rhino.AddCircle3Pt (startPt0, startPt1, startPt2)
 centerPt = Rhino.CircleCenterPoint (strCircle)
 CirclePlane = Rhino.AddPlanarSrf (Array(strCircle))
 crvNormal = Rhino.CurveNormal(strCircle)

 dblRadius = Rhino.CircleRadius (strCircle) 
 offCirclePlane1 = Rhino.OffsetSurface(CirclePlane(0), dblRadius * 0.707)
 newCenterPt = Rhino.SurfaceAreaCentroid(offCirclePlane1)
 ’strLabel = Rhino.AddTextDot (Rhino.Pt2Str(newCenterPt(0)), newCenterPt(0))

 offCirclePlane2 = Rhino.OffsetSurface(offCirclePlane1, dblRadius * 2)
 topCenterPt = Rhino.SurfaceAreaCentroid(offCirclePlane2)
 
 ’ draw 3 new base lines and one top line
 baseLine1 = Rhino.AddLine(startPt0, newCenterPt(0))
 baseLine2 = Rhino.AddLine(startPt1, newCenterPt(0))
 baseLine3 = Rhino.AddLine(startPt2, newCenterPt(0))
 baseLine4Top = Rhino.AddLine(newCenterPt(0), topCenterPt(0))
 
 Dim arrSpiculeLines, arrSpiculePoints, arrSpiculeVectors
 
 Rhino.DeleteObject strCircle
 Rhino.DeleteObject CirclePlane(0)
 Rhino.DeleteObject offCirclePlane1
 Rhino.DeleteObject offCirclePlane2
 
 ”’make the pipes
 Rhino.SelectObject baseLine1
 Rhino.Command(“Pipe .25 .25 _enter”)
 Rhino.UnselectAllObjects
  
 Rhino.SelectObject baseLine2
 Rhino.Command(“Pipe .25 .25 _enter”)
 Rhino.UnselectAllObjects
  
 Rhino.SelectObject baseLine3
 Rhino.Command(“Pipe .25 .25 _enter”)
 Rhino.UnselectAllObjects
  
 Rhino.SelectObject baseLine4Top
 Rhino.Command(“Pipe .25 .25 _enter”)
 Rhino.UnselectAllObjects
  ‘now it collects all the info generated into an array that we can refer to
 arrSpiculeLines = Array(baseLine1, baseLine2, baseLine3, baseLine4Top)
 arrSpiculePoints = Array(startPt0, startPt1, startPt2, centerPt, newCenterPt(0), topCenterPt(0))
 arrSpiculeVectors = Array(crvNormal, dblRadius)
 
 AddNewSpicule = Array(arrSpiculeLines, arrSpiculePoints, arrSpiculeVectors)
 ’ whatever it returns should have all the info you need to place the next one(within nested array)…

End Function

Leave a Comment

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment