Point Density Based on Surface Curvature

This RhinoScript places points on a surface with the density of points varying with the curvature of the surface. A version of this script has been used in the TableCloth project by Ball-Nogues Studio at the Schoenberg Hall courtyard in the UCLA Department of Music.

Option Explicit
‘Script written by <Ayodh Kamath>
‘Script copyrighted by <Ayodh Kamath>
‘Script version Tuesday, June 22, 2010 6:14:09 PM
Call Main()
Sub Main()
Dim strSrf, intUdiv, intVdiv, arrPts, arrHeightDiff, arrRange
Dim i, j
strSrf = Rhino.GetObject(“Select surface to populate with points”,8)
intUdiv = Rhino.GetInteger(“Enter number of U divisions”)
intVdiv = Rhino.GetInteger(“Enter number of V divisions”)
arrPts = IsoPoints(strSrf, intUdiv, intVdiv)
arrHeightDiff = HeightDifference(arrPts, intUdiv, intVdiv)
arrRange = HeightRange(arrHeightDiff, intUdiv, intVdiv)
Call SubDivide(strSrf, arrPts, intUdiv, intVdiv, arrHeightDiff, arrRange)
End Sub
Function IsoPoints(strSrf, intUdiv, intVdiv)
Dim arrUdomain, arrVdomain
Dim i,j
ReDim arrPts(intUdiv, intVdiv)
ReDim arrParamsU(intUdiv)
ReDim arrParamsV(intVdiv)
arrUdomain = Rhino.SurfaceDomain(strSrf, 0)
arrVdomain = Rhino.SurfaceDomain(strSrf, 1)
For i = 0 To intUdiv
For j = 0 To intVdiv
arrParamsU(i) = i*(arrUdomain(0)+arrUdomain(1))/intUdiv
arrParamsV(j) = j*(arrVdomain(0)+arrVdomain(1))/intVdiv
arrPts(i,j) = Rhino.EvaluateSurface(strSrf, Array(arrParamsU(i), arrParamsV(j)))
‘Call Rhino.AddPoint(arrPts(i,j))
IsoPoints = arrPts
End Function
Function HeightDifference(arrPts, intUdiv, intVdiv)
Dim arrPt1, arrPt2, arrPt3, arrPt4, arrSortHeights
Dim i, j
ReDim arrHeights(intUdiv-1, intVdiv-1)
ReDim arrY(3)
For i = 0 To intUdiv – 1
For j = 0 To intVdiv – 1
arrPt1 = arrPts(i,j)
arrPt2 = arrPts(i+1,j)
arrPt3 = arrPts(i+1,j+1)
arrPt4 = arrPts(i,j+1)
arrY(0) = arrPt1(1)
arrY(1) = arrPt2(1)
arrY(2) = arrPt3(1)
arrY(3) = arrPt4(1)
arrSortHeights = Rhino.SortNumbers(arrY)
arrHeights(i,j) = Round(arrSortHeights(3)-arrSortHeights(0), 2)
HeightDifference = arrHeights
End Function
Function HeightRange(arrHeights, intUdiv, intVdiv)
Dim i, j, intCount, arrSortHeight
ReDim arrHeightFlat((intUdiv*intVdiv)-1)
ReDim arrRange(3)
intCount = 0
For i = 0 To intUdiv-1
For j = 0 To intVdiv-1
arrHeightFlat(intCount) = arrHeights(i,j)
intCount = intCount+1
arrSortHeight = Rhino.SortNumbers(arrHeightFlat)
arrRange(0) = arrSortHeight(0)
arrRange(1) = arrSortHeight(Int(((intUdiv*intVdiv)-1)/3))
arrRange(2) = arrSortHeight(Int((2*((intUdiv*intVdiv)-1))/3))
arrRange(3) = arrSortHeight((intUdiv*intVdiv)-1)
HeightRange = arrRange
End Function
Function SubDivide(strSrf, arrPts, intUdiv, intVdiv, arrHeightDiff, arrRange)
Dim intPtNum, strTempSrf, arrTempPts, arrParams, arrPt, intBaseDensity
Dim i, j, k, l
intBaseDensity = Rhino.GetInteger(“Enter base density”,2,0)
For i = 0 To intUdiv-1
For j = 0 To intVdiv-1
If arrheightDiff(i,j)>= arrRange(0) And arrheightDiff(i,j)<= arrRange(1) Then
intPtNum = intBaseDensity*2
ElseIf arrheightDiff(i,j)> arrRange(1) And arrheightDiff(i,j)<= arrRange(2) Then
intPtNum = Int(intBaseDensity*1.5)
intPtNum = intBaseDensity
End If
strTempSrf = Rhino.AddSrfPt(Array(arrPts(i,j), arrPts(i+1,j), arrPts(i+1,j+1), arrPts(i,j+1)))
arrTempPts = IsoPoints(strTempSrf, intPtNum, intPtNum)
For k = 0 To intPtNum
For l = 0 To intPtNum
arrParams = Rhino.SurfaceClosestPoint(strSrf, arrTempPts(k,l))
arrPt = Rhino.EvaluateSurface(strSrf, arrParams)
If k<>0 And k<>intPtNum And ((k/2)-Int(k/2))<>0 Then
If ((l/2)-Int(l/2))=0 Then
Call Rhino.AddPoint(arrPt)
End If
If k<>0 And k<>intPtNum And ((l/2)-Int(l/2))<>0 Then
Call Rhino.AddPoint(arrPt)
End If
End If
Call Rhino.DeleteObject(strTempSrf)
End Function

One thought on “Point Density Based on Surface Curvature

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