(n)certainties – Die Angewandte – Fall 2008

17X_Repulsion

 

rep

 

 

 

 

 

 

 

 

 

 

 

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
  Do 
   a=1
   b=1
  
   For j=0 To ubound(arrRep)
    If  rhino.IsPointInSurface(strB,aPts(i-1))= True And rhino.IsPointInSurface(arrRep(j),aPts(i-1))= True Then
     a=RN(0.5,0.2)
     b=1 
    End If 
   Next
   ” temp/generic 
   aPtTemp = array(aPts(i-1)(0)+ (RN(nMin/a, nMax/a)),_                     
    aPts(i-1)(1)+RN(nMin/b, nMax/b),_                                                  
    aPts(0)(2))
   ” 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),_
      z+0.5)
    End If
   
   End If
   ” collect
   ReDim Preserve aPts(i)
   
   aPts(i) = aPtTemp
  
   If  rhino.IsPointInSurface(strB,aPts(i))= True Then Exit Do
   
    
  Loop 
  
  ” vizu
  ’Dim scircle : sCircle = rhino.AddCircle(rhino.MovePlane(Rhino.WorldXYPlane,aPts(i)),dblSearchRad)
  ’Call rhino.AddPlanarSrf(array(scircle))
 
 Next
 
 Dim strTrack
 Call rhino.addpolyline(aPts)
 
 strTrack = rhino.addinterpcurve(aPts)

 
End Sub

Function RN(nMin, nMax)
 Randomize
 RN = (nMax – nMin) * Rnd + nMin
End Function
Function eitherOr(n1, n2)
 Randomize
 If rnd > 0.5 Then
  eitherOr = n1
 Else
  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
 Next
 If n = 0 Then
  searchWithinRad = Null
 Else
  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)
 Next
 heighestZ = z
End Function

Leave a Comment

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

You must be logged in to post a comment.