A playground for University of Bologna Students and a 6-days seminar about digital tools.

Digital generative tools are a very important part of architectural education. Andrew Kudless during his conference at SimAE was telling about chinese traditional woodcraftsmen: they spend their first two years of apprentice in making their own tools. Today, we have a large pool of digital ready made tools, built to respond to more or less specific problems or tasks, while keeping a level of flexibility and personalization. The majority of these tools have hidden capabilities, which can only be accessed bypassing the conventional interface and getting close to the machine logic of programming or building parametric components which generate shapes. Thus, seriality, differentiation, complexity can be implemented in architectural projects through code, in order to exploit the power of algorithmic based complex systems which are the basis of biological systems.


But, before going through such complexity, we must start with simple tasks and simple rules. Before playing seriously we need practice. This is the playground where a bunch of students will start to practice, a pool where they will share their results and questions. Maybe the stuff here that will be posted will seem obvious or naive to the navigated code-monkey, but, as I mentioned before, we all start from the basics and this is intended as a place to start. However, any comment and contribution is appreciated.

Playground is open, let's play! _ Alessio

31.5.09

[Wip] Grasshopper definition in rose curvature way


This definition create a serie of soft curves, from rose curvatures, along a base curve, related with an analisys surface on top of all

I applied it to obtain a relationship between lines of force fields and the surface derivated from my ambiental analisys diagram

(img updated)

tensegrity - surfacex10




















While I am studying tensegrity structure for my thesis (http://en.wikipedia.org/wiki/Tensegrity), and building weird models like the one up here, I have written a simple script you can implement in my last post collection (just adding another "case" to the nine alredy there, so they are ten now!).
The scripts takes a surface and tesselates it with x-elements (I consider these as tensioned elements) and pipe elements (compressed ones). X-elements are scaled in proximity to an attractor point.
It is very simple so here it is



















' CASE 10 SURFSTARS
Sub surfstars(strsurf,upar,vpar)
upar = upar*5
vpar = vpar*5
Dim dblheight : dblheight = rhino.getreal("extrusion height?" ,.05)
If isnull (dblheight) Then Exit Sub
Dim attrpoint : attrpoint = rhino.getobject("point attractor",1)
Dim arrpoint : arrpoint = rhino.PointCoordinates(attrpoint)
Call rhino.enableredraw(False)
Dim i, j
Dim uvalone(1), uvaltwo
Dim arrUone, arrVone
Dim arrpttemp, pointtwo
Dim pt1, pt2, pt3, pt4, pt5, pt6, PT7, Pt8, pt5b, pt6b, pt7b, pt8b, ptc1, ptc2
ReDim matrix (upar, vpar)
Dim tempt
arruone = array (0,0)
arrVone = array (0,0)
Dim strcell, arrct, arrptsurf, arrnorm, arrnormend,arrnormenddown, arrline, strcell2
If rhino.IsSurface(strsurf) Then
arruone = rhino.surfacedomain(strsurf,0)
arrVone = rhino.surfacedomain(strsurf,1)
End If
For i=0 To upar
For j=0 To vpar
uvalone(0)= ((arruone(1)-arruone(0))/upar)*i
uvalone(1) = ((arrVone(1)-arrVone(0))/vpar)*j
arrpttemp = rhino.EvaluateSurface(strsurf,uvalone)
matrix(i,j) = arrpttemp
Next
Next
Dim oct1, oct2, oct3, oct4, arrlinehuge, arrel1, arrel2
Dim rn, crvtemp, dbldist

For i = 1 To upar-1
For J=0 To vpar-1
pt1 = matrix(i,j)
pt2 = matrix(i+1,j)
pt3 = matrix(i,j+1)
pt4 = matrix(i+1,j+1)
pt5 = array( (pt1(0)+pt2(0))/2,(pt1(1)+pt2(1))/2,(pt1(2)+pt2(2))/2)
pt6 = array( (pt2(0)+pt4(0))/2,(pt2(1)+pt4(1))/2,(pt2(2)+pt4(2))/2)
pt7 = array( (pt3(0)+pt4(0))/2,(pt3(1)+pt4(1))/2,(pt3(2)+pt4(2))/2)
pt8 = array( (pt1(0)+pt3(0))/2,(pt1(1)+pt3(1))/2,(pt1(2)+pt3(2))/2)
ptc1 = array( (pt5(0)+pt7(0))/2,(pt5(1)+pt7(1))/2,(pt5(2)+pt7(2))/2)
ptc2 = array( (pt6(0)+pt8(0))/2,(pt6(1)+pt8(1))/2,(pt6(2)+pt8(2))/2)
dbldist = rhino.Distance(ptc1,arrpoint)
dbldist = Rhino.Log10 (dbldist*7)
If dbldist<1.1 dbldist="">
pt5b = array( pt5(0)+(ptc1(0)-pt5(0))/(dbldist),pt5(1)+(ptc1(1)-pt5(1))/(dbldist),pt5(2)+(ptc1(2)-pt5(2))/(dbldist))
pt6b = array( pt6(0)+(ptc2(0)-pt6(0))/(dbldist),pt6(1)+(ptc2(1)-pt6(1))/(dbldist),pt6(2)+(ptc2(2)-pt6(2))/(dbldist))
pt7b = array( pt7(0)+(ptc1(0)-pt7(0))/(dbldist),pt7(1)+(ptc1(1)-pt7(1))/(dbldist),pt7(2)+(ptc1(2)-pt7(2))/(dbldist))
pt8b = array( pt8(0)+(ptc2(0)-pt8(0))/(dbldist),pt8(1)+(ptc2(1)-pt8(1))/(dbldist),pt8(2)+(ptc2(2)-pt8(2))/(dbldist))

Call rhino.AddCurve(array(pt1,pt2,pt4,pt3,pt1),1)
strcell = rhino.addcurve(array(pt1,,pt5b, pt2,pt6b, pt4, pt7b,pt3,pt8b,pt1),1)

arrct = array( (pt4(0)+pt1(0))/2,(pt4(1)+pt1(1))/2,(pt4(2)+pt1(2))/2)
arrptsurf = rhino.SurfaceClosestPoint(strsurf,arrct)
arrnorm = rhino.SurfaceNormal(strsurf,arrptsurf)
arrnorm = rhino.VectorScale(arrnorm, dblheight)
arrnormend = rhino.PointAdd(arrct,arrnorm)
arrnormenddown = rhino.Pointsubtract(arrct,arrnorm)
crvtemp = rhino.AddSrfPt(array(pt1,arrnormend,pt5b))
crvtemp = rhino.AddSrfPt(array(pt5b,arrnormend,pt2))
crvtemp = rhino.AddSrfPt(array(pt2,arrnormend,pt6b))
crvtemp = rhino.AddSrfPt(array(pt6b,arrnormend,pt4))
crvtemp = rhino.AddSrfPt(array(pt4,arrnormend,pt7b))
crvtemp = rhino.AddSrfPt(array(pt7b,arrnormend,pt3))
crvtemp = rhino.AddSrfPt(array(pt3,arrnormend,pt8b))
crvtemp = rhino.AddSrfPt(array(pt8b,arrnormend,pt1))

crvtemp = rhino.AddSrfPt(array(pt1,arrnormenddown,pt5b))
crvtemp = rhino.AddSrfPt(array(pt5b,arrnormenddown,pt2))
crvtemp = rhino.AddSrfPt(array(pt2,arrnormenddown,pt6b))
crvtemp = rhino.AddSrfPt(array(pt6b,arrnormenddown,pt4))
crvtemp = rhino.AddSrfPt(array(pt4,arrnormenddown,pt7b))
crvtemp = rhino.AddSrfPt(array(pt7b,arrnormenddown,pt3))
crvtemp = rhino.AddSrfPt(array(pt3,arrnormenddown,pt8b))
crvtemp = rhino.AddSrfPt(array(pt8b,arrnormenddown,pt1))
arrline = rhino.AddLine(pt1,pt2)
Call rhino.selectobject (arrline)
rhino.Command "_pipe " & ".02 " & ".02 " & " _enter " & " _enter "
rhino.UnselectAllObjects
arrline = rhino.AddLine(pt3,pt4)
Call rhino.selectobject (arrline)
rhino.Command "_pipe " & ".02 " & ".02 " & " _enter " & " _enter "
rhino.UnselectAllObjects
Next
Next


Call rhino.deleteobject(strsurf)
Call rhino.EnableRedraw(True)
End Sub


25.5.09

honeycumb

Hi guys! Before studying Vink's exeples about texturing I tryed to create an honeycumb surface. It is only a simple test and probably I didn't follow the better way for create an Hexagon grid. In future I'll optimize this, may be using rules like attractors or surface curvature...

(sorry for comments, but is only a draft, and coding is simple to understand)


[EDIT]

well, I modified the code revising some errors (like problems with closed surfaces, not completly solved). I also insert comments. I hope it's clear now... ;-)


[/EDIT]

[EDIT]

I also added a diagram for better explain meaning of formulas with sin() and cos() ;-)


