#Point Matrix import rhinoscriptsyntax as rs import random def GenerateMatrix(IMAX, JMAX, KMAX): imax = IMAX jmax = JMAX kmax = KMAX Pt = {} midPt = [] # dictionary of all of our points keyed on a tuple # of i,j,k values for i in range(imax): for j in range(jmax): for k in range(kmax): #redfine x,y,z relative to i,j,k x = i * 5 + random.random() * 2 y = j * 5 + random.random() * 2 z = k * 5 + random.random() * 5 Pt[(i,j,k)] = (x,y,z) points = rs.AddPoint((x,y,z)) #rs.AddTextDot((i,j,k), points) # use dictionary of points to find mid points and store as list for i in range(imax): for j in range(jmax): for k in range(kmax): if i > 0 and j > 0 and k > 0: midPt.append(MidPt(Pt[(i,j,k)], Pt[(i,j-1,k)])) midPt.append(MidPt(Pt[(i,j,k)], Pt[(i-1,j,k)])) midPt.append(MidPt(Pt[(i-1,j,k)], Pt[(i-1,j-1,k)])) midPt.append(MidPt(Pt[(i-1,j-1,k)], Pt[(i,j-1,k)])) midPt.append(MidPt(Pt[(i-1,j-1,k)], Pt[(i-1,j-1,k-1)])) midPt.append(MidPt(Pt[(i-1,j-1,k-1)], Pt[(i,j-1,k-1)])) midPt.append(MidPt(Pt[(i,j-1,k-1)], Pt[(i,j-1,k)])) midPt.append(MidPt(Pt[(i,j-1,k-1)], Pt[(i,j,k-1)])) midPt.append(MidPt(Pt[(i,j,k)], Pt[(i,j,k-1)])) midPt.append(MidPt(Pt[(i,j,k-1)], Pt[(i-1,j,k-1)])) midPt.append(MidPt(Pt[(i-1,j,k)], Pt[(i-1,j,k-1)])) midPt.append(MidPt(Pt[(i-1,j,k-1)], Pt[(i-1,j-1,k-1)])) GenerateSurfaces(midPt) def GenerateSurfaces(MIDPT): midPt = MIDPT for i in range(0, len(midPt)-11, 12): rs.AddSrfPt((midPt[i], midPt[i+1], midPt[i+2], midPt[i+3])) rs.AddSrfPt((midPt[i+3], midPt[i+4], midPt[i+5], midPt[i+6])) rs.AddSrfPt((midPt[i], midPt[i+6], midPt[i+7], midPt[i+8])) rs.AddSrfPt((midPt[i+1], midPt[i+8], midPt[i+9], midPt[i+10])) rs.AddSrfPt((midPt[i+2], midPt[i+10], midPt[i+11], midPt[i+4])) rs.AddSrfPt((midPt[i+5], midPt[i+11], midPt[i+9], midPt[i+7])) rs.AddSrfPt((midPt[i], midPt[i+3], midPt[i+6])) rs.AddSrfPt((midPt[i+3], midPt[i+2], midPt[i+4])) rs.AddSrfPt((midPt[i+2], midPt[i+1], midPt[i+10])) rs.AddSrfPt((midPt[i+1], midPt[i], midPt[i+8])) rs.AddSrfPt((midPt[i+8], midPt[i+7], midPt[i+9])) rs.AddSrfPt((midPt[i+6], midPt[i+5], midPt[i+7])) rs.AddSrfPt((midPt[i+4], midPt[i+11], midPt[i+5])) rs.AddSrfPt((midPt[i+10], midPt[i+9], midPt[i+11])) def MidPt(aP1, aP2): MidPt = None MidPt = [(aP1[0] + aP2[0]) / 2, (aP1[1] + aP2[1]) / 2, (aP1[2] + aP2[2]) / 2] return MidPt def Main(): imax = rs.GetInteger('max number of x points',5) jmax = rs.GetInteger('max number of y points',5) kmax = rs.GetInteger('max number of z points',5) GenerateMatrix(imax, jmax, kmax) if __name__=="__main__": Main()