2009年2月25日 星期三
Rhino Script Excise09
aim: add one new vertex in the middle position of every two continuous existing vertices of a polyline.
Option Explicit
'Script written by Jeong-der ho, based on Robert McNeel & Associates Rhino script tutorial
'Script copylefted by de place
'Script version 2009年2月18日 上午 11:25:38
Call DividePolyline()
Sub DividePolyline()
Dim strOriPolyline
strOriPolyline = Rhino.GetObject("Select a Polyline sample", 4, True, True)
If IsNull(strOriPolyline) Then Exit Sub
Dim arrPolyVertices
arrPolyVertices = Rhino.PolylineVertices(strOriPolyline)
Dim arrNewVertices
arrNewVertices = SubDividePolyline(arrPolyVertices)
Dim strNewPolyline
Dim arrStart : arrStart = Array(0,0,0)
Dim arrEnd : arrEnd = Array(10,0,0)
strNewPolyline = Rhino.AddPolyline (arrNewVertices)
Call Rhino.MoveObject(strNewPolyline, arrStart, arrEnd)
End Sub
Function SubDividePolyline(ByRef arrV)
Dim arrSubD() : ReDim arrSubD(2 * UBound(arrV))
Dim i
For i = 0 To UBound(arrV)-1
'copy the original vertex location
arrSubD(i * 2) = arrV(i)
'compute the average of the current vertex and the next one
arrSubD(i * 2 + 1) = Array( (arrV(i)(0) + arrV(i+1)(0)) / 2.0, _
(arrV(i)(1) + arrV(i+1)(1)) / 2.0, _
(arrV(i)(2) + arrV(i+1)(2)) / 2.0)
Next
'copy the last vertex (this is skipped by the loop)
arrSubD(UBound(arrSubD)) = arrV(UBound(arrV))
SubDividePolyline = arrSubD
End Function
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言