[/EDIT]


Option Explicit
' Script written by Alessandro Zomparelli
' alessandro.zomparelli@gmail.com
' http://alessandrozompa.altervista.org/
' Script version sabato 9 maggio 2009 17.11.41

Call Main()
Sub Main()
Call Rhino.EnableRedraw(False)

Dim strSrf, u, v, arrParC, arrUdom, arrVdom, s, u1, v1
ReDim arrParC(1)
strSrf = Rhino.GetObject("pick target surface")
u1 = Rhino.GetInteger("number of U subdivision", 10, 2)
v1 = Rhino.GetInteger("number of V subdivision", 10, 2)

'we are trying to define a grid for drawing hexagons,
'For Do this we need to define the unit parameter to whom refer coordinates:
'For example I choose the radius of circle in whom hexagon is inscribed
'Now we evaluate the number of radius needed for drawing the choosen number of hexagons
v = v1*2*sin(ToRadians(60))
u = u1*(1+cos(ToRadians(60)))

'Here we ask to user the scale of holes
s = Rhino.GetReal("scale value for holes", 0.5, 0.1, 1)

arrUdom = Rhino.SurfaceDomain(strSrf, 0)
arrVdom = Rhino.SurfaceDomain(strSrf, 1)

Dim arrPts, i, j, arrPtsE, arrPtM
ReDim arrPts(3), arrPtsE(6), arrPtM(2)


'now I define the parameter to use for conversion from xy units to uv
Dim parU, parV
parU=(arrUdom(1)-arrUdom(0))/u
parV=(arrVdom(1)-arrVdom(0))/v

For i=0 To u1/2-1
For j=0 To v1-1

'center of hexagon A
arrParC(0) = 2*i*parU*(1+cos(ToRadians(60)))
arrParC(1) = j*parV*2*sin(ToRadians(60))

'drawing hexagon
Call Hexagon(strSrf, parU, parV, arrParC, arrPtsE)
'creating panels
Call Panel (strSrf, arrParC, arrPtsE, s)

'center of hexagon B
arrParC(0) = 2*(i+0.5)*parU*(1+cos(ToRadians(60)))
arrParC(1) = (j+0.5)*parV*2*sin(ToRadians(60))
'drawing hexagon
Call Hexagon(strSrf, parU, parV, arrParC, arrPtsE)
'creating panels
Call Panel (strSrf, arrParC, arrPtsE, s)
Next
Next
Call Rhino.DeleteObject(strSrf)
Call Rhino.EnableRedraw(True)

End Sub

Sub Hexagon (strSrf, parU, parV, arrParC, arrPtsE)
Dim i, strExa
ReDim arrPtsE(6)
For i=0 To 6
'coordinates of vertex related to local center
arrPtsE(i)=Rhino.EvaluateSurface(strSrf, array(arrParC(0)+cos(i*ToRadians(60))*parU,arrParC(1)+sin(i*ToRadians(60))*parV))
Next
End Sub

Sub Panel (strSrf, arrParC, arrPtsE, s)
Dim strExa, strIn, arrPtM, arrPlane
strExa=Rhino.AddPolyline(arrPtsE)
strIn=Rhino.AddPolyline(arrPtsE)
arrPlane=Rhino.SurfaceNormal(strSrf,arrParC)
If isnull (arrPlane) Then Exit Sub
arrPtM=Rhino.EvaluateSurface(strSrf,arrParC)
Call Rhino.ScaleObject(strIn, arrPtM, (array(s,s,s)))
Call Rhino.MoveObject(strIn,arrPlane)
Call Rhino.AddLoftSrf(array(strExa,strIn))
Call Rhino.DeleteObjects(array(strExa,strIn))
End Sub

14.5.09

The Grasshopper website!


Bob McNeel announced on the Grasshopper Google Group that the Official Grasshopper site has finally open! Downloads, tutorials, gallery, tips & tricks, videos... all in one place.

http://www.grasshopper3d.com/

Enjoy!

12.5.09

CHAPTER 1 - Textures














Once upon a time and a very good time it was there was a moocow coming down along the road and this moocow that was coming down along the road met a nicens little boy named baby tuckoo..

..by the way, after applying a lot on scripting I finally start making some render and put some
pieces together.
For this part I took inspiration from the book "Design and visual communication" written by Bruno Munari and his studies about textures (organic or geometric, how to treat a surface to make variations on it but preserving its uniformity, rarefaction and thickening
).
First of all I made two grids one with squares and one with triangles and three kind of modules (squares, circles, triangles) and their submodules (in geometric progression). Then I started trying "without thinking".
I also watched at some natural configurations and tried with them.









Then I selected some configurations and I tried to put them on a script.

For this part David Rutten and Theverymany examples were vital.

I thought that best way to deal with textures, their
rarefaction and thickening , was to make an application were you can build surfaces (based on based on z = f(x,y[,d,a]) equation) and decide dimension and number of subdivisions (but you can also select an existing surface).

[the only problem is that in this manner I have linked dimension and subdivision, if you want to split them you have firstly to generate the surface and then rerun the script only to tasselate it. But I'll fix it soon, so don't worry]

