Pages of codes / BACK

------------------------------------------------------------------------

DK&AW_Protocol_Labyrinth

Option Explicit

‘Script written by <Dave Kwon>
‘Script copyrighted by <Dave KWon>
‘Script version Sunday, October 18, 2009 9:00:53 PM

Call Main()
Sub Main()

Dim i,j,k, acs, aCenters, atan, aplan, sC, aps, aSeeds, aIndex

acs = rhino.GetObjects(“pick paths”, 4)
aSeeds = rhino.GetPointCoordinates(“pick pts”)

Dim drad : drad = 10

Call rhino.EnableRedraw(False)
For i = 0 To UBound(acs)-1
aCenters = rhino.DivideCurve(acs(i), 100)

For j = 0 To UBound(aCenters)
atan = rhino.CurveTangent(acs(i),rhino.CurveClosestPoint(acs(i), aCenters(j)))
aplan = rhino.PlaneFromNormal(aCenters(j), atan)
sc = rhino.AddCircle(aplan, drad)
aps = rhino.DivideCurve(sC, 20)
For k = 0 To Ubound(aps)
aIndex = SortBasedDist (aps(k),aSeeds)
Dim n, dd, pt, m
m = 0
ReDim aptsCrv(1)
For n = i+1 To UBound(aSeeds)-1
pt = rhino.EvaluateCurve(acs(i),rhino.CurveClosestPoint(acs(i),aSeeds(aIndex(n))))
dd = rhino.Distance(aSeeds(aIndex(n)), aps(k))
If dd > drad Then
aptsCrv(m) = aSeeds(aIndex(n))
If m = 1 Then Exit For
m = m + 1
End If
Next
‘-Call rhino.addCurve(array(aptsCrv(0), aps(k), aptsCrv(1)))
Call rhino.addCurve(array(aSeeds(aIndex(0)), aps(k), aSeeds(aIndex(1))))
Next
rhino.DeleteObject sc
Next
Next

Call rhino.EnableRedraw(True)
End Sub

Function SortBasedDist (pt,arpts)

Dim i
Dim dists()
ReDim dists (Ubound (arpts))
Dim sortedDist,j
Dim SortedIndex()
ReDim SortedIndex (Ubound (arpts))

For i=0 To ubound (arpts)
dists(i) = rhino.Distance (pt,arpts(i))
Next

sortedDist = rhino.SortNumbers (dists)

For i=0 To ubound(sortedDist)
For j=0 To ubound (dists)
If dists(j) = sortedDist(i) Then
SortedIndex(i) = j
End If
Next
Next
SortBasedDist = SortedIndex

End Function

KK&ET_Protocol_Salt

Boxes

Option Explicit
‘Script written by <Eric Tse>
‘Script copyrighted by <Eric Tse>
‘Script version Monday, October 19, 2009 9:11:38 PM

Dim numSegments : numSegments = 20
Dim segmentL : segmentL = 1.25
Dim numPts : numPts = 6
Dim fractScale : fractScale = 0.75
Dim fractNum : fractNum = 1
Dim boxScale : boxScale = 0.25
Dim fractalLim : fractalLim = 0.002

Call Main()
Sub Main()
 
 Dim strBox
 Dim arrCrv : arrCrv = rhino.GetObjects (“selcrv”,4)
 Dim arrCentroidNew
 Dim crv, divpts
 Dim i,j,k,l,m
 Dim pt, clpt,clparam
 ReDim arrpt(pt)
 Dim ptparam,plane
 Dim xvect,yvect,vect,zvect
 Dim Tvect, Tv, Zv, tangVect
 Dim Nvect : Nvect = array (0,1,0)
 Dim angle
 Dim newBox, xBox, arrBox
 Dim scale
 Dim vScale
 Dim fractal_output, vol
 
 rhino.EnableRedraw False
 
 For l = 0 To ubound (arrCrv)
  crv = arrCrv(l)
  divpts = rhino.DivideCurveLength (crv,segmentL*boxScale)
  For i = 0 To ubound(divpts)
   ptparam = rhino.CurveClosestPoint (crv,divpts(i))
   plane = rhino.CurvePerpFrame (crv,ptparam)
   For j = 0 To numPts
   
    xvect = rhino.Vectorrotate (plane(1),fx_Random (0, 360),plane(3))
    yvect = rhino.Vectorrotate (plane(1),fx_Random (0, 360),plane(3))
    zvect = rhino.VectorScale (plane(3),fx_Random (-0.15, 0.15))
    vect = rhino.VectorAdd (xvect,yvect)
    vect = rhino.VectorAdd (vect,zvect)
    vect = rhino.VectorScale(vect,boxScale)
    vect = rhino.vectorscale (vect,fx_Random (0.5,0.75))
   
    pt = rhino.PointAdd (divpts(i),vect)
    newBox = Rhino.InsertBlock (“box2″, pt)
    newBox = rhino.ScaleObject(newBox,pt,array(boxScale,boxScale,boxScale))
    ’find closest point on curve’
    clparam = Rhino.CurveClosestPoint (crv, pt)
    clpt = rhino.EvaluateCurve (crv,clparam)
    ’create vector’
    Tvect = Rhino.VectorCreate (pt, clpt)
    
    angle = 45
    tangVect = rhino.CurveTangent(crv,clparam)
    tangVect = rhino.VectorUnitize(tangVect)
    tangVect = rhino.VectorScale(tangVect,1)
    Tv = rhino.VectorUnitize (Tvect)
    Tv = Rhino.VectorAdd (Tv,tangVect)
    Tv = rhino.VectorUnitize (Tv)
    Tv = rhino.VectorScale(Tv,boxScale)
    
    scale = 1 * (numPts-(j/2))/numPts
    newBox = rhino.ScaleObject(newBox,pt,array(scale,scale,scale))
    
    ’    For m = 0 To fractNum
    ’     fractal_output = fractal (newBox,Tv,pt)
    ’     newBox = fractal_output(0)
    ’     Tv = fractal_output(1)
    ’     pt = fractal_output(2)
    ’     vol = fractal_output(3)
    ’    Next
    
    arrBox = rhino.ExplodeBlockInstance(newBox)
    xBox = arrBox(0)
    
    vol = 1000
    Do
     fractal_output = fractal (xBox,Tv,pt)
     xBox = fractal_output(0)
     Tv = fractal_output(1)
     pt = fractal_output(2)
     vol = fractal_output(3)
    Loop While vol > fractalLim
   
   Next
  
  Next
 Next 

 rhino.EnableRedraw True
 
End Sub

Function fractal (xBox,Tv,cntr)

 Dim i
 Dim box, boxLength, newPt, arrVol, vol
 
 boxLength = 1
 
 box = rhino.CopyObject(xBox)
 box = rhino.MoveObject(box,Tv)
 newPt = rhino.PointAdd(cntr,Tv)
 box = rhino.ScaleObject (box,newPt,array(fractScale,fractScale,fractScale))
 
 Tv = rhino.VectorScale (Tv,fractScale)
 
 arrVol = rhino.MeshVolume(box)
 vol = arrVol(1)
 
 fractal = array(box,Tv,newPt,vol)
 
End Function

Function fx_Random (min, max)
 
 fx_Random = Rnd*(max-min) + min
 
End Function

Field

Option Explicit
‘Script written by <Eric Tse>
‘Script copyrighted by <Eric Tse>
‘Script version Friday, November 20, 2009 2:17:02 PM

Dim range1 : range1 = 16
Dim scale1 : scale1 = 50
Dim range2 : range2 = range1*2
Dim scale2 : scale2 = 75
Dim range3 : range3 = range1*3
Dim arcAngle : arcAngle = 90
Dim arcAngle2 : arcAngle2 = 180
Dim arcArrAngle : arcArrAngle = 5
Dim dblPavilion : dblPavilion = 1.5
Dim dblEnd : dblEnd = 2

