181008_squeezedLofts

squeez

 

 

 

 

 

 

 

 

 

 

 

Option Explicit

Call Worm()

Sub Worm()
 
 
 Dim aObjects : aObjects = Rhino.GetObjects(“Select Curves”, 4, True, False)
 ‘Dim intSamples : intSamples = Rhino.GetInteger(“Number of Cross Sections”, 50, 5)
 
 Dim i
 Dim arrCrossSections()
 
 For i = 0 To UBound(aObjects)
  
  Dim crvObject : crvObject = aObjects(i)
  
  ‘ define number of sections based on crv length
  Dim dblSegments : dblSegments = Rhino.DivideCurveLength ( aObjects(i), 1)
  Dim intSamples : intSamples = UBound(dblSegments)
  
 
  Dim crvDomain : crvDomain = Rhino.CurveDomain(crvObject)
  Dim t, n, l

  l = RN(51, 56)
 
  Dim 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(1,5)
   Dim dblPerpRadius : dblPerpRadius = random(1,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
  
  
   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)
 
 Next

End Sub

 

Function random(intLow,intUp)
 
 Randomize
 
 random = (intUp-intLow) * Rnd() + intLow
 
End Function

Function RN(nMin, nMax)
 RN = Null
 If Not IsNumeric(nMin) Then Exit Function
 If Not IsNumeric(nMax) Then Exit Function
 If nMin >= nMax Then Exit Function
 Randomize
 RN = Int((nMax – nMin + 1) * Rnd + nMin)
End Function

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google 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 )

Connecting to %s