After that I grouped 9 kind of tesselation I have developed, more or less complex, you
just simple have to set the different parameter and see what you get. It is likely to view how texture changes when you increase o decrease one or both u-v params. And I found that sometimes textures have a good-looking backside lol..
Post it if something nice comes out!















Next step is to see how textures interact with both the surface they are subdividing and the environmental conditions (I tried something about differentiation, attractors, L-system, cellula automata), and also how do they organize in three-dimensional forms and structures... And also something architectural finally... See you soon then!

[p.s.Vray for rhino sucks!]

Option Explicit
' . Script written by Vincenzo Reale
' . univin@libero.it
'Script version sabato 11 maggio 2009 05.02.28

Call SurfacesEditor()

Sub SurfacesEditor()

Dim arrparam, arrresults, arrvalues
Dim strsurf
Dim arrchoose
arrchoose = (array("1° SURFHONEY","2° SURFHEXAGON", "3° SURFGRID","4° SURFRND","5° SURFBOX","6° SURFWAVES","7° SURFBOXHOLE","8° SURFPYRAMID","9° SURFCURVES"))
If isnull (arrchoose) Then Exit Sub

arrparam = array("create surfaces from equation? (Y/N)","equation surfaces z = f(x,y[,D,A])", "u subdivisions (>1)","v subdivisions (>1)")
arrvalues = array("Y","cos(sqr(x^2 + y^2))","5","5")
arrchoose = Rhino.ListBox (arrchoose, "choose!", "SURFACE")
arrresults = rhino.propertylistbox(arrparam, arrvalues,"Parameters","Vink's Surface Editor")

Dim upar, vpar
upar = CInt (formatnumber (arrresults(2)))
If isnull(upar) Then Exit Sub
vpar = CInt (formatnumber (arrresults(3)))
If isnull (vpar) Then Exit Sub

If isarray(arrresults) Then
Select Case Ucase (arrresults(0))
Case "Y"
strsurf = createsurface(arrresults(1), upar,vpar)
Case "N"
strsurf = rhino.getobject("Select surface to texturize",8+16+32,True,True)
End Select

Select Case Ucase (arrchoose)
Case "1° SURFHONEY"
Call surfhoney(strsurf,upar,vpar)
Case "2° SURFHEXAGON"
Call surfhexagon (strsurf,upar,vpar)
Case "3° SURFGRID"
Call surfgrid (strsurf,upar,vpar)
Case "4° SURFRND"
Call surfrnd(strsurf,upar,vpar)
Case "5° SURFBOX"
Call surfbox (strsurf,upar,vpar)
Case "6° SURFWAVES"
Call surfwaves (strsurf,upar,vpar)
Case "7° SURFBOXHOLE"
Call surfboxhole(strsurf,upar,vpar)
Case "8° SURFPYRAMID"
Call surfpyramid (strsurf,upar,vpar)
Case "9° SURFCURVES"
Call surfcurves(strsurf,upar,vpar)

End Select
End If

Call rhino.EnableRedraw(True)
End Sub
' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CREATE SURFACE -----

Function createsurface (streq, upar,vpar)
Dim arrCount(1), nCount, x, y, z
Dim intstart, intEnd
intstart = -5
intEnd = -5

arrCount(0) = upar
arrCount(1) = vpar

nCount = 0
Dim arrpoints()

For x = intstart To arrCount(0) + sgn(intstart) * (abs(intstart)+1)
For y = intend To arrCount(0) + sgn(intend) * (abs(intend)+1)
z = solveequation(streq,x,y)
ReDim Preserve arrpoints(ncount)
arrPoints(nCount) = Array(x, y, z )
nCount = nCount + 1
Next
Next

createsurface = Rhino.AddSrfPtGrid (arrCount, arrPoints)
Call rhino.EnableRedraw(True)

End Function

Function solveequation( ByVal strfunction, ByVal x, ByVal y)
Dim z
Dim D, A, Angledata

D = rhino.Hypot(x,y)
angleData= rhino.Angle(array(0,0,0), array(x,y,0))

' 0 The X,Y angle In degrees.
' 1 The elevation.
' 2 The delta In the X direction.
' 3 The delta In the Y direction.
' 4 The delta In the Z direction.

If isnull (angledata) Then
A = 0.0
Else
A = Rhino.ToRadians(Angledata(0)) 'l'angolo in coordinate polari

End If

On Error Resume Next
Execute("z =" & strfunction)

If err.number = 0 Then
solveequation = z
Else
solveequation = 0.0
End If

End Function
-----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 1 SURFHONEY -----

Sub surfhoney(strsurf,upar,vpar)
upar = upar*10
vpar = vpar*10
Dim dblheight : dblheight = rhino.getreal("extrusion height?" ,.3)
If isnull (dblheight) Then Exit Sub

Call rhino.enableredraw(False)
Dim i, j
Dim uvalone(1), uvaltwo
Dim arrUone, arrVone
Dim arrpttemp, pointtwo
Dim pt1, pt2, pt3, pt4, pt5, pt6
ReDim matrix (upar, vpar)
Dim tempt

arruone = array (0,0)
arrVone = array (0,0)
Dim strcell, arrct, arrptsurf, arrnorm, arrnormend, arrline, strcell2

If rhino.IsSurface(strsurf) Then
arruone = rhino.surfacedomain(strsurf,0)
arrVone = rhino.surfacedomain(strsurf,1)
End If

For i=0 To upar
For j=0 To vpar
uvalone(0)= ((arruone(1)-arruone(0))/upar)*i
uvalone(1) = ((arrVone(1)-arrVone(0))/vpar)*j
arrpttemp = rhino.EvaluateSurface(strsurf,uvalone)
matrix(i,j) = arrpttemp
Next
Next


Dim oct1, oct2, oct3, oct4, arrlinehuge, arrel1, arrel2
Dim rn


For i = 1 To upar-2 Step 4

For J=0 To vpar-2 Step 2
pt1 = matrix(i,j)
pt2 = matrix(i+1,j)
pt3 = matrix(i+2,j+1)
pt4 = matrix(i+1,j+2)
pt5 = matrix(i,j+2)
pt6 = matrix(i-1,j+1)
strcell = rhino.AddCurve(array(pt1,pt2,pt3,pt4,pt5,pt6,pt1),1)
arrct = array( (pt6(0)+pt3(0))/2,(pt6(1)+pt3(1))/2,(pt6(2)+pt3(2))/2)
arrptsurf = rhino.SurfaceClosestPoint(strsurf,arrct)
rn = rnd

strcell2 = rhino.ScaleObject(strcell,arrct,array(0.5,0.5,0.5),True)

arrnorm = rhino.SurfaceNormal(strsurf,arrptsurf)
arrnorm = rhino.VectorScale(arrnorm, dblheight)
arrnormend = rhino.PointAdd(arrct,arrnorm)
arrline = rhino.AddLine(arrct,arrnormend)


Call rhino.SelectObject (strcell)
rhino.Command("-patch " & "enter")
oct1=rhino.FirstObject
rhino.UnselectAllObjects

rhino.SelectObject (strcell2)
rhino.Command("-patch " & "enter")
oct2=rhino.FirstObject
rhino.UnselectAllObjects