Call Main()
Sub Main()
 
 Dim i, j
 Dim arrStartPt : arrStartPt = rhino.GetPointCoordinates(“pick start pt”)
 Dim arrEndPt : arrEndPt = rhino.GetPointCoordinates(“pick end pt”)    
 Dim arrPts : arrPts = rhino.GetPointCoordinates(“pick pts”)
 
 Dim arrPtsN
 
 rhino.EnableRedraw(False)
 
 For i = 0 To UBound(arrPts)
  arrPtsN = fx_findNeighborsWithinRange(i, arrPts, range1, arrStartPt(0), arrEndPt(0))
  If Not isnull(arrPtsN) Then
   ’Call rhino.addcircle(rhino.Moveplane(WorldXYPlane,arrPts(i)), range1)
  End If
 Next
 
 rhino.Command “seldup” & ” ” & “delete”

 rhino.LayerVisible “arcs array1″,False
 rhino.LayerVisible “arcs array2″,False 
 rhino.CurrentLayer(“Default”)
 
 rhino.EnableRedraw(True)
 
End Sub

Function fx_findNeighborsWithinRange(index, arrPts, range1, startPt, endPt)
 
 fx_findNeighborsWithinRange = Null
 
 Dim i, dblDist, n
 Dim endVect, newVect, length
 Dim arrPtsCollect()
 Dim currentPt, newPt, drawPt, vect1, vect2
 
 currentPt = arrPts(index)
 
 If rhino.distance(currentPt,endPt) > 0 Then
  Call fx_EndDirection(currentPt,endPt)
 End If
 
 endVect = rhino.VectorCreate(startPt,endPt)
 
 n = 0
 For i = 0 To Ubound(arrPts)
  If i <> index Then
   newPt = arrPts(i)
   dblDist = rhino.Distance(currentPt,newPt)
   newVect = rhino.VectorCreate(currentPt,newPt)
   length = rhino.VectorLength(newVect)
   newVect = rhino.VectorUnitize(newVect)
   newVect = rhino.VectorDivide(newVect,length)
   ’newVect = rhino.VectorScale(newVect,100)
   
   If dblDist <= range1 Then
    If fx_AngleDiff(endVect,newVect) < 90 Then
     rhino.currentlayer(“vects1″)
     newVect = rhino.VectorReverse(newVect)
     drawPt = rhino.PointAdd(currentPt,newVect)
     ’rhino.AddPoint drawPt
     vect1 = rhino.AddLine (currentPt,drawPt)
     rhino.ScaleObject vect1,currentPt,array(scale1,scale1,scale1)
     Call fx_Arc1(currentPt,newPt,endVect)
     Call fx_Pavilion(currentPt,newPt)
    End If
   End If
   
   If dblDist <= range2 Then
    ReDim Preserve arrPtsCollect(n)
    arrPtsCollect(n) = newPt
    n = n + 1
    
    If fx_AngleDiff(endVect,newVect) < 90 Then
     If dblDist > range1 Then
      rhino.currentlayer(“vects2″)
      newVect = rhino.VectorReverse(newVect)
      drawPt = rhino.PointAdd(currentPt,newVect)
      ’rhino.AddPoint drawPt
      vect2 = rhino.AddLine (currentPt,drawPt)
      rhino.ScaleObject vect2,currentPt,array(scale2,scale2,scale2)
     End If
     Call fx_Arc2(currentPt,newPt,endVect)
    End If
   End If
   
  End If
 Next
 
 For i = 0 To Ubound(arrPtsCollect)
  rhino.CurrentLayer(“connections”)
  rhino.AddLine currentPt,arrPtsCollect(i)
 Next
 
 If n > 0 Then
  fx_findNeighborsWithinRange = arrPtsCollect
 End If

End Function

Function fx_EndDirection(currentPt,endPt)
 
 Dim vect, drawPt
 
 rhino.CurrentLayer(“end direction”)
 
 vect = rhino.VectorCreate(currentPt,endPt)
 vect = rhino.VectorUnitize(vect)
 vect = rhino.VectorScale(vect,dblEnd)
 vect = rhino.VectorReverse(vect)
 
 drawPt = rhino.PointAdd(currentPt,vect)
 
 rhino.AddLine currentPt,drawPt
 
End Function

Function fx_Pavilion(currentPt,newPt)
 
 Dim vect, vectL, vectR, drawPt, lineR, lineL
 
 rhino.CurrentLayer(“perp lines”)
 
 vect = rhino.VectorCreate(currentPt,newPt)
 
 vectR = rhino.VectorRotate(vect,90,array(0,0,1))
 vectR = rhino.VectorUnitize(vectR)
 vectR = rhino.VectorScale(vectR,dblPavilion)
 drawPt = rhino.PointAdd(newPt,vectR)
 lineR = rhino.AddLine (newPt,drawPt)
 
 vectL = rhino.VectorRotate(vect,-90,array(0,0,1))
 vectL = rhino.VectorUnitize(vectL)
 vectL = rhino.VectorScale(vectL,dblPavilion)
 drawPt = rhino.PointAdd(newPt,vectL)
 lineL = rhino.AddLine (newPt,drawPt)
 
 rhino.JoinCurves array(lineR,lineL),True
 
End Function

Function fx_Arc1(p1, p2, endVect)
 
 Dim i
 Dim vectMid, vectDraw, vectL, vectR, ptMid, ptL, ptR, ptDraw

 vectMid = rhino.VectorCreate(p1,p2)
 vectMid = rhino.VectorReverse(vectMid)
 vectMid = rhino.VectorUnitize(vectMid)
 vectMid = rhino.VectorScale(vectMid,range1)
  
 rhino.CurrentLayer(“arcs array1″)
 For i = 0 To (arcAngle/2)/arcArrAngle – 1
  vectDraw = rhino.VectorRotate(vectMid,arcArrAngle*i,array(0,0,1))
  ptDraw = rhino.PointAdd(p1,vectDraw)
  rhino.AddLine p1,ptDraw
  vectDraw = rhino.VectorRotate(vectMid,-arcArrAngle*i,array(0,0,1))
  ptDraw = rhino.PointAdd(p1,vectDraw)
  rhino.AddLine p1,ptDraw  
 Next
 
 ptMid = rhino.PointAdd(p1,vectMid)
 vectL = rhino.VectorRotate(vectMid,arcAngle/2,array(0,0,1))
 ptL = rhino.PointAdd(p1,vectL)
 vectR = rhino.VectorRotate(vectMid,-arcAngle/2,array(0,0,1))
 ptR = rhino.PointAdd(p1,vectR) 
 
 rhino.CurrentLayer(“arcs1″)
 rhino.AddLine p1,ptL
 rhino.AddLine p1,ptR
 rhino.AddArc3Pt ptL,ptR,ptMid

End Function

Function fx_Arc2(p1, p2, endVect)
 
 Dim i
 Dim vectPt, vectMid, vectDraw, vectL, vectR, ptMid, ptL, ptR, ptDraw

‘ vectPt = rhino.PointAdd(p1,array(0,1,0))
‘ vectMid = rhino.VectorCreate(p1,p2)
 vectMid = endVect
 vectMid = rhino.VectorReverse(vectMid)
 vectMid = rhino.VectorUnitize(vectMid)
 vectMid = rhino.VectorScale(vectMid,range2)
  
 rhino.CurrentLayer(“arcs array2″)
 For i = 0 To (arcAngle2/2)/arcArrAngle – 1
  vectDraw = rhino.VectorRotate(vectMid,arcArrAngle*i,array(0,0,1))
  ptDraw = rhino.PointAdd(p1,vectDraw)
  rhino.AddLine p1,ptDraw
  vectDraw = rhino.VectorRotate(vectMid,-arcArrAngle*i,array(0,0,1))
  ptDraw = rhino.PointAdd(p1,vectDraw)
  rhino.AddLine p1,ptDraw  
 Next
 
 ptMid = rhino.PointAdd(p1,vectMid)
 vectL = rhino.VectorRotate(vectMid,arcAngle2/2,array(0,0,1))
 ptL = rhino.PointAdd(p1,vectL)
 vectR = rhino.VectorRotate(vectMid,-arcAngle2/2,array(0,0,1))
 ptR = rhino.PointAdd(p1,vectR) 
 
 rhino.CurrentLayer(“arcs2″)
 rhino.AddLine p1,ptL
 rhino.AddLine p1,ptR
 rhino.AddArc3Pt ptL,ptR,ptMid

