Curve Fitting Script

This is a very simple curve fitting script to find where a short curve fits best along longer curve. I’ve developed this script in the context of my on-going work with bamboo weaving.

The curve fitting script finds where a short curve fits best along longer curve.

The Nest Roof is a result of woven bamboo beams following paths of minimum curvature along a funicular surface.

A 1:50 scale model of the Nest Roof

While the bamboo beams may follow paths of minimum curvature, one is still left with the possibility to further optimize the selection of where along a beam profile to use each individual piece of bamboo. Bamboo being a natural material does not have uniform properties and every piece of bamboo is different. Every piece has a different shape and bends by a different amount. Therefore different pieces of bamboo will be suited to different parts of the roof with different beam curvature. Selecting the right piece of bamboo for a given segment of a beam is fundamentally finding where along the beam a given piece of bamboo fits best so that it will have to be bent a minimum amount, which is what this script does. However, it is far from clear how exactly, and if at all, the script can be used during construction. The principal problem is finding a work flow whereby the curvature of each individual piece of bamboo can be recorded and digitized so as to form an input for this script (or some version of it) during construction, and a way to convey the result of the script in real time to the craftspersons building the roof. These issues were tackled in my SMArchS thesis, but only at a theoretical level and at a table top model scale. I hope to be able to carry this forward to a building scale and a live project through the Nest Roof.

The script uses a very crude brute force algorithm that incrementally slides a short curve (representing an individual piece of bamboo) along a longer curve (the beam profile) while checking the deviation between the two curves at each increment. The length of the increment can be specified and the smaller the increment the more accurate the result will be. An interesting by-product of the brute force algorithm is the plant like shapes that it produces. “Leaves” appear to sprout as the script slides one curve along the other, and then the “leaves” are then shed as the script deletes all but the best-fit result.

"Leaves" formed during the running of the script

Below is a version of the script that works on planar curves, but the same idea can be expanded to apply to 3D curves as well –

Option Explicit
‘Script written by <Ayodh Kamath>
‘Script copyrighted by <Kamath Design Studio/PostScriptDesign>
‘Script version 08 April 2012 14:18:42

Call Main()
Sub Main()

Dim strCrv1, strCrv2, dblDivLength, arrDivPts1, arrDivPts2
Dim intCheckPt, strAlignCrv
Dim intCount, intMin
Dim j, i

strCrv1 = Rhino.GetObject(“Select guide curve to check against”,4)
strCrv2 = Rhino.GetObject(“Select curve to check”,4)

dblDivLength = (Rhino.CurveLength(strCrv2))/10
dblDivLength = Rhino.GetReal(“Enter division length:”, dblDivLength)

arrDivPts1 = Rhino.DivideCurveLength(strCrv1, dblDivLength)
arrDivPts2 = Rhino.DivideCurveLength(strCrv2, dblDivLength)

ReDim arrDot(UBound(arrDivPts1))

For i = 0 To UBound(arrDivPts1)

arrDot(i) = Rhino.AddTextDot(CStr(i), arrDivPts1(i))

Next

intCheckPt = Rhino.GetInteger(“Enter point number to check from”, 0, 0, (UBound(arrDivPts1) – UBound(arrDivPts2)))
Call Rhino.DeleteObjects(arrDot)

ReDim arrDev(((UBound(arrDivPts1) – UBound(arrDivPts2) – intCheckPt + 1)*(UBound(arrDivPts2))) – 1)
ReDim arrAlignCrvs(((UBound(arrDivPts1) – UBound(arrDivPts2) – intCheckPt + 1)*(UBound(arrDivPts2))) – 1)

intCount = 0

For i = intCheckPt To (UBound(arrDivPts1) – UBound(arrDivPts2))

For j = 1 To UBound(arrDivPts2)

arrAlignCrvs(intCount) = Rhino.OrientObject(strCrv2, Array( arrDivPts2(0), arrDivPts2(j)), Array(arrDivPts1(i), arrDivPts1(i + j)),1)

arrDev(intCount) = Deviation(strCrv1, arrAlignCrvs(intCount), i, dblDivLength, arrDivPts1)

intCount = intCount + 1

Next

Next

intCount = intCount – 1

intMin = Minimum(arrDev)

For i = 0 To UBound(arrDev)

If i <> intMin Then

Call Rhino.DeleteObject(arrAlignCrvs(i))

End If

Next

Call Rhino.SelectObject(arrAlignCrvs(intMin))

End Sub

Function Deviation(ByRef strCrv1, strAlignCrv, intFnCheckPt, ByRef dblDivLength, ByRef arrDivPts1)

End Function

Function Minimum(arrCheck)
End Function

Advertisements

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