Tuesday, April 24, 2012

Hexagon Offset W/ Pyramid between


Probably a much simpler way to do this but it worked...

import rhinoscriptsyntax as rs
import random
import math


def cenPt(_ptL):
    ptL = _ptL
    xL = []
    yL = []
    zL = []
    for i in range (0,len(ptL)):
#        pt = rs.PointCoordinates(ptL[i])
        Xval = ptL[i][0]
        xL.append(Xval)
        Yval = ptL[i][1]
        yL.append(Yval)
        Zval = ptL[i][2]
        zL.append(Zval)
    cenPt = rs.AddPoint([math.fsum(xL)/len(xL),math.fsum(yL)/len(yL),math.fsum(zL)/len(zL)])
    return cenPt

srf = rs.GetObject('select surface',8)
uDom = rs.SurfaceDomain(srf,0)
vDom = rs.SurfaceDomain(srf,1)

uDivide = 30
vDivide = 30

Ustep = (uDom[1]-uDom[0])/int(uDivide)
Vstep = (vDom[1]-vDom[0])/int(vDivide)
rs.EnableRedraw(False)
ptL = []
normalList = []
rowList = []
vectorScale = 10
for i in rs.frange(uDom[0],uDom[1],Ustep):
    colList = []
    tempNorm = []
    for j in rs.frange(vDom[0],vDom[1]+Vstep,Vstep):
        eval = rs.EvaluateSurface(srf,i,j)
        colList.append(eval)
        normal = rs.SurfaceNormal(srf,(i,j))
        normal = rs.VectorUnitize(normal)
        normal = rs.VectorScale(normal,vectorScale)
        normPt = rs.VectorAdd(eval,normal)
        tempNorm.append(normPt)
    normalList.append(tempNorm)
    rowList.append(colList)

row1Cen = []
row1Hex = []

for i in range (0,len(rowList)-3,4):
    for j in range (0,len(rowList[i])-2,2):
        tempHex = []
        tempHex.append((rowList[i][j+1],rowList[i+1][j],rowList[i+2][j],rowList[i+3][j+1],rowList[i+2][j+2],rowList[i+1][j+2]))
        rs.AddPolyline((rowList[i][j+1],rowList[i+1][j],rowList[i+2][j],rowList[i+3][j+1],rowList[i+2][j+2],rowList[i+1][j+2],rowList[i][j+1]))
        rs.AddSrfPt((rowList[i][j+1],rowList[i+1][j],rowList[i+2][j],rowList[i+3][j+1]))
        rs.AddSrfPt((rowList[i+3][j+1],rowList[i+2][j+2],rowList[i+1][j+2],rowList[i][j+1]))
        row1Hex.append(tempHex)

for i in range (0,len(normalList)-3,4):
    for j in range (0,len(normalList[i])-2,2):
        cen = rs.PointCoordinates(cenPt((normalList[i][j+1],normalList[i+1][j],normalList[i+2][j],normalList[i+3][j+1],normalList[i+2][j+2],normalList[i+1][j+2])))
        row1Cen.append(cen)
        rs.AddPolyline((normalList[i][j+1],normalList[i+1][j],normalList[i+2][j],normalList[i+3][j+1],normalList[i+2][j+2],normalList[i+1][j+2],normalList[i][j+1]))
        rs.AddSrfPt((normalList[i][j+1],normalList[i+1][j],normalList[i+2][j],normalList[i+3][j+1]))
        rs.AddSrfPt((normalList[i+3][j+1],normalList[i+2][j+2],normalList[i+1][j+2],normalList[i][j+1]))
for i in range (0,len(row1Hex)):
    for j in range(0,len(row1Hex[i])):
        for k in range (0,len(row1Hex[i][j])-1):
            rs.AddSrfPt([row1Hex[i][j][k],row1Hex[i][j][k+1],row1Cen[i]])
        rs.AddSrfPt([row1Hex[i][j][5],row1Hex[i][j][0],row1Cen[i]])

row2Cen = []
row2Hex = []

for i in range (2,len(rowList)-3,4):
    for j in range (1,len(rowList[i])-2,2):
        tempHex = []
        tempHex.append((rowList[i][j+1],rowList[i+1][j],rowList[i+2][j],rowList[i+3][j+1],rowList[i+2][j+2],rowList[i+1][j+2]))
        rs.AddPolyline((rowList[i][j+1],rowList[i+1][j],rowList[i+2][j],rowList[i+3][j+1],rowList[i+2][j+2],rowList[i+1][j+2],rowList[i][j+1]))
        rs.AddSrfPt((rowList[i][j+1],rowList[i+1][j],rowList[i+2][j],rowList[i+3][j+1]))
        rs.AddSrfPt((rowList[i+3][j+1],rowList[i+2][j+2],rowList[i+1][j+2],rowList[i][j+1]))
        row2Hex.append(tempHex)

for i in range (2,len(normalList)-3,4):
    for j in range (1,len(normalList[i])-2,2):
        cen = rs.PointCoordinates(cenPt((normalList[i][j+1],normalList[i+1][j],normalList[i+2][j],normalList[i+3][j+1],normalList[i+2][j+2],normalList[i+1][j+2])))
        row2Cen.append(cen)
        rs.AddPolyline((normalList[i][j+1],normalList[i+1][j],normalList[i+2][j],normalList[i+3][j+1],normalList[i+2][j+2],normalList[i+1][j+2],normalList[i][j+1]))
        rs.AddSrfPt((normalList[i][j+1],normalList[i+1][j],normalList[i+2][j],normalList[i+3][j+1]))
        rs.AddSrfPt((normalList[i+3][j+1],normalList[i+2][j+2],normalList[i+1][j+2],normalList[i][j+1]))
for i in range (0,len(row2Hex)):
    for j in range(0,len(row2Hex[i])):
        for k in range (0,len(row2Hex[i][j])-1):
            rs.AddSrfPt([row2Hex[i][j][k],row2Hex[i][j][k+1],row2Cen[i]])
        rs.AddSrfPt([row2Hex[i][j][5],row2Hex[i][j][0],row2Cen[i]])




rs.EnableRedraw(True)

No comments:

Post a Comment