End Function

Function fx_AngleDiff(v0, v1)   
 
 Dim u0  : u0  = Rhino.VectorUnitize(v0)   
 Dim u1  : u1  = Rhino.VectorUnitize(v1)     
 Dim dot : dot = Rhino.VectorDotProduct(u0, u1)
 
 ’ domain for inverse cosine is -1 <= x <= 1
 If (dot < -1.0) Then     
  dot = -1.0   
 ElseIf (dot > 1.0) Then    
  dot = 1.0   
 End If   
 
 fx_AngleDiff = Rhino.ToDegrees(Rhino.ACos(dot)) 

End Function

Trajectories

Option Explicit
‘Script written by <Eric Tse>
‘Script copyrighted by <Eric Tse>
‘Script version Sunday, October 18, 2009 9:00:53 PM

Dim ZvectLim : ZvectLim = 45
Dim ZvectSize : ZvectSize = 1
Dim ZvectRotate : ZvectRotate = 0
Dim dbVectScale : dbVectScale = 0.5
Dim dbScale : dbScale = 0.5
Dim dbRadiusFactor : dbRadiusFactor = 0.25
Dim dbShortenV : dbShortenV = 1
Dim textSize : textSize = 0.15
Dim dotSize : dotSize = 0.05
Dim crossScale : crossScale = 2

Call Main()
Sub Main()
 
 Dim i, j, k
 Dim arrSrf : arrSrf = rhino.GetObjects(“Select surfaces”,8)
 Dim strBox : strBox = rhino.GetObject(“Select box”,16)
 Dim gridPts1 : gridPts1 = 3
 Dim gridPts2 : gridPts2 = 2      
 Dim numSegments : numSegments = 4
 Dim angleLim : angleLim = 15
 Dim numPts1 : numPts1 = 30
 Dim numPts2 : numPts2 = 30
 Dim dbRadius : dbRadius = 0.35
 
 rhino.HideObject strBox
 
 Dim startPt, newVect, Zvect, ZvectPt, ZvectLine
 Dim fx_SrfPts_output, arrStartPts, arrNvects, arrSrfs
 Dim fx_Segment_output
 Dim arrArrPts()
 ReDim arrArrPts(0)
 Dim arrArrVects()
 ReDim arrArrVects(0)
 Dim arrSegments()
 ReDim arrSegments(0)
 Dim arrRadius()
 ReDim arrRadius(0)
 Dim fx_IPOC_output
 Dim startRadius
 Dim blnZvect, ZvectPt1, ZvectPt2, plane, newText
 
 blnZvect = rhino.GetInteger(“Zvect down (0) or choose Zvect (1)”,0,0,1)
 If blnZvect = 0 Then
  Zvect = array(0,0,-ZvectSize)
 Else
  ZvectPt1 = rhino.GetPoint(“Select start point for Zvect”)
  ZvectPt2 = rhino.GetPoint(“Select end point for Zvect”)
  Zvect = rhino.VectorCreate(ZvectPt1,ZvectPt2)
  Zvect = rhino.VectorUnitize(Zvect)
  Zvect = rhino.VectorReverse(Zvect)
  Zvect = rhino.VectorScale(Zvect,ZvectSize)
 End If
 
 rhino.EnableRedraw False
 
 ’for each selected surface,
 ’divide surface into grid of points
 fx_SrfPts_output = fx_SrfPts(arrSrf, gridPts1, gridPts2)
 arrStartPts = fx_SrfPts_output(0) ‘array of grid points for each srf
 arrNvects = fx_SrfPts_output(1) ‘nvect for each srf 
 
 For i = 0 To 0′Ubound(arrSrf) ‘for each surface
  For j = 0 To 0′Ubound(arrStartPts(i)) ‘for each start point
   
   ReDim arrArrPts(0)
   ReDim arrArrVects(0)
   ReDim arrSegments(0)
   
   startPt = arrStartPts(i)(j)
   newVect = arrNvects(i)
   ’Zvect = array(0,0,-ZvectSize)
   startRadius = dbRadius
   
   For k = 0 To numSegments ‘draw number of segments
    
    rhino.CurrentLayer(“text gen”)
    plane = rhino.MovePlane(WorldXYPlane,startPt)
    newText = rhino.AddText(“   t=” & j+1 & “_” & k+1,plane,textSize)
    
    Call fx_TextCoords(startPt)
    
    fx_Segment_output = fx_Segment(startPt,newVect,Zvect,startRadius,angleLim,numPts1,numPts2,strBox,arrSrf,arrNvects)
    arrArrPts(k) = fx_Segment_Output(0)
    arrArrVects(k) = fx_Segment_Output(1)
    arrSegments(k) = fx_Segment_Output(2)
    arrRadius(k) = fx_Segment_Output(3)

    fx_IPOC_output = fx_IPOC (arrArrPts,arrArrVects,arrSegments,Zvect, arrRadius)
    startPt = fx_IPOC_output(0)
    newVect = fx_IPOC_output(1)
    startRadius = fx_IPOC_output(2)
    
    If k < numSegments Then
     ReDim Preserve arrArrPts(Ubound(arrArrPts)+1)
     ReDim Preserve arrArrVects(Ubound(arrArrVects)+1)
     ReDim Preserve arrSegments(Ubound(arrSegments)+1)
     ReDim Preserve arrRadius(Ubound(arrRadius)+1)
    End If
    
    rhino.Command “selall ” & “group”
    
   Next  
  Next
 Next
 
 rhino.EnableRedraw True
 
 rhino.CurrentLayer(“Default”)

End Sub