oct3 = rhino.ExtrudeSurface(oct1,arrline)
arrlinehuge = rhino.ExtendCurveLength(arrline,0,1,40)
oct4 = rhino.ExtrudeSurface(oct2,arrlinehuge)


rhino.MoveObject oct4, arrnormend,arrct
arrel1 = (array(oct3))
arrel2 = (array(oct4))

rhino.BooleanDifference arrel1,arrel2

Call rhino.DeleteObject (arrline)
Call rhino.DeleteObject (oct1)
Call rhino.DeleteObject (oct2)

Next
Next

For i = 3 To upar-2 Step 4
For J=1 To vpar-2 Step 2
pt1 = matrix(i,j)
pt2 = matrix(i+1,j)
pt3 = matrix(i+2,j+1)
pt4 = matrix(i+1,j+2)
pt5 = matrix(i,j+2)
pt6 = matrix(i-1,j+1)
strcell = rhino.AddCurve(array(pt1,pt2,pt3,pt4,pt5,pt6,pt1),1)
arrct = array( (pt6(0)+pt3(0))/2,(pt6(1)+pt3(1))/2,(pt6(2)+pt3(2))/2)
arrptsurf = rhino.SurfaceClosestPoint(strsurf,arrct)
rn = rnd

strcell2 = rhino.ScaleObject(strcell,arrct,array(0.5,0.5,0.5),True)

arrnorm = rhino.SurfaceNormal(strsurf,arrptsurf)
arrnorm = rhino.VectorScale(arrnorm, dblheight)
arrnormend = rhino.PointAdd(arrct,arrnorm)
arrline = rhino.AddLine(arrct,arrnormend)


Call rhino.SelectObject (strcell)
rhino.Command("-patch " & "enter")
oct1=rhino.FirstObject
rhino.UnselectAllObjects

rhino.SelectObject (strcell2)
rhino.Command("-patch " & "enter")
oct2=rhino.FirstObject
rhino.UnselectAllObjects

oct3 = rhino.ExtrudeSurface(oct1,arrline)
arrlinehuge = rhino.ExtendCurveLength(arrline,0,1,40)
oct4 = rhino.ExtrudeSurface(oct2,arrlinehuge)


rhino.MoveObject oct4, arrnormend,arrct
arrel1 = (array(oct3))
arrel2 = (array(oct4))

rhino.BooleanDifference arrel1,arrel2

Call rhino.DeleteObject (arrline)
Call rhino.DeleteObject (oct1)
Call rhino.DeleteObject (oct2)
Next
Next

Call rhino.deleteobject(strsurf)
Call rhino.EnableRedraw(True)
End Sub
' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 2 SURFHEXAGON -----

Sub SURFHEXAGON(strsurf,Intuint,Intvint)

Dim dblheight : dblheight = rhino.getreal("extrusion height",.3)
Intuint = IntUint*20
Intvint = Intvint*20
Call rhino.EnableRedraw (False)

Dim arrUdom, arrVdom
arrUdom = Rhino.SurfaceDomain(strsurf,0)
arrVdom = Rhino.SurfaceDomain(strsurf,1)

Dim i, j
Dim arrPt, upar, vpar
ReDim arrPt(intUint-1 , intVint-1)
For i = 0 To Intuint-1
For j = 0 To intvint-1

upar = arrudom(0) + i*(arrudom(1)-arrudom(0))/(intuint-1)
vpar = arrudom(0) + j*(arrvdom(1)-arrvdom(0))/(intvint-1)
arrpt (i,j) = rhino.EvaluateSurface(strsurf,array(upar,vpar))

Next
Next


Dim arrpanel, arrpanel2
Dim strcurvepanel, strcurvepanel2
Dim arrsurfpanel,arrsurfpanel2
Dim strcut, arrCP, dbldist1, dblscale
For i = 6 To Intuint-6 Step 6

For j = 0 To intvint-6 Step 18

arrpanel = array (arrpt(i,j),arrpt(i+3,j+6), arrpt(i-3,j+6),arrpt(i,j))
arrsurfpanel = rhino.addsrfpt(arrpanel)

Next
Next

For i = 0 To Intuint-6 Step 6

For j = 0 To intvint-6 Step 18

arrpanel = array (arrpt(i,j),arrpt(i+6,j), arrpt(i+3,j+6),arrpt(i,j))
arrsurfpanel = rhino.addsrfpt(arrpanel)

Next
Next

For i = 3 To Intuint-6 Step 12

For j = 6 To intvint-6 Step 18

arrpanel = array (arrpt(i,j),arrpt(i+6,j), arrpt(i+3,j+6),arrpt(i,j))
arrsurfpanel = rhino.addsrfpt(arrpanel)

Next
Next
For i = 12 To Intuint-12 Step 12

For j = 0 To intvint-12 Step 18

arrpanel2 = array (arrpt(i,j),arrpt(i-3,j+6), arrpt(i+3,j+6),arrpt(i,j))
strcurvepanel2 = rhino.addcurve(arrpanel2,1)
arrsurfpanel2 = rhino.addsrfpt(arrpanel2)

Next
Next

For i = 6 To Intuint-12 Step 12

For j = 12 To intvint-12 Step 18
arrpanel2 = array (arrpt(i,j),arrpt(i-3,j+6), arrpt(i+3,j+6),arrpt(i,j))
strcurvepanel2 = rhino.addcurve(arrpanel2,1)
arrsurfpanel2 = rhino.addsrfpt(arrpanel2)

Next
Next

Dim arrstrcurvepanel(), k
k =0
For i = 9 To Intuint-9 Step 12
For j = 6 To intvint-12 Step 18
ReDim Preserve arrstrcurvepanel (k)
arrpanel = array (arrpt(i,j),arrpt(i+6,j), arrpt(i+9,j+6),arrpt(i+6,j+12), arrpt(i,j+12),arrpt(i,j+12),arrpt(i-3,j+6),arrpt(i,j))
arrstrcurvepanel(k) = rhino.addcurve(arrpanel,1)
Dim arrct
arrct = array( (arrpt(i-3,j+6)(0)+arrpt(i+9,j+6)(0))/2,(arrpt(i-3,j+6)(1)+arrpt(i+9,j+6)(1))/2,(arrpt(i-3,j+6)(2)+arrpt(i+9,j+6)(2))/2)
Dim arrptsurf
arrptsurf = rhino.SurfaceClosestPoint(strsurf,arrct)
Dim strcell2
strcell2 = rhino.ScaleObject(arrstrcurvepanel(k),arrct,array(0.3,0.3,0.3),True)
Dim arrnorm, arrnormend, arrline
arrnorm = rhino.SurfaceNormal(strsurf,arrptsurf)
arrnorm = rhino.VectorScale(arrnorm, dblheight)
arrnormend = rhino.PointAdd(arrct,arrnorm)
arrline = rhino.AddLine(arrct,arrnormend)

rhino.MoveObject strcell2, arrct, arrnormend
Call rhino.AddLoftSrf(array(arrstrcurvepanel(k),strcell2),,,,,,False)
Call rhino.deleteobject (arrline)
k = k+1
Next
Next

