Monday, 19 November 2007

071120_Surface Tassellation



The surface is subdivided following UV coordinates; the logic of the script is, effectively, mapping the curvature of the surface; whereas the surface is flat and homogeneous the subdivision grid is large; where the surface curvature is steeper the subdivision gets further partitioned. It would be Interesting to see whether there is a correlation between scripting logic and structural logic. Undoubtedly the presence of the circles helps to stiffen the linear structural grid.






































I apologize for the guilt delay in posting. Well, I've been spending some time practicing with Rhinoscript and trying to develop some meaningful results.

The script develops a surface tessellation exercise where components are distributed along the surface: this is a recursive script where the surface is subdivided according to its degree of curvature. In this manner smaller components are allocated where curvature is steeper, bigger ones where the curvature is rather flat.
More to come...


Option Explicit

Call Main()
Sub Main()
Dim idSrf : idSrf = Rhino.GetObject("Surface to recurse", 8, True, True)
If IsNull(idSrf) Then Exit Sub

Dim uDomain : uDomain = Rhino.SurfaceDomain(idSrf, 0)
Dim vDomain : vDomain = Rhino.SurfaceDomain(idSrf, 1)

Call RecurseSurface(idSrf, uDomain(0), uDomain(1), vDomain(0), vDomain(1))
End Sub

Function RecurseSurface(ByVal idSrf, ByVal u0, ByVal u1, ByVal v0, ByVal v1)
Dim um : um = u0 + 0.5 * (u1-u0)
Dim vm : vm = v0 + 0.5 * (v1-v0)

Dim A : A = Rhino.EvaluateSurface(idSrf, Array(u0, v0))
Dim B : B = Rhino.EvaluateSurface(idSrf, Array(u1, v0))
Dim C : C = Rhino.EvaluateSurface(idSrf, Array(u1, v1))
Dim D : D = Rhino.EvaluateSurface(idSrf, Array(u0, v1))
Dim E : E = Rhino.EvaluateSurface(idSrf, Array(um, vm))
Dim M(2)
m(0) = (A(0) + C(0))/2
m(1) = (A(1) + C(1))/2
m(2) = (A(2) + C(2))/2
Dim N(2)
n(0) = (D(0) + B(0))/2
n(1) = (D(1) + B(1))/2
n(2) = (D(2) + B(2))/2

If (rhino.Distance(E, M) < 0.5) And (rhino.Distance(E, N) < 0.5) Then
Call ExtrudeDomain (idSrf, u0, u1, v0, v1)
Else
Call RecurseSurface(idSrf, u0, um, v0, vm)
Call RecurseSurface(idSrf, um, u1, v0, vm)
Call RecurseSurface(idSrf, u0, um, vm, v1)
Call RecurseSurface(idSrf, um, u1, vm, v1)
End If
End Function

Sub ExtrudeDomain(ByVal idSrf, ByVal u0, ByVal u1, ByVal v0, ByVal v1)
Dim A : A = Rhino.EvaluateSurface(idSrf, Array(u0, v0))
Dim B : B = Rhino.EvaluateSurface(idSrf, Array(u1, v0))
Dim C : C = Rhino.EvaluateSurface(idSrf, Array(u1, v1))
Dim D : D = Rhino.EvaluateSurface(idSrf, Array(u0, v1))

Dim Na : Na = Rhino.SurfaceNormal(idSrf, Array(u0, v0))
Dim Nb : Nb = Rhino.SurfaceNormal(idSrf, Array(u1, v0))
Dim Nc : Nc = Rhino.SurfaceNormal(idSrf, Array(u1, v1))
Dim Nd : Nd = Rhino.SurfaceNormal(idSrf, Array(u0, v1))

Dim E : E = Rhino.vectoradd(A, Na)
Dim F : F = Rhino.vectoradd(B, Nb)
Dim G : G = Rhino.vectoradd(C, Nc)
Dim H : H = Rhino.vectoradd(D, Nd)

Dim idBase, idTop
idBase = Rhino.AddCurve(Array(A, B, C, D, A), 1)
idTop = Rhino.AddCurve(Array(E, F, G, H, E), 1)

Call Rhino.AddLoftSrf(Array(idBase, idTop))
Call Rhino.DeleteObject (idBase)
Call Rhino.DeleteObject (idTop)
End Sub



(developed in collaboration with eng. C.Diaco; special thanks to David Rutten.)