web analytics
VIOLENT  VOLUMES

Polyline OffsetStructure

'---------------------------------------------------------------
'take closed polyline and returns polyline of each offset step
'---------------------------------------------------------------
Function OffsetCurveStructure(strCurve)

	Dim arrPolylineVertices
	arrPolylineVertices = Rhino.PolylineVertices(strCurve)

	Dim ActualVertNum
	ActualVertNum = UBound(arrPolylineVertices)

	Dim arrCenterPt

	'set of offset polylines at each step
	Dim arrOffsetStepPolylines
	Redim arrOffsetStepPolylines(UBound(arrPolylineVertices)-3) 

	'distance between offset steps
	Dim arrOffsetStepDistance
	Redim arrOffsetStepDistance(UBound(arrPolylineVertices)-4)

	Dim arrCurrentPolylineVertices
	Redim arrCurrentPolylineVertices(UBound(arrPolylineVertices))

	Dim arrCurrentLine1
	Dim arrCurrentLine2

	Dim currentVectorSet
	Redim currentVectorSet(UBound(arrPolylineVertices)-1)

	Dim arrFirstIntersectionIndex

	'Check if strCurve is closed
	If NOT Rhino.IsCurveClosed(strCurve) Then
		OffsetCurveStructure = vbNull
	End If

	'Check if strCurve is planar
	If NOT Rhino.IsCurvePlanar(strCurve) Then
		OffsetCurveStructure = vbNull
	End If

	Dim offsetDist

	Dim i,j,k
	Dim arrPrevPt, arrNextPt
	k = 0
	Rhino.Print "ActualVertNum is " & ActualVertNum

	arrOffsetStepPolylines(0) = arrPolylineVertices

	Do While ActualVertNum >3
		k = k+1
		arrCenterPt = GenCenterPoint(arrPolylineVertices)

		currentVectorSet = getVectorSet(arrPolylineVertices)

		'find which indices meet to make closest intersection
		arrFirstIntersectionIndex = getFirstIntersection(currentVectorSet)(1)
		offsetDist = getFirstIntersection(currentVectorSet)(0)

		'store offset distance of current step
		arrOffsetStepDistance(k-1) = offsetDist

		Rhino.Print "Now working on offset step : " & k+1 & ". and offset distance is " & offsetDist

		For i = 0 to UBound(arrPolylineVertices)-1

			arrPrevPt = getPrevPt(arrPolylineVertices,i)
			arrNextPt = getNextPt(arrPolylineVertices,i)

			arrCurrentLine1 = Array(arrPolylineVertices(i),arrPrevPt)
			arrCurrentLine2 = Array(arrPolylineVertices(i),arrNextPt)

			' Offset 2 lines
			arrCurrentLine1 = OffsetSingleLine(arrCurrentLine1,offsetDist,arrCenterPt)
			arrCurrentLine2 = OffsetSingleLine(arrCurrentLine2,offsetDist,arrCenterPt)

			'Rhino.Addline arrCurrentLine1(0),arrCurrentLine1(1)
			'Rhino.Addline arrCurrentLine2(0),arrCurrentLine2(1)

			'Get Intersection and store in current step of arrCurrentPolylineVertices
			arrCurrentPolylineVertices(i) = Rhino.LineLineIntersection (arrCurrentLine1, arrCurrentLine2)
			'Rhino.AddPoint arrCurrentPolylineVertices(i)

		Next

		arrCurrentPolylineVertices(UBound(arrPolylineVertices)) = arrCurrentPolylineVertices(0)

		'Uncomment this, you will see offset thresholds
		Rhino.AddPolyline(arrCurrentPolylineVertices)

		'get the result polylive for current step
		arrOffsetStepPolylines(k) = arrCurrentPolylineVertices
		'set it to arrPolylineVertices for next step
		arrPolylineVertices = arrCurrentPolylineVertices

		ActualVertNum = ActualVertNum-1
	Loop

	' returns arrPolylineVertices and offset distance of each offset step
	OffsetCurveStructure = Array(arrOffsetStepPolylines,arrOffsetStepDistance)

End Function

Took one of my precious weekends to finish this function that returns array of polylines of

each offset thresholds. Default Rhino offset function does not return what I want, so

I had to build my own.


Categorised as: Generative design


Leave a Reply

Your email address will not be published. Required fields are marked *

Connect with Facebook

* Copy This Password *

* Type Or Paste Password Here *