(n)certainties – Columbia – Fall 2008

EM_Lofted Worm

This script is dividing a curve and drawing ellipses in each division to finally loft them:

Option Explicit
‘If it is working then scripted by Eduardo Mayoral
‘If Not scripted by anyone else

Call Worm()

Sub Worm()
 
 ’============================================
 ’  Selecting and Evaluating Path Curve
 ’============================================
 
 Dim crvObject : crvObject = Rhino.GetObject(“Select a Curve”, 4, True, False)
 Dim intSamples : intSamples = Rhino.GetInteger(“Number of Cross Sections”, 50, 5)
 
 Dim crvDomain : crvDomain = Rhino.CurveDomain(crvObject)
 Dim t, n

 Dim arrCrossSections(), CrossSectionPlane
 Dim crvCurvature, crvPoint, crvTangent, crvPerp, crvNormal
 
 n = -1

 For t = crvDomain(0) To crvDomain(1) + 1e-9 Step (crvDomain(1)-crvDomain(0))/intSamples

  Dim dblBendRadius : dblBendRadius = random(3,3.5)
  Dim dblPerpRadius : dblPerpRadius = random(3,3.5)

  n = n+1
  
  crvCurvature = Rhino.CurveCurvature(crvObject, t)

  If IsNull(crvCurvature) Then
   
   crvPoint = Rhino.EvaluateCurve(crvObject, t)
   crvTangent = Rhino.CurveTangent(crvObject, t)
   crvPerp = Array(0,0,1)
   crvNormal = Rhino.VectorCrossProduct(crvTangent, crvPerp)

  Else
   
   crvPoint = crvCurvature(0)
   crvTangent = crvCurvature(1)
   crvPerp = Rhino.VectorUnitize(crvCurvature(4))
   crvNormal = Rhino.VectorCrossProduct(crvTangent, crvPerp)

  End If
   
  ’============================================
  ’  Drawing Sections and Lofting
  ’============================================

  CrossSectionPlane = Rhino.PlaneFromFrame(crvPoint, crvPerp, crvNormal)
  ReDim Preserve arrCrossSections(n)
  arrCrossSections(n) = Rhino.AddEllipse(CrossSectionPlane, dblBendRadius, dblPerpRadius)

 Next
 
 If n < 1 Then Exit Sub
 
 Call Rhino.AddLoftSrf(arrCrossSections)
 Call Rhino.DeleteObjects(arrCrossSections)

End Sub

 ’============================================
 ’  Random Function for the Ellipse Radius
 ’============================================

Function random(intLow,intUp)
 
 Randomize
 
 random = (intUp-intLow) * Rnd() + intLow
 
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