curves.bezier.01

Option Explicit
‘Script written by
‘Script copyrighted by
‘Script version Tuesday, July 21, 2009 7:50:34 PM

Call Main()
Sub Main()
Dim arrPoints,intSamples
Do
arrPoints = Rhino.GetObjects(“Select at Least 3 Points”,1,,True)
If isNull(arrPoints) Then Exit Sub

If uBound(arrPoints) > 1 Then
Exit Do
End If
Loop
intSamples = Rhino.GetReal(“Samples”,10,1)
If isNull(intSamples) Then Exit Sub

Dim i, arrPts(),arrOutput
ReDim arrPts(uBound(arrPoints))
For i = 0 To uBound(arrPoints) Step 1
arrPts(i) = Rhino.PointCoordinates(arrPoints(i))
Next

Call Rhino.EnableRedraw(False)
arrOutput = bezierConstructor(arrPts,intSamples)
Call Rhino.AddInterpCurve(arrOutput(0))
Call Rhino.ObjectColor(arrOutput(1),RGB(255,0,0))
Call Rhino.EnableRedraw(True)

End Sub
Function bezierConstructor(arrPts,intSamples)
bezierConstructor = Null
Dim i, j, k, r, s, t
Dim arrOutput(), arrOutputs(), arrStore, arrTemp, arrLines(),arrSet()
r = 0
k=1
ReDim arrOutput(0),arrOutputs(0)
arrOutput(0) = arrPts(0)

For i = 1 To uBound(arrPts) Step 1
ReDim Preserve arrLines(r),arrOutputs(r)
arrLines(r) = Rhino.AddLine(arrPts(i-1),arrPts(i))
arrOutputs(r) = arrLines(r)
r=r+1
Next
t=r
arrStore = arrLines
For i = 1 To intSamples-1 Step 1
r=0
s=0
arrTemp = arrStore
Do
If r = 1 Then
ReDim Preserve arrOutput(k)
arrOutput(k) = curveParameter(arrTemp(0),i*(1/intSamples))
k=k+1
Exit Do
End If
r=0
ReDim Preserve arrSet(s)
arrSet(s) = arrTemp
ReDim arrLines(0)
For j = 1 To ubound(arrSet(s)) Step 1
ReDim Preserve arrLines(r), arrOutputs(t)
arrLines(r) = Rhino.AddLine(curveParameter(arrSet(s)(j-1),i*(1/intSamples)),curveParameter(arrSet(s)(j),i*(1/intSamples)))
arrOutputs(t) = arrLines(r)
t=t+1
r=r+1
Next
arrTemp = arrLines
s=s+1
Loop
Next
ReDim Preserve arrOutput(k)
arrOutput(k) = arrPts(uBound(arrPts))
bezierConstructor = array(arrOutput,arrOutputs)
End Function
Function curveParameter(strCurve,dblParameter)
curveParameter = Null
Dim cDom,arrPoint
cDom = Rhino.CurveDomain(strCurve)
arrPoint = Rhino.EvaluateCurve(strCurve,cDom(0)+dblParameter*(cDom(1)-cDom(0)))
curveParameter = arrPoint
End Function

Advertisements

There are no comments on this post.

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 )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: