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