Function fx_Segment (startPt, newVect, Zvect, startRadius, angleLim, numPts1, numPts2, strBox, arrSrf, arrNvects)
 
 Dim i, j
 Dim numPts : numPts = Int(fx_Random(numPts1,numPts2))
 Dim arrPts()
 ReDim arrPts(numPts)
 Dim arrVects()
 ReDim arrVects(numPts)
 Dim angleDiff, EndPt, strCurve, scaleVect
 Dim tempSrf, closestSrf, tempNvect, Nvect, minDist, tempDist, srfCentroid, srfOrigin, tempArr
 Dim strPt, arrPtCoord, lowerLim, upperLim
 Dim arrRadius()
 ReDim arrRadius(numPts)
 Dim arrCircles()
 ReDim arrCircles(numPts)
 Dim plane1, plane2, planeZvect, planePt, planeAngleX, planeAngleY, plane, length, newText
 
 newVect = rhino.VectorScale(newVect,dbShortenV)
 
 arrPts(0) = startPt
 arrVects(0) = newVect
 plane1 = rhino.PlaneFromNormal(startPt,newVect)
 arrRadius(0) = startRadius
 rhino.CurrentLayer(“circles”)
 arrCircles(0) = Rhino.AddCircle(plane1,startRadius)
 rhino.CurrentLayer(“branch pts”)
 rhino.AddCircle rhino.Moveplane(WorldXYPlane,startPt),dotSize*1.5
 rhino.CurrentLayer(“branch cross”)
 rhino.InsertBlock “cross”,startPt,array(crossScale*1.5,crossScale*1.5,crossScale*1.5)
 For i = 1 To numPts
  
  scaleVect = rhino.VectorScale(newVect,fx_Random(1-dbVectScale,1+dbVectScale))
  
  EndPt = Rhino.PointAdd(startPt,scaleVect)
  
  If Rhino.IsPointInSurface(strBox,EndPt) Then
   arrPts(i) = EndPt
  Else
   minDist = 100000
   For j = 0 To Ubound(arrSrf)
    tempSrf = arrSrf(j)
    tempNvect = arrNvects(j)
    srfCentroid = Rhino.SurfaceAreaCentroid(tempSrf)
    srfOrigin = srfCentroid(0)
    tempDist = rhino.Distance(EndPt,srfOrigin)
    If tempDist < minDist Then
     minDist = tempDist
     closestSrf = tempSrf
     Nvect = tempNvect
    End If
   Next
   tempArr = Rhino.ProjectPointToSurface(EndPt, closestSrf, Nvect)
   If Not IsNull(tempArr) Then
    EndPt = tempArr(0)
   Else
    EndPt = arrPts(i – 1)
   End If
   arrPts(i) = EndPt
  End If
  
  arrVects(i) = scaleVect
  
  startPt = EndPt
  
  lowerLim = -angleLim
  upperLim = angleLim
  newVect = fx_RotateVect(newVect,lowerLim,upperLim,startPt,Zvect)
  
  plane2 = rhino.PlaneFromNormal(startPt,newVect)
  planeZvect = plane2(3)
  planeAngleX = fx_AngleDiff(plane2(1),plane1(1))
  If planeAngleX > 90 Then
   plane2 = rhino.RotatePlane(plane2,planeAngleX,planeZvect)
  End If

  startRadius = startRadius * ((numPts-i/4+1)/numPts) ‘((numPts-(i/dbRadiusFactor)+1)/(numPts))
  startRadius = startRadius * (1 + fx_Random(-dbRadiusFactor,dbRadiusFactor))
  arrRadius(i) = startRadius
  rhino.CurrentLayer(“circles”)
  arrCircles(i) = Rhino.AddCircle(plane2,arrRadius(i))
  rhino.CurrentLayer(“points”)
  rhino.AddCircle rhino.Moveplane(WorldXYPlane,startPt),dotSize
  rhino.CurrentLayer(“branch cross”)
  rhino.InsertBlock “cross”,startPt,array(crossScale,crossScale,crossScale)
  
  plane1 = plane2
  
 Next
 
 rhino.CurrentLayer(“lofts”)
 Rhino.AddLoftSrf arrCircles
 
 rhino.CurrentLayer(“segments”)
 strCurve = rhino.AddInterpCurve(arrPts)
 
 rhino.CurrentLayer(“text length”)
 length = rhino.CurveLength(strCurve)
 plane = rhino.MovePlane(WorldXYPlane,startPt)
 rhino.AddText “   l=” & Int(length),plane,textSize
 
 Call fx_TextCoords(startpt)
 
 fx_Segment = array (arrPts, arrVects, strCurve, arrRadius)
 
End Function

Function fx_IPOC (arrArrPts, arrArrVects, arrSegments, Zvect, arrRadius)
 
 Dim i, j, k
 Dim strLine, arrPt, ptVect
 Dim smallestAngle, angleDiff
 Dim arrFork()
 ReDim arrFork(0)
 Dim startPt, newVect, tempPt, tempVect, startRadius
 
 For i = 0 To Ubound(arrArrPts) ‘for each array of pts per segment
  For j = 1 To Ubound(arrArrPts(i)) ‘FOR EACH PT IN ARRAY
   
   arrPt = arrArrPts(i)(j)
   ptVect = arrArrVects(i)(j)
   startPt = arrPt
   newVect = ptVect
   startRadius = arrRadius(i)(j)
   ’rhino.addpoint arrPt
   
   ’check if pt on multiple curves
   For k = 0 To Ubound(arrSegments) ‘for each segment
    If k <> i Then ‘if segment different from set of pts
     strLine = arrSegments(k)
     smallestAngle = fx_AngleDiff(ptVect,Zvect)
     If Rhino.IsPointOnCurve(strLine, arrPt) Then ‘if pt on segment
      tempPt = arrArrPts(k)(j)
      tempVect = arrArrVects(k)(j)
      angleDiff = fx_AngleDiff(tempVect,Zvect)
      If angleDiff < smallestAngle Then ‘find smallest angle
       smallestAngle = angleDiff
       startPt = tempPt
       newVect = tempVect
       j = Ubound(arrArrPts(i))
      End If
     End If
    End If
   Next
   
   ’check if angleDiff > ZvectLim
   angleDiff = fx_AngleDiff(newVect,Zvect)
   If angleDiff > ZvectLim/2 Then
    ’Rhino.AddPoint startPt
    newVect = rhino.VectorAdd(newVect, Zvect)
    newVect = rhino.VectorDivide(newVect, 2)
    i = Ubound(arrArrPts)
    j = Ubound(arrArrPts(i))
   End If
    
  Next
 Next
 
 fx_IPOC = array(startPt, newVect, startRadius)
 
End Function

Function fx_SrfPts (arrSrf, gridPts1, gridPts2)
 
 Dim i
 Dim num : num = Ubound(arrSrf)
 Dim Udom, Vdom
 Dim srfCentroid, srfOrigin, scaleSrf
 Dim arrPts()
 ReDim arrPts(num)
 Dim Nvect()
 ReDim Nvect(num)
 
 For i = 0 To Ubound(arrSrf)
  Udom = rhino.SurfaceDomain (arrSrf(i),0)
  Vdom = rhino.SurfaceDomain (arrSrf(i),1)
  
  srfCentroid = Rhino.SurfaceAreaCentroid(arrSrf(i))
  srfOrigin = srfCentroid(0)
  scaleSrf = Rhino.ScaleObject (arrSrf(i), srfOrigin, array(dbScale,dbScale,dbScale), True)
  Rhino.RebuildSurface scaleSrf, Array(gridPts1,gridPts2), Array(gridPts1,gridPts2)
  arrPts(i) = rhino.SurfacePoints (scaleSrf)
  Rhino.deleteobject scaleSrf
    
  Nvect(i) = Rhino.SurfaceNormal(arrSrf(i), array(Udom(0),Vdom(0)))
  Nvect(i) = rhino.VectorScale(Nvect(i),ZvectSize/2)
 Next
 
 fx_SrfPts = array (arrPts, Nvect)
 
End Function

