EM_Spheres along a Curve

This script is generating spheres with certain radius variation along a curve:

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

Call Spheres()

Sub Spheres()
 ‘  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 dblRadius : dblRadius = 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)

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

  End If
  ‘  Drawing Spheres

  CrossSectionPlane = Rhino.PlaneFromFrame(crvPoint, crvPerp, crvNormal)
  ReDim Preserve arrCrossSections(n)
  arrCrossSections(n) = Rhino.AddSphere(CrossSectionPlane, dblRadius)

 If n < 1 Then Exit Sub
End Sub

 ‘  Random Function for the Sphere Radius

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

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