Call rhino.deleteobject(strsurf)
Call rhino.enableredraw(True)
End Sub
' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 3 SURFGRID -----

Sub surfgrid (strsurf,upar,vpar)

Dim radius : radius = rhino.getstring("pipe radius?" ,".1")
If isnull (radius) Then Exit Sub

Call rhino.enableredraw(False)
Dim i, j
Dim uvalone(1), uvaltwo
Dim arrUone, arrVone
Dim arrpttemp, pointtwo
Dim pt1, pt2, pt3, pt4
ReDim matrix (upar, vpar)
Dim tempt

arruone = array (0,0)
arrVone = array (0,0)

If rhino.IsSurface(strsurf) Then
arruone = rhino.surfacedomain(strsurf,0)
arrVone = rhino.surfacedomain(strsurf,1)
End If

For i=0 To upar
For j=0 To vpar
uvalone(0)= ((arruone(1)-arruone(0))/upar)*i
uvalone(1) = ((arrVone(1)-arrVone(0))/vpar)*j
arrpttemp = rhino.EvaluateSurface(strsurf,uvalone)
matrix(i,j) = arrpttemp
Next
Next

For i = 0 To upar-1

For J=0 To vpar-1
pt1 = matrix(i,j)
pt2 = matrix(i+1,j)
pt3 = matrix(i+1,j+1)
pt4 = matrix(i,j+1)

Call grid(pt1,pt2,pt3,pt4, radius)
Next
Next

Call rhino.deleteobject(strsurf)
Call rhino.EnableRedraw(True)
End Sub

Function grid(pt1,pt2,pt3,pt4,radius)



Dim lin12, lin23, lin34, lin41, lin13, lin24

lin12 = rhino.AddLine(pt1,pt2)
lin23 = rhino.AddLine(pt2, pt3)
lin34 = rhino.AddLine(pt3,pt4)
lin41 = rhino.AddLine(pt4, pt1)
lin13 = rhino.AddLine(pt1,pt3)
lin24 = rhino.AddLine(pt2, pt4)

Call rhino.selectobject (lin12)
rhino.Command "_pipe " & radius &" "& radius & " " & " _enter "
rhino.UnselectAllObjects

Call rhino.selectobject (lin23)
rhino.Command "_pipe " & ".1 " & ".1 " & " _enter " & " _enter "
rhino.UnselectAllObjects

Call rhino.selectobject (lin34)
rhino.Command "_pipe " & ".1 " & ".1 " & " _enter " & " _enter "
rhino.UnselectAllObjects

Call rhino.selectobject (lin41)
rhino.Command "_pipe " & ".1 " & ".1 " & " _enter " & " _enter "
rhino.UnselectAllObjects

Call rhino.selectobject (lin13)
rhino.Command "_pipe " & ".1 " & ".1 " & " _enter " & " _enter "
rhino.UnselectAllObjects

Call rhino.selectobject (lin24)
rhino.Command "_pipe " & ".1 " & ".1 " & " _enter " & " _enter "
rhino.UnselectAllObjects

End Function

' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 4 SURFRND -----

Sub surfrnd (strsurf,upar,vpar)

Dim dblheight : dblheight = rhino.getreal("elements height?" ,.3)

If isnull (dblheight) Then Exit Sub

Call rhino.enableredraw(False)
Dim i, j
Dim uvalone(1), uvaltwo
Dim arrUone, arrVone
Dim arrpttemp, pointtwo
Dim pt1, pt2, pt3, pt4, pt5, pt6
ReDim matrix (upar, vpar)
Dim tempt

arruone = array (0,0)
arrVone = array (0,0)
Dim strcell, arrct, arrptsurf, arrnorm, arrnormend, arrline, strcell2

If rhino.IsSurface(strsurf) Then
arruone = rhino.surfacedomain(strsurf,0)
arrVone = rhino.surfacedomain(strsurf,1)
End If

For i=0 To upar
For j=0 To vpar
uvalone(0)= ((arruone(1)-arruone(0))/upar)*i
uvalone(1) = ((arrVone(1)-arrVone(0))/vpar)*j
arrpttemp = rhino.EvaluateSurface(strsurf,uvalone)
matrix(i,j) = arrpttemp
Next
Next


Dim strcell3, strcell4

Dim rn


For i = 1 To upar-2 Step 4

For J=0 To vpar-2 Step 2
pt1 = matrix(i,j)
pt2 = matrix(i+1,j)
pt3 = matrix(i+2,j+1)
pt4 = matrix(i+1,j+2)
pt5 = matrix(i,j+2)
pt6 = matrix(i-1,j+1)

strcell = rhino.AddCurve(array(pt1,pt2,pt3,pt4,pt5,pt6,pt1),2)
arrct = array( (pt6(0)+pt3(0))/2,(pt6(1)+pt3(1))/2,(pt6(2)+pt3(2))/2)
arrptsurf = rhino.SurfaceClosestPoint(strsurf,arrct)
rn = rnd

strcell2 = rhino.ScaleObject(strcell,arrct,array(rn*0.7,rn*0.7,rn*0.7),True)

arrnorm = rhino.SurfaceNormal(strsurf,arrptsurf)
arrnorm = rhino.VectorScale(arrnorm, dblheight)
arrnormend = rhino.PointAdd(arrct,arrnorm)
arrline = rhino.AddLine(arrct,arrnormend)

rn = rnd
strcell3 = rhino.ScaleObject(strcell,arrct,array(rn*0.5,rn*0.5,rn*0.5),True)
strcell4 = rhino.ScaleObject(strcell,arrct,array(0.8,0.8,0.8),True)

rhino.MoveObject strcell3, arrct, arrnormend
rhino.MoveObject strcell4, arrct, arrnormend

Call rhino.AddLoftSrf(array(strcell,strcell2,strcell3,strcell4),,,,,,True)


Call rhino.DeleteObject (arrline)
Call rhino.DeleteObjects (array(strcell,strcell2,strcell3,strcell4))

Next
Next

For i = 3 To upar-2 Step 4
For J=1 To vpar-2 Step 2
pt1 = matrix(i,j)
pt2 = matrix(i+1,j)
pt3 = matrix(i+2,j+1)
pt4 = matrix(i+1,j+2)
pt5 = matrix(i,j+2)
pt6 = matrix(i-1,j+1)

strcell = rhino.AddCurve(array(pt1,pt2,pt3,pt4,pt5,pt6,pt1),2)
arrct = array( (pt6(0)+pt3(0))/2,(pt6(1)+pt3(1))/2,(pt6(2)+pt3(2))/2)
arrptsurf = rhino.SurfaceClosestPoint(strsurf,arrct)
rn = rnd

strcell2 = rhino.ScaleObject(strcell,arrct,array(rn*0.8,rn*0.8,rn*0.8),True)

arrnorm = rhino.SurfaceNormal(strsurf,arrptsurf)
arrnorm = rhino.VectorScale(arrnorm, dblheight)
arrnormend = rhino.PointAdd(arrct,arrnorm)
arrline = rhino.AddLine(arrct,arrnormend)
rn=rnd

