Feeds:
Posts

## Modified Surface Subdivision Code

To create a geodesic it will be imperative for me to deal with linear members which form triangles, and nodes where they join. I modified the surface subdivision code to construct triangles made up of single lines and introduced a set of conditionals that ensure that there are no overlapping lines. The lines thus constructed are placed in an array so that each line can then be manipulated in the future. Visually, however, the result of the script is just a triangulated surface. Here’s the code:

Option Explicit
‘Script written by <insert name>
‘Script copyrighted by <insert company name>
‘Script version Tuesday, January 13, 2009 4:44:45 PM

Call Main()
Sub Main()

Dim strObject : strObject = Rhino.GetObject(“Select Surface:”, 8)

‘Get integers x, y
Dim intX, intY

intX = Rhino.GetInteger(“Give X divisions”, 10, 2, 200)
intY = Rhino.GetInteger(“Give Y divisions”, 10, 2, 200)
intX = intX-1
intY = intY-1

‘Get surface domain
Dim arrU, arrV
arrU = Rhino.SurfaceDomain(strObject, 0)
arrV = Rhino.SurfaceDomain(strObject, 1)

‘Loop through U & V to get x & y
Dim intI, intJ
Dim arrPt(200, 200)
Dim arrParam(1)
For intI = 0 To intX
arrParam(0) = arrU(0)+(((arrU(1)-arrU(0)) / intX)*intI)
For intJ = 0 To intY
arrParam(1) = arrV(0)+(((arrV(1)-arrV(0)) / intY)*intJ)
arrPt(intI, intJ) = Rhino.EvaluateSurface(strObject, arrParam)
Next
Next

‘triangulate without overlapping lines
Dim intM, intN
Dim arrLin()
Dim intCount
For intM = 0 To (intX-1)
For intN = 0 To (intY-1)
If (intM Mod 2 = 0) And (intN Mod 2 = 0) Then
ReDim Preserve arrLin(intCount): arrLin(intCount) = Rhino.AddLine (arrPt(intM, intN), arrPt(intM+1, intN))
intCount = intCount + 1
ReDim Preserve arrLin(intCount): arrLin(intCount) = Rhino.AddLine (arrPt(intM+1, intN), arrPt(intM+1, intN+1))
intCount = intCount + 1
ReDim Preserve arrLin(intCount): arrLin(intCount) = Rhino.AddLine (arrPt(intM+1, intN+1), arrPt(intM, intN))
intCount = intCount + 1
ReDim Preserve arrLin(intCount): arrLin(intCount) = Rhino.AddLine (arrPt(intM+1, intN+1), arrPt(intM, intN+1))
intCount = intCount + 1
ReDim Preserve arrLin(intCount): arrLin(intCount) = Rhino.AddLine (arrPt(intM, intN+1), arrPt(intM, intN))
intCount = intCount + 1
ElseIf (intM Mod 2 <> 0) And (intN Mod 2 = 0) Then
ReDim Preserve arrLin(intCount): arrLin(intCount) = Rhino.AddLine (arrPt(intM, intN), arrPt(intM+1, intN))
intCount = intCount + 1
ReDim Preserve arrLin(intCount): arrLin(intCount) = Rhino.AddLine (arrPt(intM+1, intN+1), arrPt(intM, intN+1))
intCount = intCount + 1
ReDim Preserve arrLin(intCount): arrLin(intCount) = Rhino.AddLine (arrPt(intM+1, intN+1), arrPt(intM, intN))
intCount = intCount + 1
ElseIf (intM Mod 2 = 0) And (intN Mod 2 <> 0) Then
ReDim Preserve arrLin(intCount): arrLin(intCount) = Rhino.AddLine (arrPt(intM, intN), arrPt(intM, intN+1))
intCount = intCount + 1
ReDim Preserve arrLin(intCount): arrLin(intCount) = Rhino.AddLine (arrPt(intM, intN), arrPt(intM+1, intN+1))
intCount = intCount + 1
ReDim Preserve arrLin(intCount): arrLin(intCount) = Rhino.AddLine (arrPt(intM+1, intN+1), arrPt(intM+1, intN))
intCount = intCount + 1
ElseIf (intM Mod 2 <> 0) And (intN Mod 2 <> 0) Then
ReDim Preserve arrLin(intCount): arrLin(intCount) = Rhino.AddLine (arrPt(intM, intN), arrPt(intM+1, intN+1))
intCount = intCount + 1
End If
Next
Next

End Sub