Option Explicit
‘Script written by <insert name>
‘Script copyrighted by <insert company name>
‘Script version 7 listopada 2008 12:38:46

Call Main()
Sub Main()
 Dim i,aPtTemp, aPtsNeighbors:
 Dim aPts(),arrPtsG
 Dim strB
 Dim arrRep,j
 Dim nMin : nMin = -5
 Dim nMax: nMax =5
 Dim dblSearchRad: dblSearchRad =5
 Dim a,b

 ReDim Preserve aPts(0)
 aPts(0) = rhino.GetPoint(“pick one pt”)
 strB = rhino.getobject(“border”,8+16+32)

 arrRep = rhino.getobjects(“repulsors”,8+16+32)

 For i = 1 To 50
   For j=0 To ubound(arrRep)
    If  rhino.IsPointInSurface(strB,aPts(i-1))= True And rhino.IsPointInSurface(arrRep(j),aPts(i-1))= True Then
    End If 
   ” temp/generic 
   aPtTemp = array(aPts(i-1)(0)+ (RN(nMin/a, nMax/a)),_                     
    aPts(i-1)(1)+RN(nMin/b, nMax/b),_                                                  
   ” if atr, rep, neutral
   ” check its status
   If i > 1 Then
    aPtsNeighbors = searchWithinRad(aPtTemp, aPts, dblSearchRad)
    If Not isnull (aPtsNeighbors) Then
     Dim z : z = heighestZ(aPtsNeighbors)
     aPtTemp = array(aPts(i-1)(0)+ eitherOr(nMin/a,nMax/a),_
      aPts(i-1)(1)+eitherOr(nMin/b, nMax/b),_
    End If
   End If
   ” collect
   ReDim Preserve aPts(i)
   aPts(i) = aPtTemp
   If  rhino.IsPointInSurface(strB,aPts(i))= True Then Exit Do
  ” vizu
  ‘Dim scircle : sCircle = rhino.AddCircle(rhino.MovePlane(Rhino.WorldXYPlane,aPts(i)),dblSearchRad)
  ‘Call rhino.AddPlanarSrf(array(scircle))
 Dim strTrack
 Call rhino.addpolyline(aPts)
 strTrack = rhino.addinterpcurve(aPts)

End Sub

Function RN(nMin, nMax)
 RN = (nMax – nMin) * Rnd + nMin
End Function
Function eitherOr(n1, n2)
 If rnd > 0.5 Then
  eitherOr = n1
  eitherOr = n2
 End If
End Function

Function searchWithinRad(aPtSeed, aPts, dblRad)
 Dim i, dblDist, n
 Dim aPtscollect()
 For i = 0 To UBound(aPts)
  ‘dblDist = rhino.Distance(aPtSeed, aPts(i))
  dblDist = rhino.Distance(aPtSeed, array(aPts(i)(0),aPts(i)(1),aPtSeed(2)))
  If dblDist < dblRad Then
   ReDim Preserve aPtscollect(n)
   aPtscollect(n) = aPts(i)
   Call rhino.addPoint(aPtscollect(n))
   n = n + 1
  End If
 If n = 0 Then
  searchWithinRad = Null
  searchWithinRad = aPtscollect
 End If
End Function

Function heighestZ(aPts)
 Dim i
 Dim z : z = 0
 For i = 0 To Ubound(aPts)
  If aPts(i)(2) > z Then z = aPts(i)(2)
 heighestZ = z
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