strcell3 = rhino.ScaleObject(strcell,arrct,array(rn*0.8,rn*0.8,rn*0.8),True)
strcell4 = rhino.ScaleObject(strcell,arrct,array(0.9,0.9,0.9),True)

rhino.MoveObject strcell3, arrct, arrnormend
rhino.MoveObject strcell4, arrct, arrnormend

Call rhino.AddLoftSrf(array(strcell,strcell2,strcell3,strcell4),,,,,,True)


Call rhino.DeleteObject (arrline)
Call rhino.DeleteObjects (array(strcell,strcell2,strcell3,strcell4))

Next
Next

Call rhino.deleteobject(strsurf)
Call rhino.EnableRedraw(True)
End Sub
' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 5 SURFBOX -----

Sub surfbox(strsurf,upar,vpar)

Call rhino.enableredraw(False)

Dim intposition: intposition = rhino.getreal ("maximum interposition?",0.4,0)
Dim intheight: intheight = rhino.getreal("maximum height?",0.6,0)

Dim i,j
Dim uvalone(1),uvaltwo
Dim arrudom, arrvdom
Dim arrpttemp, pointtwo
Dim pt1, pt2, pt3, pt4
Dim arrpts: arrpts = array(pt1,pt2,pt3,pt4)
ReDim arrpts (upar,vpar)
Dim temppt
arrudom = array(0,0)
arrvdom = array (0,0)

arrudom = rhino.SurfaceDomain(strsurf,0)
arrvdom = rhino.surfacedomain (strsurf,1)

For i = 0 To upar
For j= 0 To vpar
uvalone(0) = ((arrudom(1)-arrudom(0))/upar)*i
uvalone(1) = ((arrvdom(1)-arrvdom(0))/vpar) * (j)
arrpttemp = rhino.EvaluateSurface(strsurf, uvalone)
arrpts(i,j) = arrpttemp
Next
Next

For i = 0 To upar-1
For j=0 To vpar -1
pt1 = arrpts(i,j)
pt2 = arrpts(i+1,j)
pt3 = arrpts(i+1,j+1)
pt4 = arrpts (i,j+1)
Call boxes(pt1,pt2,pt3,pt4,intposition,intheight)

Next
Next

Call rhino.DeleteObject (strsurf)

Call rhino.enableredraw(True)

End Sub

Function boxes (pt1,pt2,pt3,pt4,intposition,intheight)
Dim tempsrf, arrdomainU, arrdomainv, arrdirection
Dim arrparam(1), arrnormal, linenormalsmall, linenormalbig, pt5
Dim linep1p4, linep1p4extend, linearray, linep1p2, linep1p4norm,linep1p2extend
Dim vertsurface1,vertsurface2, arrptdomain,arrptparam,pt6

tempsrf = rhino.AddSrfPt(array(pt1,pt2,pt3,pt4))

arrdomainU = rhino.surfacedomain(tempsrf,0)
arrdomainV = rhino.surfacedomain(tempsrf,1)
arrparam(0) = (arrdomainU(1)-arrdomainu(0))/2
arrparam(1) = (arrdomainV(1)-arrdomainV(0))/2
pt5 = rhino.EvaluateSurface(tempsrf, arrparam)


arrnormal = rhino.surfacenormal(tempsrf, arrparam)

Dim vector
vector = rhino.PointAdd(pt5,arrnormal)
linenormalsmall = rhino.AddLine(pt5, Rhino.VectorAdd(pt5,arrnormal))
linenormalbig = rhino.ExtendCurveLength(linenormalsmall, 0,1,intheight*rnd)

arrptdomain = rhino.CurveDomain(linenormalbig)
arrptparam = arrptdomain(1)
pt6 = rhino.EvaluateCurve(linenormalbig,arrptparam)


linep1p4 = rhino.AddLine(pt1,pt4)
linep1p2 = rhino.AddLine(pt1,pt2)
linep1p4norm = rhino.CopyObject(linep1p4,pt5,pt6)
linep1p4extend = rhino.ExtendCurveLength(linep1p4, 0,1,intposition)
linep1p2extend = rhino.ExtendCurveLength(linep1p2, 0,1,intposition)
linearray= (array(linep1p4extend,linep1p4norm))
vertsurface1 =rhino.AddEdgeSrf(linearray)
vertsurface2 = rhino.ExtrudeSurface(vertsurface1,linep1p2extend)

Call rhino.DeleteObject(tempsrf)
Call rhino.DeleteObjects(array(linep1p4norm,linep1p2extend,linep1p4extend,linep1p2,linep1p4))
rhino.UnselectAllObjects

End Function
' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 9 SURFCURVES -----

Sub SURFCURVES(strsurf,upar,vpar)

Dim U,v, i,j,arrparam(1),arrpoint
Dim arrparamnormal, arrnormal, linenorm
Dim interpcurve
Dim strsurfloft, strinterpcurve, strinterpcurveonsurf, intheight, intloftfreq, intlofttype
Dim arrinterpcurve


upar = upar -1
vpar = vpar -1
intheight = rhino.getreal("maximum height?",1)
If isnull(intheight) Then Exit Sub
intloftfreq = rhino.getinteger("loft frequence?",2,2)
If intloftfreq < intlofttype =" rhino.getreal(">4 Then Exit Sub
intlofttype = intlofttype -1


U = rhino.SurfaceDomain(strsurf,0)
v = rhino.surfacedomain (strsurf,1)
If Not isarray(U) Or Not isarray (v) Then Exit Sub


For i = 0 To upar
arrparam(0) = u (0) + (((u(1)-u(0))/upar)*i)

For j = 0 To vpar
arrparam(1) = v (0) + (((v(1)-v(0))/vpar)*j)
arrpoint = rhino.evaluatesurface(strsurf,arrparam)
arrparamnormal = rhino.surfaceclosestpoint(strsurf,arrpoint)
arrnormal = rhino.surfacenormal(strsurf, arrparamnormal)
arrnormal = rhino.VectorScale(arrnormal,intheight)

Dim arrnvect
arrnvect = rhino.pointAdd(arrpoint,arrnormal)
' linenorm = rhino.AddLine(arrpoint,arrnvect)
' Call rhino.ObjectColor(linenorm,rgb(255,0,255))

ReDim Preserve arrnormptssurf(vpar)
arrnormptssurf(j)=arrpoint
ReDim Preserve arrnormptsEnd(vpar)
If i = 0 And i = upar And j=0 And j=vpar Then
arrnormptsEnd(j) = arrpoint
Else
arrnormptsEnd (j) = arrnvect
End If

Dim intcrossnpts: intcrossnpts = 2
Dim intstripefreq: intstripefreq = i+1
ReDim Preserve arrptwave(vpar)
Dim strWAVE
ReDim Preserve arrptwaveud(vpar)
Dim strwaveud

If intstripefreq Mod 2 Then
If intstripefreq <> 1 Then
If j Mod intcrossnpts Then

arrptwave(j) = arrnormptssurf(j)
arrptwaveud(j) = arrnormptssurf(j)
Else

arrptwave(j) = arrnormptssurfPr(j)
arrptwaveud(j) = arrnormptsEnd(j)
End If
If j = vpar Then