Function fx_RotateVect (newVect, lowerLim, upperLim, newPt, Zvect)
 
 Dim skewAngle, lowerPt, upperPt, zPt, lowerVect, upperVect, drawPt, tempZvect, tempVect
 Dim lowerVectX, upperVectX, lowerVectY, upperVectY, lowerVectZ, upperVectZ, arcZ
 Dim angleDiff, endPt, midPt, strArc, arrAngleZ, angleZ, angleZPlane, vectLength, oldVect
 
 oldVect = newVect
 
 skewAngle = fx_Random(lowerLim,upperLim)
 newVect = Rhino.VectorRotate(newVect,skewAngle,array(0,1,0))
 skewAngle = fx_Random(lowerLim,upperLim)
 newVect = Rhino.VectorRotate(newVect,skewAngle,array(1,0,0))
 skewAngle = fx_Random(lowerLim,upperLim)
 newVect = Rhino.VectorRotate(newVect,skewAngle,array(0,0,1))
 
 rhino.CurrentLayer(“text angle”)
 
 angleDiff = fx_AngleDiff(oldVect,newVect)
 rhino.AddText “   Δtv=” & Int(angleDiff) & “°”,newPt,textSize
 
 lowerVectX = Rhino.VectorRotate(newVect,lowerLim,array(0,1,0))
 upperVectX = Rhino.VectorRotate(newVect,upperLim,array(0,1,0))
 lowerVectY = Rhino.VectorRotate(newVect,lowerLim,array(1,0,0))
 upperVectY = Rhino.VectorRotate(newVect,upperLim,array(1,0,0))
 lowerVectZ = Rhino.VectorRotate(newVect,lowerLim,array(0,0,1))
 upperVectZ = Rhino.VectorRotate(newVect,upperLim,array(0,0,1))
  
 rhino.CurrentLayer(“rvects”)
 
 lowerVect = rhino.VectorAdd(lowerVectX,lowerVectY)
 lowerVect = rhino.VectorDivide(lowerVect,2)
 lowerVect = rhino.VectorAdd(lowerVect,lowerVectZ)
 lowerVect = rhino.VectorDivide(lowerVect,2)
 lowerVect = rhino.VectorScale(lowerVect,2)
 lowerPt = rhino.PointAdd(newPt,lowerVect)
 rhino.AddLine newPt,lowerPt
 
 upperVect = rhino.VectorAdd(upperVectX,upperVectY)
 upperVect = rhino.VectorDivide(upperVect,2)
 upperVect = rhino.VectorAdd(upperVect,upperVectZ)
 upperVect = rhino.VectorDivide(upperVect,2)
 upperVect = rhino.VectorScale(upperVect,2)
 upperPt = rhino.PointAdd(newPt,upperVect)
 rhino.AddLine newPt,upperPt

 rhino.CurrentLayer(“zvects”)
 
 vectLength = rhino.VectorLength(newVect)
 tempZvect = rhino.VectorScale(Zvect,1)
 tempZvect = rhino.VectorUnitize(tempZvect)
 tempZvect = rhino.VectorScale(tempZvect,vectLength*2)
 zPt = rhino.PointAdd(newPt,tempZvect)
 rhino.AddLine newPt,zPt

 rhino.CurrentLayer(“arcs”)
 
 tempVect = rhino.VectorScale(newVect,2)
 endPt = rhino.PointAdd(newPt,tempVect)
 ’rhino.AddPoint midPt
 strArc = rhino.AddArc3Pt (lowerPt,upperPt,endPt)
 If rhino.ArcAngle(strArc) > 90 Then
  rhino.DeleteObject(strArc)
  strArc = rhino.AddArc3Pt (upperPt,lowerPt,endPt)
 End If
 
 rhino.CurrentLayer(“z arcs”)
 
 angleZPlane = rhino.PlaneFromPoints(newPt,endPt,zPt)
 vectLength = rhino.VectorLength(tempVect)
 arrAngleZ = rhino.Angle2 (array(newPt,endPt),array(newPt,zPt))
 arcZ = rhino.AddArc(angleZPlane,vectLength,arrAngleZ(0))
 
 rhino.CurrentLayer(“text”)

 angleZ = Int(arrAngleZ(0))
 midPt = rhino.ArcMidPoint(arcZ)
 rhino.AddText “-zv=” & angleZ & “°”,midPt,textSize
         
 rhino.CurrentLayer(“vects”)
  
 tempVect = rhino.VectorScale(newVect,2) 
 drawPt = rhino.PointAdd(newPt,tempVect)
 rhino.AddLine newPt,drawPt
 
 rhino.CurrentLayer(“tvects”)
 
 angleDiff = fx_AngleDiff(newVect,Zvect)
 If angleDiff > ZvectLim Then ‘ZvectLim is global limit on angle diff
  ’rhino.addpoint startPt
  newVect = rhino.VectorAdd(newVect, Zvect)
  newVect = rhino.VectorDivide(newVect, 2)
  tempVect = rhino.VectorScale(newVect,1.5) 
  drawPt = rhino.PointAdd(newPt,tempVect)
  rhino.AddLine newPt,drawPt
 End If

 fx_RotateVect = newVect
   
End Function

Function fx_TextCoords(pt)
 
 Dim plane, newText
 
 rhino.CurrentLayer(“text coords”)
 plane = rhino.MovePlane(WorldXYPlane,array(pt(0),pt(1)-textSize*1.5,pt(2)))
 newText = rhino.AddText(“   x=” & Int(pt(0)),plane,textSize)
 plane = rhino.MovePlane(WorldXYPlane,array(pt(0),pt(1)-textSize*1.5*2,pt(2)))
 newText = rhino.AddText(“   y=” & Int(pt(1)),plane,textSize)
 plane = rhino.MovePlane(WorldXYPlane,array(pt(0),pt(1)-textSize*1.5*3,pt(2)))
 newText = rhino.AddText(“   Z=” & Int(pt(2)),plane,textSize)
 
End Function

Function fx_RotateZvect (Zvect, angleLim)
 
 Dim skewAngle
 
 skewAngle = fx_Random(angleLim,angleLim)
 Zvect = Rhino.VectorRotate(Zvect,skewAngle,array(0,1,0))
 skewAngle = fx_Random(angleLim,angleLim)
 Zvect = Rhino.VectorRotate(Zvect,skewAngle,array(1,0,0))
 skewAngle = fx_Random(angleLim,angleLim)
 Zvect = Rhino.VectorRotate(Zvect,skewAngle,array(0,0,1))
 
 fx_RotateZvect = Zvect
 
End Function

Function fx_AngleDiff(v0, v1)   
 
 Dim u0  : u0  = Rhino.VectorUnitize(v0)   
 Dim u1  : u1  = Rhino.VectorUnitize(v1)     
 Dim dot : dot = Rhino.VectorDotProduct(u0, u1)
 
 ’ domain for inverse cosine is -1 <= x <= 1
 If (dot < -1.0) Then     
  dot = -1.0   
 ElseIf (dot > 1.0) Then    
  dot = 1.0   
 End If   
 
 fx_AngleDiff = Rhino.ToDegrees(Rhino.ACos(dot)) 

End Function

Function fx_Random (min, max)
 
 fx_Random = Rnd*(max-min) + min
 
End Function

MC&OG_Protocol_Carbon

Cracking

Option Explicit
‘Script written by <Marina Cisneros and Olivera Grk>

‘Script version Friday, 16 October 2009 14:11:31

Call Main()
Sub Main()
 
 Dim polygons
 Dim crack
 Dim i, j
 
 polygons = rhino.GetObjects (“get polygons”,4)
 crack = rhino.getobjects (“sel pts”,1)
 
 crack = rhino.PointCoordinates (crack)
 
 
 For i=0 To ubound(polygons)
  
  Dim vertex
  
  vertex = Rhino.CurvePoints (polygons(i))
  
 
  Dim vector()
  ReDim vector(ubound(crack))
  Dim length
  Dim scale
  Dim totvector
  
  For j=0 To ubound(vertex)
   
   For h=0 To ubound(crack)
 
    vector(h) = rhino.VectorCreate (vertex(j),crack(h))
    totvector = Rhino.VectorAdd (totvector, vector(h))
    length = Rhino.VectorLength (totvector)
    totvector = Rhino.VectorUnitize (totvector)
    scale= 100/length
    totvector= Rhino.VectorScale (totvector, scale)
   
   Next
   vertex(j) = rhino.pointadd (vertex(j), totvector)
   
   
  Next
  
  Rhino.Addpolyline vertex
  
 Next

End Sub

Expansion

Option Explicit
‘Script written by <Marina Cisneros and Olivera Grk>
‘Script copyrighted by <insert company name>
‘Script version Monday, October 19, 2009 1:51:37 PM

Call Main()
Sub Main()

 Dim arGrowPTs : arGrowPts = rhino.GetPointCoordinates (“Select Grow Points”)
 Dim arVolumes : arVolumes = rhino.getobjects (“SelVolumes”,16)
 Dim time
 time=0
 
 For i=0 To 5
  Dim arVolPts : arVolPts = f_GetPointArrayFromVolumes (arVolumes)
  Dim arVolCntrs : arVolCntrs = f_GetVolumeCentroids (arVolPts)
  Dim splitThresh : splitThresh = 10
  Dim i
  
 

  arVolPts = f_Grow (arVolPts,arGrowPTs,time)
  ’arVolPts = f_SubDivide (arVolPts)

  Call f_DrawResultVolumes (arVolumes,arVolPts)
  time=time+2
 
 Next
 
 
End Sub

 

 

 

Function f_Grow (arVolPts,arGrowPTs,time)

 Dim i,j,k,w
 Dim vect
 Dim movpts : movpts = arVolPts
 
 For i=0 To ubound (movpts)
  For j=0 To ubound(movpts(i))
   For k=0 To UBound (movpts(i)(j))
    vect = FindGrowVect (movpts(i)(j)(k),arGrowPTs,time)
    movpts(i)(j)(k) = rhino.PointAdd (movpts(i)(j)(k),vect)
   Next
  Next
 Next
 
 f_Grow = movpts
 
End Function

 

