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

## 25.5.09

Subscribe to:
Post Comments (Atom)

Alessandro,

ReplyDeleteyour approach to the hex patterning is quite interesting, please take some time to add explanations, since your code might not be clear to many readers (also a graphic scheme will be appreciated). Since this blog is a playground for mutual growth and experimentation let's try to share with care. ;-)

ok, I'll explain soon

ReplyDeleteok, now I think it's more clear. Please tell me about errors or inaccuracies.

ReplyDelete;-)

zompa

hmm... something's wrong with the diagram I guess... wether the dimensions or the proportions...

ReplyDeleteLet's presume, for example, that one of your hexagons in the grid can be inscribed in a circle of radius 1 (that will be the measure of any line from the center to one vertex of the hex). In this case the vertical dimension is correct, but not so the horizontal ones...

On the other side, if (as I guess from the script and the render) you put the correct dimensions the picture is misleading since you don't get regular honeycomb with that proportions. Not that you have to, but correct and precise explanations help you and others in checking if your process was rigorous or not and (most important) help you identify where things happen (in other words, for example, to giva an answer to the question: "why do I get stretched honeycomb here? Was that supposed to happen or just something unexpected?").

Cheers!

PS: please help me in enhancing aesthetically the word cloud in the upper right corner of the blog... use keywords when you post. (they also might help some reader in searching stuff...)

Alessandro! Oooops, my bad! Shame on me.... :-(

ReplyDeleteYour diagram is correct, please ignore my comment here above... I read 1*cos(60°) instead of 1+cos(60°) and accordingly 2*cos(60°) instead 2*(1+cos(60°)), that's why I was misled... sorry about that!

Don't worry... :-)

ReplyDeleteSoon I'll post my developments.

Great work Alessandro your approach for solving hexagonal tessellations is very interesting i´m going to translate this algorithm into grasshopper and add some functions to make apertures according a sunlight vector

ReplyDelete