Sunday, April 29, 2012

+ Artichokes



import rhinoscriptsyntax as rs

def samplesurface(strSurf, intUdivisions, intVdivisions):
   
    uDomain = rs.SurfaceDomain(surface,0)
    #print uDomain
    vDomain = rs.SurfaceDomain(surface,1)
    #print vDomain
   
    listOfRows = []
   
    for i in rs.frange(uDomain[0], uDomain[1]+.001, (uDomain[1]-uDomain[0])/intUdivisions):
        columnList = []
        for j in rs.frange(vDomain[0], vDomain[1]+.001,(vDomain[1]-vDomain[0])/intVdivisions):
            pt = rs.EvaluateSurface(surface,i,j)
            columnList.append(pt)
        listOfRows.append(columnList)
    return listOfRows

def CenterPt(listOfPoints):
  
    X = 0
    Y = 0
    Z = 0
    for i in range (0,len(listOfPoints)):
        X = X + (listOfPoints[i][0])
        Y = Y + (listOfPoints[i][1])
        Z = Z + (listOfPoints[i][2])
    XMid = X/len(listOfPoints)
    YMid = Y/len(listOfPoints)
    ZMid = Z/len(listOfPoints)
  
    CentPt = [XMid, YMid, ZMid]
    CentPtViz = rs.AddPoint([XMid, YMid, ZMid])
    return CentPt

def NewVec(pt1, pt2, scaleval):
    vectorbetween = rs.VectorCreate(pt1, pt2)
    scaledvector = rs.VectorScale(vectorbetween, -scaleval)
    mynewpoint = rs.VectorAdd( scaledvector, pt1)
    return mynewpoint

rs.EnableRedraw(False)
surface = rs.GetObject("surface",8)

udivisions = 10
vdivisions = 10

Udomain = rs.SurfaceDomain(surface,0)
Vdomain = rs.SurfaceDomain(surface,1)

ustep = (Udomain[1]-Udomain[0])/udivisions
vstep = (Vdomain[1]-Vdomain[0])/vdivisions

listofpoints = []

intUdivisions = 10 #divisions of the surface
intVdivisions = 10

listOfPoints = samplesurface(surface, intUdivisions, intVdivisions)

##diamonds 01
for i in range(0,len(listOfPoints)-1,2):
    for j in range(0,len(listOfPoints[i])-2,2):
        CurveAdd = rs.AddCurve([listOfPoints[i][j+1], listOfPoints[i+1][j+2], listOfPoints[i+2][j+1], listOfPoints[i+1][j], listOfPoints[i][j+1]],2)
        Romb1 = rs.AddSrfPt([listOfPoints[i][j+1], listOfPoints[i+1][j+2], listOfPoints[i+2][j+1], listOfPoints[i+1][j]])
        Points = ([listOfPoints[i][j+1], listOfPoints[i+1][j+2], listOfPoints[i+2][j+1], listOfPoints[i+1][j]])
       
        borderPts = [listOfPoints[i][j+1], listOfPoints[i+1][j+2], listOfPoints[i+2][j+1],listOfPoints[i+1][j]]
        MidPt = CenterPt(borderPts) #places the borderPts into MidPT
        innerPts = []
       
        for k in range(0,len(borderPts)):
            innerPts.append(NewVec(borderPts[k],MidPt,.2))
           
        uv = rs.SurfaceClosestPoint(surface, innerPts[3])
        norm = rs.SurfaceNormal(surface,uv) # is giving you the normal at [0,0,0]
        norm = rs.VectorUnitize(norm) # it is making the lenght of the vector = 1 (still at the origin)
        norm = rs.VectorScale(norm, j/7)
        norm = rs.VectorAdd(innerPts[3],norm)
        srf01= rs.AddSrfPt([innerPts[0], innerPts[1],borderPts[1],borderPts[0]])
        srf02= rs.AddSrfPt([innerPts[1], innerPts[2],borderPts[2],borderPts[1]])
        srf03= rs.AddSrfPt([innerPts[2], innerPts[3],borderPts[3],borderPts[2]])
        srf04= rs.AddSrfPt([innerPts[0], innerPts[3],borderPts[3],borderPts[0]])
        srf05= rs.AddSrfPt([innerPts[0], innerPts[1],innerPts[2],norm])