strWAVE = Rhino.AddInterpCrvOnSrf (strsurf,arrptwave)
strwaveud = Rhino.AddInterpCurve (arrptwaveud, 3)

arrInterpCurve = array(strWAVEp(i-1), strwaveudpr(i-1), strWAVE)
strsurfLoft = Rhino.AddLoftSrf (arrInterpCurve, , ,intLoftType,1,100, False)
Call Rhino.SurfaceIsocurveDensity (strsurfLoft, -1)
End If
End If
Else
If j Mod intcrossnpts Then
arrptwave(j) = arrnormptssurfPr(j)
arrptwaveud(j) = arrnormptsEnd(j)
Else
arrptwave(j) = arrnormptssurf(j)
arrptwaveud(j) = arrnormptssurf(j)
End If
If j = vpar Then
strWAVE = Rhino.AddInterpCrvOnSrf (strsurf,arrptwave)
strwaveud = Rhino.AddInterpCurve (arrptwaveud, 3)
If i>1 Then
arrInterpCurve = array(strWAVEp(i-1), strwaveudpr(i-1), strWAVE)
strsurfLoft = Rhino.AddLoftSrf (arrInterpCurve, , ,intLoftType,1,100, False)
Rhino.SurfaceIsocurveDensity strsurfLoft, -1


End If
End If

End If
ReDim Preserve strWAVEp(upar)
strWAVEp(i) = strWAVE
ReDim Preserve strwaveudpr(upar)
strwaveudpr(i) = strwaveud
ReDim Preserve arrnormptssurfPr(vpar)
arrnormptssurfPr(j) = arrnormptssurf(j)
ReDim Preserve arrnormptsEndpr(vpar)
arrnormptsEndpr(j) = arrnormptsEnd(j)


Next

Next

Call rhino.deleteobject (strsurf)


End Sub

' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 7 SURFBOXHOLE -----

Sub surfboxhole(strsurf,upar,vpar)
Call rhino.enableredraw(False)
Dim intposition: intposition = rhino.getreal ("maximum interposition?",0.05,0)
Dim intheight: intheight = rhino.getreal("maximum height?",0.4,0)

Dim i,j
Dim uvalone(1),uvaltwo
Dim arrudom, arrvdom
Dim arrpttemp, pointtwo
Dim pt1, pt2, pt3, pt4
Dim arrpts: arrpts = array(pt1,pt2,pt3,pt4)
ReDim arrpts (upar,vpar)
Dim temppt
arrudom = array(0,0)
arrvdom = array (0,0)

arrudom = rhino.SurfaceDomain(strsurf,0)
arrvdom = rhino.surfacedomain (strsurf,1)

For i = 0 To upar
For j= 0 To vpar
uvalone(0) = ((arrudom(1)-arrudom(0))/upar)*i
uvalone(1) = ((arrvdom(1)-arrvdom(0))/vpar) * (j)
arrpttemp = rhino.EvaluateSurface(strsurf, uvalone)
arrpts(i,j) = arrpttemp
Next
Next

For i = 0 To upar-1
For j=0 To vpar -1
pt1 = arrpts(i,j)
pt2 = arrpts(i+1,j)
pt3 = arrpts(i+1,j+1)
pt4 = arrpts (i,j+1)
Call drawbox2(pt1,pt2,pt3,pt4,intposition,intheight)

Next
Next

Call rhino.DeleteObject (strsurf)

Call rhino.enableredraw(True)

End Sub

Function drawbox2(pt1,pt2,pt3,pt4,intposition,intheight)
Dim tempsrf, arrdomainU, arrdomainv, arrdirection
Dim arrparam(1), arrnormal, linenormalsmall, linenormalbig, pt5
Dim linep1p4, linep1p4extend, linearray, linep1p2, linep1p4norm,linep1p2extend
Dim vertsurface1,vertsurface2, arrptdomain,arrptparam,pt6

tempsrf = rhino.AddSrfPt(array(pt1,pt2,pt3,pt4))

arrdomainU = rhino.surfacedomain(tempsrf,0)
arrdomainV = rhino.surfacedomain(tempsrf,1)
arrparam(0) = (arrdomainU(1)-arrdomainu(0))/2
arrparam(1) = (arrdomainV(1)-arrdomainV(0))/2
pt5 = rhino.EvaluateSurface(tempsrf, arrparam)


arrnormal = rhino.surfacenormal(tempsrf, arrparam)

Dim vector
vector = rhino.PointAdd(pt5,arrnormal)
linenormalsmall = rhino.AddLine(pt5, Rhino.VectorAdd(pt5,arrnormal))
linenormalbig = rhino.ExtendCurveLength(linenormalsmall, 0,1,intheight*rnd)

arrptdomain = rhino.CurveDomain(linenormalbig)
arrptparam = arrptdomain(1)
pt6 = rhino.EvaluateCurve(linenormalbig,arrptparam)


linep1p4 = rhino.AddLine(pt1,pt4)
linep1p2 = rhino.AddLine(pt1,pt2)
linep1p4norm = rhino.CopyObject(linep1p4,pt5,pt6)
linep1p4extend = rhino.ExtendCurveLength(linep1p4, 0,1,intposition)
linep1p2extend = rhino.ExtendCurveLength(linep1p2, 0,1,intposition)
linearray= (array(linep1p4extend,linep1p4norm))
vertsurface1 =rhino.AddEdgeSrf(linearray)
vertsurface2 = rhino.ExtrudeSurface(vertsurface1,linep1p2extend)

Dim linenormhuge
linenormhuge = rhino.ExtendCurveLength(linenormalsmall,0,1,40)
Dim ellipse1
ellipse1 = rhino.AddCurve(array(pt1,pt2,pt3,pt4,pt1))

rhino.SelectObject ellipse1
rhino.Command("-patch " & "enter")

Dim ellipse2

ellipse2=rhino.FirstObject

Dim ellipse3

ellipse3 = rhino.ExtrudeSurface(ellipse2,linenormhuge)

rhino.MoveObject ellipse3, pt6,pt5

Dim arrellipse, arrtrapezoid
arrellipse = (array(ellipse3))
arrtrapezoid = (array(vertsurface2))
rhino.BooleanDifference arrtrapezoid,arrellipse

Call rhino.DeleteObject(tempsrf)
Call rhino.DeleteObject(ellipse2)
Call rhino.DeleteObject(linenormhuge)
Call rhino.DeleteObjects(array(linep1p4norm,linep1p2extend,linep1p4extend,linep1p2,linep1p4))
rhino.UnselectAllObjects

End Function
' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 8 SURFPYRAMID -----

Sub Surfpyramid(strsurf,upar,vpar)
Dim intheight: intheight = rhino.getreal("maximum height?",0.4,0)
Call rhino.enableredraw(False)

Dim i, j
Dim uvalone(1), uvaltwo
Dim arrudom, arrvdom
Dim arrpttemp, pointtwo
Dim pt1, pt2, pt3, pt4

Dim arrpts()
ReDim arrpts (upar, vpar)

arrudom = array(0,0)
arrvdom= array(0,0)

