EM_Torus nGen

This is the first trial for a script (video) that draws several generations of torus and print their center points to draw a trajectory through them:

Option Explicit
‘Scripted by Eduardo Mayoral

Call Main()
Sub Main()
 
 ‘===================================
 ‘  Set Up Starting Position
 ‘===================================
 
 Dim arrPt1, nGen, currentTorus
  
 arrPt1 = Rhino.GetPoint (“enter starting point”)
 nGen = Rhino.GetInteger (“specify number of generations”)

 If IsArray(arrPt1) Then
  
  Generate arrPt1, nGen, currentTorus
    
 End If
 
End Sub

Function Generate(arrPt, nGen, currentTorus)
 
 ‘============================================
 ‘  Drawing Tours
 ‘============================================
 
 If currentTorus < nGen Then
 
  Dim i, arrBase, dblMajorRadius, dblMinorRadius, arrDirection

  For i = 1 To nGen

dblMajorRadius = funcRnd(3,2)

dblMinorRadius = dblMajorRadius/3

arrBase = funcGeom(nGen,arrPt)

If IsArray(arrBase) Then

arrDirection = Array(Rnd*5000, Rnd*5000, Rnd*5000)

If IsArray(arrDirection) Then

Call Rhino.AddTorus (arrBase, dblMajorRadius, dblMinorRadius, arrDirection)

Rhino.addpoint arrBase

End If

End If
   
Next
     
End If
 

End Function

Function funcGeom(nGen,arrPt)
 
 ‘===================================================
 ‘  Controlling the Distances between Torus
 ‘===================================================
 
 Dim j, strLine, dblAngle, arrEndPt, d1, d2 
  
 d1 = funcRnd (20,5)
 d2 = funcRnd (30,25)
  
 dblAngle = (360/nGen)
 

 For j = 0 To nGen

  If j <> nGen Then      
   
   strLine = Rhino.AddLine(arrPt, Array(arrPt(0),arrPt(1)+d1,arrPt(2)+d2))
      
   Call Rhino.RotateObject(strLine,arrPt,funcRnd(360,dblAngle))
   
   arrEndPt = Rhino.CurveEndPoint(strLine)
   
   funcGeom = arrEndPt 
  
   Rhino.DeleteObject (strLine)
   
     
  End If
  
 Next
 
End Function

Function funcRnd(intMax,intMin)
 
 Randomize
 
 funcRnd = (intMax – intMin+1)*(Rnd+1)
 
End Function

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