Hexagonal Grid on Surface with varried UV Domain Divisions [Python Scripting]

#Generate Hexagonal Grid on surface With Varied UV Domain Divisions
#Jeremy Luebker 2013.04.10
#jluebker.wordpress.com (jeremy.luebker@gmail.com)
import rhinoscriptsyntax as rs

class HexGridOnSrf(object):

    def __init__(self,SRTSRF):
        self.StrSrf = SRTSRF


    def HexGrid(self):

        intU = 16
        intV = 32

        PtMtx = {}

        HexCrvsV1 = []
        HexCrvsV2 = []
        HexCrvsU = []

        #find surface domain
        UDomain = rs.SurfaceDomain(self.StrSrf, 0)
        VDomain = rs.SurfaceDomain(self.StrSrf, 1)

        #define steps
        UStep = (UDomain[1] - UDomain[0]) / intU
        VStep = (VDomain[1] - VDomain[0]) / intV

        print UDomain
        print VDomain
        print UStep, VStep

        #loop to plot points
        for i in range(intU + 1): #counting starts at 0 so need to add 1 to get last point of srf
            for j in range(intV + 1):

                #u = UDomain[0] + UStep * i
                #v = VDomain[0] + VStep * j
                u = UDomain[0] + UStep * i * i/16
                v = VDomain[0] + VStep * j * j/31.05

                #if u < UDomain[1]: #and v < VDomain[1]

                #evaluate surface
                PtMtx[(i,j)] =rs.EvaluateSurface(self.StrSrf, u, v)

                #plot points

                #### APPEND last edge crve of srf with divisions of last Vstep and append to dictionary

        for i in range(intU): 
            for j in range(intV):
                if j %3== 0:

                    HexCrvsV1.append(rs.AddLine(PtMtx[(i,j)], PtMtx[(i,j+1)]))

                    HexCrvsV2.append(rs.AddLine(PtMtx[(i+1,j)], PtMtx[(i+1,j+1)]))

                elif j %3== 1:
                    centPt2 = self.MidPt(PtMtx[(i,j)], PtMtx[(i+1,j+1)])
                    midPt2 = self.MidPt(PtMtx[(i,j+1)], PtMtx[(i+1,j+1)])

                    HexCrvsV1.append(rs.AddLine(PtMtx[(i,j)], centPt2))
                    #HexCrvsV1.append(rs.AddLine(centPt2, midPt2))

                    HexCrvsV2.append(rs.AddLine(PtMtx[(i+1,j)], centPt2))
                    #HexCrvsV2.append(rs.AddLine(centPt2, midPt2))

                    HexCrvsU.append(rs.AddLine(PtMtx[(i,j)], centPt2))
                    HexCrvsU.append(rs.AddLine(PtMtx[(i+1,j)], centPt2))

                elif j %3== 2:
                    centPt3 = self.MidPt(PtMtx[(i,j)], PtMtx[(i+1,j+1)])
                    midPt3 = self.MidPt(PtMtx[(i,j)], PtMtx[(i+1,j)])

                    HexCrvsV1.append(rs.AddLine(centPt2, centPt3))
                    #HexCrvsV1.append(rs.AddLine(midPt3, centPt3))
                    HexCrvsV1.append(rs.AddLine(centPt3, PtMtx[(i,j+1)]))

                    HexCrvsV2.append(rs.AddLine(centPt2, centPt3))
                    #HexCrvsV2.append(rs.AddLine(midPt3, centPt3))
                    HexCrvsV2.append(rs.AddLine(centPt3, PtMtx[(i+1,j+1)]))

                    HexCrvsU.append(rs.AddLine(centPt3, PtMtx[(i,j+1)]))
                    HexCrvsU.append(rs.AddLine(centPt3, PtMtx[(i+1,j+1)]))



    def MidPt(self, aP1, aP2):

        MidPt = None
        MidPt = [(aP1[0] + aP2[0]) / 2,
        (aP1[1] + aP2[1]) / 2,
        (aP1[2] + aP2[2]) / 2]
        return MidPt

def Main():

    #select surface
    strSrf = rs.GetObject('select surface', rs.filter.surface)

    #call function

if __name__=="__main__":

One thought on “Hexagonal Grid on Surface with varried UV Domain Divisions [Python Scripting]

  1. I just want to tell you that I’m beginner to weblog and absolutely savored your web page. Probably I’m going to bookmark your blog post . You amazingly come with incredible article content. Cheers for sharing with us your blog site.


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 )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s