1128dancing_final

Option Explicit
‘Script written by Macus Chen
‘Script copyrighted by <insert company name>
‘Script version Friday, November 13, 2009 10:55:04 PM

Call Main()
Sub Main()
Dim strCurveID, t, arrPt, arrPts(),t1
strCurveID = Rhino.GetObject(“Select a curve to sample”, 4, True, True)
If IsNull(strCurveID) Then Exit Sub
‘Call Rhino.EnableRedraw(False)

Dim count,transPt, transPtOld, transPtNew, interLine, arrParameter
Dim midPt, newCrv

Dim curveLengthSample
curveLengthSample = rhino.CurveLength(strCurveID)
rhino.print curveLengthSample

count = 0

For t = 0.01 To 1 Step 0.02
ReDim Preserve arrPts(count)

If count > 0 Then
transPtOld = transPt ‘TRANS2
End If

arrParameter = AddPointAtR1Parameter(strCurveID, t)

arrPts(count) = arrParameter(0)
transPt = arrParameter(2)’TRANS1
transPtNew = arrParameter(1)
‘rhino.Addpoint transPt

If count > 0 Then
interLine = rhino.AddLine(transPtOld, transPtNew)

midPt = rMidPrepPt(interLine)
newCrv = rhino.AddCurve(array(transPtOld,midPt,transPtNew))
rhino.DeleteObject interLine

End If

count = count + 1
Next
‘Call Rhino.EnableRedraw(True)
End Sub

Function AddPointAtR1Parameter(strCurveID, dblUnitParameter)
AddPointAtR1Parameter = Null

Dim crvDomain, dblR1Param, arrR3Point, strPointID
crvDomain = Rhino.CurveDomain(strCurveID)

dblR1Param = crvDomain(0) + dblUnitParameter * (crvDomain(1) – crvDomain(0))

arrR3Point = Rhino.EvaluateCurve(strCurveID, dblR1Param)

strPointID = Rhino.AddPoint(arrR3Point)

‘AddPointAtR1Parameter = strPointID

Dim tangentVec, prepVec,reversePrepVec
tangentVec = Rhino.CurveCurvature(strCurveID, dblUnitParameters)(1)
prepVec = rhino.VectorRotate(tangentVec,-90,array(0,0,1))
prepVec = rhino.VectorUnitize(prepVec)
prepVec = rhino.VectorScale(prepVec,3.2+rnd*0.4)
reversePrepVec = rhino.VectorReverse(prepVec)

Dim pt1, pt2

pt1 = rhino.PointAdd(arrR3Point, prepVec)
pt2 = rhino.PointAdd(arrR3Point, reversePrepVec)

‘pt1 = rhino.AddPoint(pt1)
‘pt2 = rhino.AddPoint(pt2)
Dim crv, midPt,newCrv

crv = rhino.AddLine(pt1,pt2)
midPt = midPrepPt(crv)
newCrv = rhino.AddCurve(array(pt1,midPt,pt2))
rhino.DeleteObject crv

AddPointAtR1Parameter = array(strPointID,pt1,pt2)

End Function

Function midPrepPt(line)
Dim startPt, endPt, midPt
startPt = Rhino.CurveStartPoint(line)
endPt = Rhino.CurveEndPoint(line)
midPt = Rhino.CurveMidPoint(line)

Dim vec
vec = rhino.VectorCreate(endPt,startPt)
vec = rhino.VectorRotate(vec,90,array(0,0,1))  ”rotate nishizhen
vec = rhino.VectorUnitize(vec)
vec = rhino.VectorScale(vec,1000)

Dim addMidPt
addMidPt = rhino.PointAdd(midPt,vec)

midPrepPt = addMidPt

‘rhino.AddPoint addMidPt

End Function

Function rMidPrepPt(line)
Dim startPt, endPt, midPt
startPt = Rhino.CurveStartPoint(line)
endPt = Rhino.CurveEndPoint(line)
midPt = Rhino.CurveMidPoint(line)

Dim vec
vec = rhino.VectorCreate(endPt,startPt)
vec = rhino.VectorRotate(vec,-90,array(0,0,1))  ”rotate nishizhen
vec = rhino.VectorUnitize(vec)
vec = rhino.VectorScale(vec,1000)

Dim addMidPt
addMidPt = rhino.PointAdd(midPt,vec)

rMidPrepPt = addMidPt

‘rhino.AddPoint addMidPt

End Function

Function avoid (obstacle,threshold)

End Function

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 )

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