With regards to my Emergent Workshop groupmates
import rhinoscriptsyntax as rs
from System.Drawing import Color
def baricenter (listpoints):
x=0
y=0
z=0
for i in range(0,len(listpoints)):
x = x+listpoints[i][0]
y = y+listpoints[i][1]
z = z+listpoints[i][2]
x = x/len(listpoints)
y = y/len(listpoints)
z = z/len(listpoints)
return(x,y,z)
def samplesurface(strSurf, intUdivisions, intVdivisions):
uDomain = rs.SurfaceDomain(surface,0)
vDomain = rs.SurfaceDomain(surface,1)
listOfPts = []
listOfNormals = []
listOfNormals2 = []
NormScale = 2
NormScale2 = 10
for i in rs.frange(uDomain[0], uDomain[1]+0.01, (uDomain[1]-uDomain[0])/intUdivisions): #TO INCLUDE THE LAST VALUE OF THE DOMAIN, SUM A VALUE TO IT WITH LESS VALUE THAN THE SEGMENT LENGTH.
TempPtsList = []
TempNormList = []
TempNormList2 = []
for j in rs.frange(vDomain[0], vDomain[1]+0.01,(vDomain[1]-vDomain[0])/intVdivisions):
TempPt = rs.EvaluateSurface(strSurf, i , j )
NormVect = rs.SurfaceNormal(strSurf,[i,j])
NormVect = rs.VectorUnitize(NormVect)
###NormScale = NormScale + 0.1
NormVect = rs.VectorScale(NormVect,NormScale)
VectPt = rs.VectorAdd(TempPt,NormVect)
NormVect2 = rs.VectorReverse(NormVect)
NormVectScale2 = rs.VectorScale(NormVect2, NormScale2)
VectPt2 = rs.VectorAdd(TempPt, NormVectScale2)
TempPtsList.append(TempPt)
TempNormList.append(VectPt)
TempNormList2.append(VectPt2)
listOfPts.append(TempPtsList)
listOfNormals.append(TempNormList)
listOfNormals2.append(TempNormList2)
return (listOfPts, listOfNormals, listOfNormals2)
surface = rs.GetObject("Select surface to evaluate",8)
rs.EnableRedraw(False)
intUdivisions = 20 #divisions of the surface
intVdivisions = 30
listOfPts = samplesurface(surface, intUdivisions, intVdivisions)[0] #THIS IS THE 2D LIST OF EVALUATION POINTS
listOfNormals = samplesurface(surface, intUdivisions, intVdivisions)[1]
listOfNormals2 = samplesurface(surface, intUdivisions, intVdivisions)[2]
#TO DRAW HEXAGONS IN SURFACE BY HALVES
hexList = []
for i in range(0,len(listOfPts)-2,2):
tempHexList = []
for j in range(0,len(listOfPts[i])-2,3):
a= listOfPts[i+1][j]
b= listOfPts[i+2][j+1]
c= listOfPts[i+2][j+2]
d= listOfPts[i+1][j+3]
e= listOfPts[i][j+2]
f= listOfPts[i][j+1]
hexagons = rs.AddCurve([a, b, c, d, e, f, a], 1)
tempHexList.append(hexagons)
rs.AddSrfPt([a, b, c, d])
rs.AddSrfPt([a, d, e, f])
hexList.append(tempHexList)
#TO FIND POINT TO EXTRUDE
baricenters = []
for i in range(0,len(listOfNormals)-2,2):
tempMiddlePts = []
for j in range(0,len(listOfNormals[i])-2,3):
a=listOfNormals[i+1][j]
b=listOfNormals[i+2][j+1]
c=listOfNormals[i+2][j+2]
d=listOfNormals[i+1][j+3]
e=listOfNormals[i][j+2]
f=listOfNormals[i][j+1]
midPt = baricenter((a,b,c,d,e,f))
tempMiddlePts.append(midPt)
baricenters.append(tempMiddlePts)
baricenters2 = []
for i in range(0,len(listOfNormals2)-2,2):
tempMiddlePts = []
for j in range(0,len(listOfNormals2[i])-2,3):
a=listOfNormals2[i+1][j]
b=listOfNormals2[i+2][j+1]
c=listOfNormals2[i+2][j+2]
d=listOfNormals2[i+1][j+3]
e=listOfNormals2[i][j+2]
f=listOfNormals2[i][j+1]
midPt = baricenter((a,b,c,d,e,f))
tempMiddlePts.append(midPt)
baricenters2.append(tempMiddlePts)
#EXTRUSION TO A POINT
for i in range(0,len(hexList)):
for j in range(0,len(hexList[i])):
rs.ExtrudeCurvePoint(hexList[i][j], baricenters[i][j])
for i in range(0,len(hexList)):
for j in range(0,len(hexList[i])):
rs.ExtrudeCurvePoint(hexList[i][j], baricenters2[i][j])
rs.EnableRedraw(True)
No comments:
Post a Comment