Function f_SubdividePolygons (polygons)
 Dim i,j,k
 Dim centroid
 Dim intVolume()
 ReDim intVolume(ubound(polygons))
 Dim arrSurf(), newvolumes(),newcapvolumes()
 Dim srfext, srfint
 
 For i=0 To ubound(polygons)
  
  centroid= Rhino.SurfaceVolumeCentroid (polygons(i))
  intVolume(i)= Rhino.ScaleObject (polygons(i), centroid(0), array(0.33,0.33,0.33),True)
  
  srfext= rhino.ExplodePolysurfaces (polygons(i))
 
  
  srfint= rhino.ExplodePolysurfaces (intVolume(i))
 
  For k=0 To ubound(srfext)
   srfext(k)= Rhino.DuplicateSurfaceBorder(srfext(k))
   srfint(k)= Rhino.DuplicateSurfaceBorder (srfint(k))
  
  Next
 
  
  For j=0 To ubound (srfext)
   
   ReDim arrSurf(ubound(srfext))
   ReDim Preserve newvolumes (ubound(srfext))
   
  
   
   arrSurf(j)= array(srfext(j)(0),srfint(j)(0))
   newvolumes(j)= Rhino.AddLoftSrf (arrSurf(j))
   

   rhino.DeleteObjects(srfext(j))
   rhino.DeleteObjects(srfint(j))
   
   
   
   
  Next
  
  
  For j=0 To ubound (srfext)
   ReDim Preserve newcapvolumes(ubound(srfext))
   newcapvolumes(j)= Rhino.CapPlanarHoles (newvolumes(j)(0))
  Next
  
 
  f_SubdividePolygons= newvolumes
 Next
 
 
 
End Function

Function FindGrowVect (pt,arGrowPts,time)
 Dim i
 Dim length, scale,timescale
 Dim vect: vect= array(0,0,0)
 Dim adVect
 Dim vectz
 
 
 For i=0 To ubound (arGrowPts)
  adVect = rhino.vectorcreate (pt,arGrowPts(i))
  vectz = array (0,0,(adVect(2))*.75)
  length = Rhino.VectorLength (adVect)
  adVect = Rhino.VectorUnitize (adVect)
  
  scale = 100/length
  adVect = rhino.VectorScale (adVect,scale)
  vect = rhino.VectorAdd (adVect,vect)
  vect = rhino.VectorAdd (vectz, vect)
  timescale= (1-(time/10))
  vect = rhino.VectorScale (vect,timescale)
 Next
 
 
 
 FindGrowVect = vect
 
 
End Function
‘tool Functions

Function f_GetPointArrayFromVolumes (arVolumes)
 f_GetPointArrayFromVolumes = Null
 
 Dim arVolPts()
 ReDim arVolPts (Ubound (arVolumes))
 
 Dim i,j
 Dim explode,cellpts(),cellcurve
 
 For i=0 To ubound (arVolPts)
  explode = rhino.ExplodePolysurfaces (arVolumes(i))
  
  ReDim cellpts (Ubound (explode))
  For j=0 To Ubound (cellpts)
   cellcurve = Rhino.DuplicateSurfaceBorder (explode(j))
   cellpts(j) = rhino.CurvePoints (cellcurve(0))
   rhino.deleteobject cellcurve(0)
  Next
  arVolPts (i) = cellpts
  rhino.DeleteObjects explode
  
 Next
 
 f_GetPointArrayFromVolumes = arVolPts
 
 
 
End Function
Function f_GetVolumeCentroids (arVolPts)
 f_GetVolumeCentroids = Null
 Dim i,n,j,k
 ReDim arCntroids (Ubound (arVolPts))
 Dim flatpts
 
 For i=0 To ubound (arVolPts)
  flatpts = Flatten2DptArray (arVolPts(i))
  flatpts = CleanOutRedundantPts (flatpts)
  arCntroids(i) = FindCntrOfPts (flatpts)
 Next

 f_GetVolumeCentroids = arCntroids

End Function
Function Flatten2DptArray (Arpts)
 Dim i,j,n
 Dim newpts()
 n=0
 For i=0 To ubound (Arpts)
  For j=0 To ubound (Arpts(i))
   ReDim Preserve newpts (n)
   newpts(n) = Arpts(i)(j)
   n=n+1
  Next
 Next
 
 Flatten2DptArray = newpts
 
 
End Function

Function CleanOutRedundantPts (arpts)

 Dim i,j
 Dim n : n=0
 Dim trig
 Dim d
 Dim returnpts()
 
 For i=0 To Ubound (arpts)
  If i=0 Then
   ReDim Preserve returnpts(n)
   returnpts(n) = arpts(i)
   n=n+1
  Else
   trig = False
   For j=0 To ubound (returnpts)
    d=rhino.Distance (arpts(i),returnpts(j))
    If d < 0.1 Then
     trig = True
    End If
   Next
   If trig = False Then
    ReDim Preserve returnpts(n)
    returnpts(n) = arpts(i)
    n=n+1
   End If
  End If
 Next
 
 CleanOutRedundantPts = returnpts
 
 

End Function

Function f_DrawResultVolumes (arVolumes,arVolPts)

 Dim i,j,k
 Dim surf()
 ReDim surf(ubound(arVolPts(i)))
 
 Dim volum()
 ReDim volum(ubound(arVolpts))
 
 For i=0 To ubound (arVolPts)
  For j=0 To ubound (arVolPts(i))
   
   arVolPts(i)(j)=Rhino.CullDuplicatePoints(arVolPts(i)(j))
   surf(j) = Rhino.AddSrfPt  (arVolPts(i)(j))
   
   
  
  Next
  
  volum(i) = Rhino.JoinSurfaces (surf)
  rhino.deleteobjects surf
  
 Next
 arVolumes= volum
 
End Function

Function FindCntrOfPts (arrPts)

 Dim Vects(),finvect
 ReDim Vects (Ubound (arrPts))
 Dim i
 
 For i=0 To ubound(arrPts)
  Vects(i) = rhino.vectorCreate (arrPts(i),array(0,0,0))
 Next
 finvect = rhino.vectorCreate (array(0,0,0),array(0,0,0))
 
 For i=0 To ubound (Vects)
  finvect= rhino.vectoradd (Vects(i),finvect)
 Next
 
 Finvect=Rhino.vectorScale (finvect,1/i)
 
 
 FindCntrOfPts = Finvect
 
 
End Function

NO&BR_infect path from path _ max dist

Option Explicit
‘Script written by <naomi ocko and ben riley>
‘Script copyrighted by <insert company name>
‘Script version Monday, 09 November 2009 18:58:49

Call Main()
Sub Main()

 Dim i,j,k
 Dim acs, apts
 Dim aPlan, dRad, dRadMax, dRadDefault
 Dim sCrv, aparam
 Dim aPt, aPtOnCrv
 Dim dTreshold, dD
 ’Dim RedIDs
 Dim Allpts
 Dim dThresh
 ’Dim iterations
 Dim sp, sC
 Dim nFibers ‘aptsCircle
 Dim vect,mid
 ’Allpts = rhino.GetObjects (“sel pts”,1)
 acs = rhino.GetObjects(“pick crvs”, 4)
 If isnull(acs) Then Exit Sub
 
 sCrv = rhino.GetObject(“pick path”, 4)
 If isnull(sCrv) Then Exit Sub
 
 ’dTreshold value was 3
 dTreshold = 7
 dRadMax = .1
 dRadDefault = 0.001
 
 Call Rhino.EnableRedraw(False)
 ” ———————————————————–
 ” divide crvs
 For i=0 To ubound (aCs)
  mid = rhino.CurveMidPoint (aCs(i))
  aParam = rhino.CurveClosestPoint(sCrv, mid)
  aPtOnCrv = rhino.EvaluateCurve(sCrv,aParam)
  
  dD = xyDist (mid,aPtOnCrv)
  
  
 
  apts = rhino.DivideCurveLength(aCs(i), 0.1)
  
  
  ReDim aptsCircle(UBound(apts))
  For j = 0 To UBound(apts)
   
   ” PT
   ’sp = rhino.addPoint(apts(j))
   
   ”PATH
   aParam = rhino.CurveClosestPoint(sCrv, aPts(j))
   aPtOnCrv = rhino.EvaluateCurve(sCrv,aParam)
   dD = xyDist (aPtOnCrv,aPts(j))
   
   ” RAD
  
   
   ’If dD < dTreshold Then
   If dD < random(.0001, 1)* dTreshold Then
   ’If dD < random(.1,.7)* dTreshold Then    ’dRad = dRadmax – (dRadMax * dD/dTreshold)
    ’zdist = abs (aPts(j)(2),aPtOnCrv(2))
    ’dRad = (dRadMax*(dD^2/dTreshold)) + dD/30
    ’If dD < 1.5 then
     dRad = (dRadMax*(dD^2/dTreshold)) + dRadDefault
    ’Else dRad = dRadMax
     
    ’End If
     
     
    ’vect = rhino.vectorcreate (aPts(j),aPtOnCrv)
    ’vect = rhino.vectorscale (vect, 0.66)
    ’aPts(j) = rhino.PointAdd (aPts(j),vect)

   
    aPlan = Rhino.MovePlane(Rhino.WorldXYPlane(),aPts(j))
    sC = Rhino.AddCircle (aPlan,dRad)
    
    ’dRad = dRadMax
   End If
   
   
   
   
  Next
  
 Next
 
  

 Call Rhino.EnableRedraw(True)
 