##diamonds 02
for i in range(1,len(listOfPoints)-2,2):
    for j in range(1,len(listOfPoints[i])-3,2):
       
        uv = rs.SurfaceClosestPoint(surface, listOfPoints[i+1][j])
       
        borderPts = [listOfPoints[i][j+1], listOfPoints[i+1][j+2], listOfPoints[i+2][j+1],listOfPoints[i+1][j]]
        MidPt = CenterPt(borderPts) #places the borderPts into MidPT
        innerPts = []
       
        for k in range(0,len(borderPts)):
            innerPts.append(NewVec(borderPts[k],MidPt,.2))
           
        uv = rs.SurfaceClosestPoint(surface, innerPts[3])
        norm = rs.SurfaceNormal(surface,uv) # is giving you the normal at [0,0,0]
        norm = rs.VectorUnitize(norm) # it is making the lenght of the vector = 1 (still at the origin)
        norm = rs.VectorScale(norm, j/7)
        norm = rs.VectorAdd(innerPts[3],norm)
        srf01= rs.AddSrfPt([innerPts[0], innerPts[1],borderPts[1],borderPts[0]])
        srf02= rs.AddSrfPt([innerPts[1], innerPts[2],borderPts[2],borderPts[1]])
        srf03= rs.AddSrfPt([innerPts[2], innerPts[3],borderPts[3],borderPts[2]])
        srf04= rs.AddSrfPt([innerPts[0], innerPts[3],borderPts[3],borderPts[0]])
        srf05= rs.AddSrfPt([innerPts[0], innerPts[1],innerPts[2],norm])
       
        CurveAdd2 = rs.AddCurve([listOfPoints[i][j+1], listOfPoints[i+1][j+2], listOfPoints[i+2][j+1], norm, listOfPoints[i][j+1]],2)
        Romb2 = rs.AddSrfPt([listOfPoints[i][j+1], listOfPoints[i+1][j+2], listOfPoints[i+2][j+1], norm])


##to make the seam diamonds, diamonds 03
for i in range(0,(vdivisions),2):
    for j in range(0,(udivisions),2):
#        rs.AddSrfPt([listOfPoints[len(listOfPoints)-2][j+2], listOfPoints[len(listOfPoints)-1][j+3], listOfPoints[i+1][j+2],listOfPoints[len(listOfPoints)-1][j+1]])
       
        uv = rs.SurfaceClosestPoint(surface, listOfPoints[len(listOfPoints)-1][j+1])
       
        borderPts = [listOfPoints[len(listOfPoints)-2][j+2], listOfPoints[len(listOfPoints)-1][j+3], listOfPoints[i+1][j+2],listOfPoints[len(listOfPoints)-1][j+1]]
        MidPt = CenterPt(borderPts) #places the borderPts into MidPT
        innerPts = []
       
        for k in range(0,len(borderPts)):
            innerPts.append(NewVec(borderPts[k],MidPt,.2))
        norm = rs.SurfaceNormal(surface,uv)
        norm = rs.VectorUnitize(norm)
        norm = rs.VectorScale(norm, j/7)
       
        norm = rs.VectorAdd(listOfPoints[len(listOfPoints)-1][j+1],norm)
       
        uv = rs.SurfaceClosestPoint(surface, innerPts[3])
        norm = rs.SurfaceNormal(surface,uv) # is giving you the normal at [0,0,0]
        norm = rs.VectorUnitize(norm) # it is making the lenght of the vector = 1 (still at the origin)
        norm = rs.VectorScale(norm, j/7)
        norm = rs.VectorAdd(innerPts[3],norm)
        srf01= rs.AddSrfPt([innerPts[0], innerPts[1],borderPts[1],borderPts[0]])
        srf02= rs.AddSrfPt([innerPts[1], innerPts[2],borderPts[2],borderPts[1]])
        srf03= rs.AddSrfPt([innerPts[2], innerPts[3],borderPts[3],borderPts[2]])
        srf04= rs.AddSrfPt([innerPts[0], innerPts[3],borderPts[3],borderPts[0]])
        srf05= rs.AddSrfPt([innerPts[0], innerPts[1],innerPts[2],norm])
       

rs.EnableRedraw(True)

No comments:

Post a Comment