If rhino.IsSurface(strsurf) Then
arrudom = rhino.SurfaceDomain(strsurf, 0)
arrvdom = rhino.SurfaceDomain(strsurf, 1)

End If

For i=0 To upar
For j=0 To vpar
uvalone(0) = ((arrudom(1)-arrudom(0))/upar)*i
uvalone(1) = ((arrvdom(1)-arrvdom(0))/vpar)*j

arrpttemp = rhino.EvaluateSurface(strsurf,uvalone)
arrpts(i,j) = arrpttemp
Next
Next

For i =0 To upar-1
For j=0 To vpar-1
pt1 = arrpts (i,j)
pt2 = arrpts (i+1,j)
pt3 = arrpts (i+1,j+1)
pt4 = arrpts (i,j+1) 'rettangoli di base

Call pyramid (pt1,pt2,pt3,pt4,intheight)
Next

Next

Call rhino.EnableRedraw(True)
Call rhino.deleteobject (strsurf)

End Sub

Function pyramid(pt1,pt2,pt3,pt4,intheight)
Dim tempsrf, arrdomainU, arrdomainV, arrdirection
Dim arrparam(1), arrnormal, linenormalsmall, linenormalbig, arrptdomain, arrptparam
Dim pt5, pt6
Dim sideone, sidetwo, sidethree, sidefour
tempsrf = rhino.addsrfpt (array(pt1,pt2,pt3,pt4))

arrdomainU = rhino.SurfaceDomain(tempsrf,0)
arrdomainv= rhino.SurfaceDomain(tempsrf,1)
arrparam(0) = (arrdomainU(1)-arrdomainU(0))/2
arrparam(1) = (arrdomainv(1)-arrdomainV(0))/2
pt5 = rhino.EvaluateSurface(tempsrf, arrparam)

arrnormal = rhino.surfacenormal (tempsrf, arrparam)

Dim vector
vector = rhino.PointAdd(pt5,arrnormal)
linenormalsmall = rhino.AddLine(pt5, Rhino.VectorAdd(pt5,arrnormal))
linenormalbig = rhino.ExtendCurveLength(linenormalsmall, 0,1,intheight)'maybe rnd*height

rhino.selectobject (tempsrf)
rhino.Command "flip"
arrnormal = rhino.SurfaceNormal(tempsrf, arrparam)
vector = rhino.PointAdd(pt5,arrnormal)
linenormalsmall = rhino.AddLine(pt5, Rhino.VectorAdd(pt5,arrnormal))
'rhino.ExtrudeSurface tempsrf, linenormalsmall
arrptdomain = rhino.curvedomain(linenormalbig)
arrptparam = arrptdomain(1)
pt6 = rhino.EvaluateCurve(linenormalbig, arrptparam)

sideone = rhino.AddSrfPt (array(pt1,pt2,pt6))
sideone = rhino.AddSrfPt (array(pt2,pt3,pt6))
sideone = rhino.AddSrfPt (array(pt3,pt4,pt6))
sideone = rhino.AddSrfPt (array(pt4,pt1,pt6))

Call rhino.deleteobject(linenormalsmall)
Call rhino.deleteobject (linenormalbig)

End Function

' -----------------------------------------------------------------------------------------------------------------------------------------
'----- CASE 6 SURFWAVES -----

Sub Surfwaves (strsurf, nrows, ncolumns)
Dim u, v, i,j, arrparam(1), arrpoint
Dim arrparamnormal, arrnormal, normal, deltaheight
Dim vector, arrnormalnew
Dim strinterpcurve, strinterpcurveonsurf
Dim strsurfloft

nrows = nrows -1
ncolumns = ncolumns -1

deltaheight = rhino.GetReal("wave height?",5,1)
Call rhino.enableredraw(False)


U = RHino.SurfaceDomain(strsurf,0)
v = rhino.surfacedomain(strsurf,1)

If Not isarray(u) Or Not isarray(V) Then Exit Sub

For i = 0 To nrows
arrparam(0) = U(0) + ((U(1)-u(0))/nrows)*i

For j= 0 To ncolumns
arrparam(1) = V(0) + ((V(1)-V(0))/ncolumns)*j
arrpoint = rhino.evaluatesurface(strsurf, arrparam)

arrparamnormal = rhino.SurfaceNormal(strsurf,arrparam)
arrparamnormal= rhino.vectorscale(arrparamnormal, CDbl(deltaheight))
vector = rhino.PointAdd(arrpoint,arrparamnormal)
normal = rhino.AddLine(arrpoint, vector)

ReDim Preserve arrnormalendcollection(ncolumns)
If j = 0 And j = ncolumns Then
arrnormalendcollection(j)=arrpoint
Else
arrnormalendcollection(j) = vector
End If

ReDim Preserve arrnormaloriginecollection(ncolumns)
arrnormaloriginecollection(j) = arrpoint

Call rhino.deleteobject (normal)

Next


ReDim Preserve arrInterpcurve(nrows)
If i Mod 2 Then
arrinterpcurve(i) = rhino.addinterpcurve(arrnormalendcollection)
Else
arrinterpcurve(i) = rhino.AddInterpCrvOnSrf(strsurf,arrnormaloriginecollection)
End If

Next

strsurfloft = rhino.AddLoftSrf(arrinterpcurve, , ,3,1,100)
rhino.SurfaceIsocurveDensity strsurfloft, -1
rhino.ObjectColor strsurfloft, rgb(255,0,255)

Call rhino.DeleteObjects (arrinterpcurve)
Call rhino.deleteobject (strsurf)
Call rhino.deleteobjects (vector)
Call rhino.EnableRedraw(True)

End Sub

2.5.09

Interpolation function

In a discussion on the Grasshopper Google Group, David Rutten (btw... whenever you read, hear or pronounce this name please join hands as in prayer and say "Thank you, Zen master!"), as I said, David Rutten (repeat) has posted a useful and easy to implement function for interpolation. Here's the text extracted from the discussion:

there's a good function that always works when interpolating linearly between two tensors (be they numbers, vectors, points... any kind of data that can be blended).

If you have 2 values (A & B) and you want to interpolate between them at f (a blending factor), the function is always:

R = A + f * (B-A)

For example, let's fill in a few numbers and see what happens... Let's assume we want to find the value one quarter along the way between 15 and 19:

R = 15 + 0.25 * (19-15)
R = 16

Or, let's go twice beyond two points {10, 10, 0} and {12, 15, 4}

R = {10, 10, 0} + 2.0 * ({12, 15, 4} - {10, 10, 0})
R = {10, 10, 0} + 2.0 * ({2, 5, 4}) <---- if you subtract two points you get the vector going from A to B R = {10, 10, 0} + {4, 10, 8} R = {14, 20, 8}

This function is handy because it works without division (no division by zero errors), it works well when A is larger than B and it works for every value of f (i.e. you can also use it to extrapolate).

Well, nothing really new to those of you guys who followed the seminar, we talked and applied a lot of interpolations as a basic task of implementing gradients at different levels of discretization, but I think Rutten explains it very straightforward so it might be useful to have it as a reminder. Now go and apply it to any attractor/repellor/blend case you might undergo from now on.