End Sub
Function xyDist (pt1,pt2)
 Dim d,pt1f,pt2f
 
 pt1f = rhino.PointAdd (pt1,array(0,0,-pt1(2)))
 pt2f = rhino.PointAdd (pt2,array(0,0,-pt2(2)))
 
 d = rhino.Distance (pt1f,pt2f)
 xyDist = d
 
 
 
End Function
Function Random (min, max)

 Random = Rnd*(max-min) + min

End Function

NO&BR_infect path from path_with gradient

Option Explicit
‘Script written by <insert name>
‘Script copyrighted by <insert company name>
‘Script version Monday, 09 November 2009 18:58:49

Call Main()
Sub Main()

 Dim i,j, k
 Dim acs, apts
 Dim aPlan, dRad, dRadMax, dRadDefault
 Dim sCrv, aparam
 Dim aPt, aPtOnCrv
 Dim dTreshold, dD
 Dim RedIDs
 Dim Allpts
 Dim dThresh
 Dim iterations
 Dim sp, sC, sFib
 Dim nFibers, aptsCircle
 
 ’Allpts = rhino.GetObjects (“sel pts”,1)
 acs = rhino.GetObjects(“pick crvs”, 4)
 If isnull(acs) Then Exit Sub
 
 sCrv = rhino.GetObject(“pick path”, 4)
 If isnull(sCrv) Then Exit Sub
 
 dTreshold = 3
 dRadMax = .25
 dRadDefault = 0.03
 nFibers = 15
 
 Call Rhino.EnableRedraw(False)
 ” ———————————————————–
 ” divide crvs
 For i=0 To ubound (aCs)
  ’apts = Rhino.CurveMidPoint(acs(i))
  ’apts = rhino.DivideCurveLength(acs(i), 0.25)
  apts = rhino.DivideCurve(acs(i), 2)
  
  ’To use midpt, firt divide crv by distance – but not array
  ’apts = Rhino.CurveMidPoint(acs(i))
  
  
  ReDim aptsCircle(UBound(apts))
  For j = 0 To UBound(apts)
   
   ” PT
   ’sp = rhino.addPoint(apts(j))
   
   ”PATH
   aParam = rhino.CurveClosestPoint(sCrv, aPts(j))
   aPtOnCrv = rhino.EvaluateCurve(sCrv,aParam)
   dD = rhino.Distance(aPts(j),aPtOnCrv)
   
   ” RAD
   If dD < dTreshold Then
    dRad = dRadmax – (dRadMax * dD/dTreshold) + dRadDefault
   Else
    dRad = dRadDefault
   End If
   
   ” CIRCLE
   ’aPlan = Rhino.MovePlane(Rhino.WorldXYPlane(),apts(j))
   aPlan = rhino.PlaneFromNormal(apts(j), rhino.CurveTangent(aCs(i),rhino.CurveClosestPoint(aCs(i), aPts(j))))
   sC = Rhino.AddCircle (aPlan,dRad)
   
   ’   ” COLOR
   ’   If dD < dTreshold Then
   ’    ’Call rhino.ObjectColor(sP, rgb(255-(200*dD/dTreshold),0,0))
   ’    Call rhino.ObjectColor(sC, rgb(255-(200*dD/dTreshold),0,0))
   ’   Else
   ’    Call rhino.ObjectColor(sC, vbBlue)
   ’   End If
   
   
   
   ” div circle
   aptsCircle(j) = rhino.DivideCurve(sC, nFibers)
   
   Call rhino.DeleteObject(sC)
   
  Next
  
  ReDim aPCrv(UBound(apts))
  For j = 0 To nFibers-1
   For k = 0 To UBound(apts)
    ’aPCrv(k) = aptsCircle(k)(j)
    aPCrv(k) = aptsCircle(k)((nFibers-1)*rnd)
   Next
   ’sFib = rhino.addInterpCurve(aPCrv)
   sFib = rhino.addCurve(aPCrv)
   Call rhino.ObjectColor(sFib, vbgreen)
  Next
  ’  
 Next

 Call Rhino.EnableRedraw(True)
 
End Sub

SG&RM_Protocols

SG&RM_particles_machine

Particles Script

Option Explicit
‘Script written by <reihaneh_sara>
‘Script copyrighted by <reihaneh_sara>
‘Script version Monday, 26 October 2009 17:19:47

Call Main()
Sub Main()
Dim aCrvs  : aCrvs =  rhino.getobjects(“pick path”, 4)
Dim i,j,k
Dim aps,ap,strPt
Dim range, rangeLocal, seedPlacement, n
seedPlacement = 10
n = 20
Call rhino.EnableRedraw(False)

For i =0 To UBound(aCrvs)
range=15
aps =DivideCurveLength(aCrvs(i),seedPlacement)
For j = 0 To Ubound(aps)
For k = 0 To int(n-(Ubound(aps)/n*j))
rangeLocal = range – (range/Ubound(aps)*j)
ap = array(aps(j)(0)+ rnd*range,_
aps(j)(1)+rnd*range,_
aps(j)(2))
strPt = rhino.addpoint(ap)

If k Mod 2 =0 Then
Call rhino.ObjectColor (strPt,rgb(255,0,0))
Else
Call rhino.ObjectColor (strPt,rgb(0,255,0))
End If
Call rhino.addpoint(ap)
Next
Next
Next
Call rhino.EnableRedraw(True)
Call component
End Sub
Function component
Dim strpts : strpts = rhino.GetObjects (“selpts”,1)
Dim i,j,k,l,m,pt
Dim component1 : component1 = rhino.GetObjects (“sel Component1″)
Dim compent1Cntr : compent1Cntr = rhino.GetPointCoordinates (“sel Comp1 Cntr”)
Dim component2 : component2 = rhino.GetObjects (“sel Component2″)
Dim compent2Cntr : compent2Cntr = rhino.GetPointCoordinates (“sel Comp2 Cntr”)
For k=0 To ubound (strpts)
For l=0 To ubound (component1)
If rhino.ObjectColor (strpts(k)) = rgb(255,0,0) Then
pt = rhino.PointCoordinates (strpts(k))
rhino.CopyObject component1(l),compent1Cntr(0),pt
End If
Next
For m=0 To ubound (component2)
If rhino.ObjectColor (strpts(k)) = rgb(0,255,0) Then
pt = rhino.PointCoordinates (strpts(k))
rhino.CopyObject component2(m),compent2Cntr(0),pt
End If
Next
Next
End Function

Machine Trajectory Definition

Machine1Machine1.1Machine1.2Machine1.3

SG&RM_particles_random_angle_scale

Option Explicit
‘Script written by <reihaneh_sara>
‘Script copyrighted by <insert company name>
‘Script version Monday, December 7, 2009 7:16:30 PM

Call Main()
Sub Main()

Dim strpts : strpts = rhino.GetObjects (“selpts”,1)
Dim i,j,pt
Dim component : component = rhino.GetObjects (“sel Component”)
Dim compentCntr : compentCntr = rhino.GetPointCoordinates (“sel Comp Cntr”)
Dim vect,angle,strobj
Dim scale

For i=0 To ubound (strpts)
For j=0 To ubound (component)
If rhino.ObjectColor (strpts(i)) = rgb(0,0,0) Then
angle = random (0,360)
vect = array (random(-10,10),random(-10,10),random(-10,10))
scale = random (0.5,1)
pt = rhino.PointCoordinates (strpts(i))
strobj = rhino.CopyObject (component(j),compentCntr(0),pt)
rhino.RotateObject strobj,pt,angle,vect,False
rhino.ScaleObject strobj,pt,array(scale,scale,scale)

End If
Next
Next

End Sub

Function random(min,max)
random=Rnd*(max-min)+min
End Function

SG&RM_particles_random_range_color

Option Explicit
‘Script written by <reihaneh_sara>
‘Script copyrighted by <insert company name>
‘Script version Friday, 4 December 2009 11:19:47

Call Main()
Sub Main()

Dim aCrvs
Dim i,j, k
Dim aps, ap, pt, lColor,Colpt
Dim range, rangeLocal, nSeeds, n
Dim l,p
‘Dim component : component = rhino.GetObjects (“sel Component”)
‘Dim compentCntr : compentCntr = rhino.GetPointCoordinates (“sel Comp Cntr”)
Dim vect,angle,strobj
Dim scale
Dim strpts()
Dim count : count = 0
Dim p1,p2, p3, m, Pspread

aCrvs =  rhino.getobjects(“pick path”, 4)

nSeeds = 100
PSpread = 5
‘n = 25

Call rhino.EnableRedraw(False)
For i =0 To UBound(aCrvs)
range=30
aps =DivideCurve(aCrvs(i),nSeeds)
For j = 0 To Ubound(aps)

ReDim Preserve strPts(20)
For k = 0 To 20
‘For k = 0 To int(n-(Ubound(aps)/n*j))
‘rangeLocal = range/Ubound(aps)*j

” SET RANGE BY HALF CRVS
If j < Ubound(aps)/2 Then
rangeLocal = range/(Ubound(aps)/2)*j
Else
rangeLocal = range – (range/(Ubound(aps)/2)*j/2)
End If
” PT COORD
ap = array(aps(j)(0)+ random(-rangeLocal,rangeLocal),_
aps(j)(1)+random(-rangeLocal,rangeLocal),_
aps(j)(2)+random(-rangeLocal,rangeLocal))

” DRAW
‘ReDim Preserve strPts(count)
‘strpts(k) = rhino.addpoint(ap)
‘pt = rhino.addpoint(ap)

” draw particul
For m = 0 To 4
p1 = array(ap(0)+random(-PSpread,PSpread),_
ap(1)+random(-PSpread,PSpread),_
ap(2)+random(-PSpread,PSpread))
p2 = array(ap(0)+random(-PSpread,PSpread),_
ap(1)+random(-PSpread,PSpread),_
ap(2)+random(-PSpread,PSpread))
p3 = array(ap(0)+random(-PSpread,PSpread),_
ap(1)+random(-PSpread,PSpread),_
ap(2)+random(-PSpread,PSpread))
Call rhino.AddCurve(array(ap,p1,p2, p3))
Next

” COLOR
If j < Ubound(aps)/2 Then
lColor = rgb(255/(Ubound(aps)/2)*j,191/(Ubound(aps)/2)*j,0)
Else
lColor = rgb(255-(255/(Ubound(aps)/2)*j/2),191-(191/(Ubound(aps)/2)*j/2),0)
End If
‘Call rhino.ObjectColor(strpts, lColor)
‘count = count+1
Next

Next
Next

‘    For p=0 To ubound (strpts)
‘        For l=0 To ubound (component)
‘            angle = random (0,360)
‘            vect = array (random(-10,10),random(-10,10),random(-10,10))
‘            scale = random (0.5,1)

‘            pt = rhino.PointCoordinates (strpts(p))
‘            strobj = rhino.CopyObject (component(l),compentCntr(0),pt)
‘            rhino.RotateObject strobj,pt,angle,vect, False
‘            rhino.ScaleObject strobj,pt,array(scale,scale,scale)
‘            ’Call rhino.ObjectColor(strobj, Colpt)

‘        Next
‘    Next

Call rhino.EnableRedraw(True)
‘Call Rhino.DeleteObjects (strPts)

End Sub

Function random(min,max)
random=Rnd*(max-min)+min
End Function

090918_WrkShp_01

Option Explicit
‘Script written by <MathewStaudt>
‘Script copyrighted by <None>
‘Script version Friday, September 18, 2009 3:00:15 PM

Call Main()

Sub Main()

 ’Get Closed Polylines And declare flow control variable
 ’4 Is a selection filter (see help files)
 Dim Polylines : Polylines = rhino.GetObjects (“Select tiangle”,4)
 Dim distLim : distLim = 5 ‘tells script To Stop subdividing once a curve Is shorter than disLim
 Dim i  ‘a counter

 ’Loop through all polylines And subdivide them over And over again
 For i=0 To Ubound (Polylines)
  ’Function has 2 inputs : the curve To subdivide And the limit To how small the subdivision can go
  Call SubDivide (Polylines(i),distLim)
 Next

End Sub

Function SubDivide (cell,lim) ‘(Function inputs)

 ’Declare all variables used In the Function
 Dim midpts,cntr,crvpts
 Dim j,a
 Dim lngth
 Dim line

 midpts = f_getMidsFromPoly (cell) ‘custom Function that returns an array of midpoint coordinates
 cntr = rhino.CurveAreaCentroid (cell) ‘method returns an array of 2 elements, we are only interested In the first: cntr(0) see help files
 crvpts = rhino.CurvePoints (cell) ‘method returns the endpts of the polyline as an array 3d coordinates

 For j=0 To ubound (midpts)
  ’rhino.AddTextDot “M” & j,midpts (j)
  ’rhino.AddTextDot “P” & j,crvpts  (j)

  ’the New cell Is drawn by looping through all the midpoints,
  ’drawing a line from that midpoint To the cntr, To the midpoint In front of him, To the curvepoint In front of him, And back To himself
  ’a problem arrises when you Get To the last midpoint In the array ( midpts(Ubound(midpts) ) there Is no midpoint In font of him!
  ’ To solve this problem you tell the script that If you are at the last midpoint : j= Ubound (midpoints)
  ’ Then look To the first midpoint In the array ‘ a=0 otherwise look In front of you a=j+1
  If j = Ubound (midpts) Then
   a=0
  Else
   a=j+1
  End If

  ’draw New cell Then measure the length of it To check If you should continue To subdivide
  line = rhino.AddPolyline ( array  ( midpts(j),cntr(0),midpts(a),crvpts(a),midpts(j) ))
  lngth = rhino.CurveLength (line)
  ’If the length of the New cell Is long enough, subdivide it again
  If lngth > lim Then
   Call SubDivide (line,lim)
  End If
 Next

End Function

Function f_getMidsFromPoly (plyln)

 ’Is custom To Null a Function first
 f_getMidsFromPoly = Null

 ’explode curves, Get their midpoints
 Dim explode : explode = rhino.ExplodeCurves (plyln)
 Dim mids()
 ReDim mids (ubound (explode))
 Dim i

 For i=0 To ubound (explode)
  mids(i) = rhino.CurveMidPoint (explode (i))
 Next

 ’Fuction output Is defined as such:
 f_getMidsFromPoly = mids

 ’Delete exploded curves
 rhino.DeleteObjects explode

End Function

 

--------------------------------------------------------------

Pages of codes / BACK