Wednesday, April 25, 2012
Loft Hexagon By Different Lengths
import rhinoscriptsyntax as rs
def baricenter (listofhexpts):
x = 0
y = 0
z = 0
for i in range(0,len(listofhexpts)):
x = x + listofhexpts[i][0]
y = y + listofhexpts[i][1]
z = z + listofhexpts[i][2]
x = x / len(listofhexpts)
y = y / len(listofhexpts)
z = z / len(listofhexpts)
return [x,y,z]
strsurf = rs.GetObject("select",8)
Udomain = rs.SurfaceDomain(strsurf,0)
Vdomain = rs.SurfaceDomain(strsurf,1)
Udivisions = 30
Vdivisions = 30
Ustep = (Udomain[1]-Udomain[0])/Udivisions
Vstep = (Vdomain[1]-Vdomain[0])/Vdivisions
listofpoints = []
listofnormals = []
pt2 = rs.GetObject("select pt2",1)
for i in rs.frange(Udomain[0],Udomain[1]+1,Ustep):
templist = []
normaltemplist = []
for j in rs.frange(Vdomain[0],Vdomain[1],Vstep):
#get the loft distance from pt to pt2
pt = rs.EvaluateSurface(strsurf, i, j)
distance = rs.Distance(pt,pt2)
normalscale = distance/5
#find normalpts
normalvector = rs.SurfaceNormal(strsurf,[i,j])
normalvector = rs.VectorUnitize(normalvector)
normalvector = rs.VectorScale(normalvector,normalscale)
normalpts = rs.VectorAdd(pt,normalvector)
templist.append(pt)
normaltemplist.append(normalpts)
listofpoints.append(templist)
listofnormals.append(normaltemplist)
# create loft01
listofbottom01 = []
for i in range (0, len(listofpoints)-2,2):
for j in range(0, len(listofpoints[i])-3,4):
hexpts = [listofpoints[i][j+1],listofpoints[i][j+2],listofpoints[i+1][j+3],listofpoints[i+2][j+2],listofpoints[i+2][j+1],listofpoints[i+1][j],listofpoints[i][j+1]]
hexcurve = rs.AddCurve(hexpts,1)
listofbottom01.append(hexcurve)
listoftop01 = []
for i in range (0, len(listofnormals)-2,2):
for j in range(0, len(listofnormals[i])-3,4):
hexpts = [listofnormals[i][j+1],listofnormals[i][j+2],listofnormals[i+1][j+3],listofnormals[i+2][j+2],listofnormals[i+2][j+1],listofnormals[i+1][j],listofnormals[i][j+1]]
hexs = rs.AddCurve(hexpts,1)
listofhexpts = hexpts
listoftop01.append(hexs)
lofts01 = []
for i in range(0 , len(listofbottom01)):
temp = []
temp.append(listofbottom01[i])
temp.append(listoftop01[i])
loft = rs.AddLoftSrf(temp)
lofts01.append(loft)
# create loft02
listofbottom02 = []
for i in range (1, len(listofpoints)-2,2):
for j in range(2, len(listofpoints[i])-3,4):
hexpts = [listofpoints[i][j+1],listofpoints[i][j+2],listofpoints[i+1][j+3],listofpoints[i+2][j+2],listofpoints[i+2][j+1],listofpoints[i+1][j],listofpoints[i][j+1]]
curve = rs.AddCurve(hexpts,1)
listofbottom02.append(curve)
listoftop02 = []
for i in range (1, len(listofnormals)-2,2):
for j in range(2, len(listofnormals[i])-3,4):
hexpts = [listofnormals[i][j+1],listofnormals[i][j+2],listofnormals[i+1][j+3],listofnormals[i+2][j+2],listofnormals[i+2][j+1],listofnormals[i+1][j],listofnormals[i][j+1]]
hexs = rs.AddCurve(hexpts,1)
listofhexpts = hexpts
listoftop02.append(hexs)
lofts02 = []
for i in range(0 , len(listofbottom02)):
temp = []
temp.append(listofbottom02[i])
temp.append(listoftop02[i])
loft = rs.AddLoftSrf(temp)
lofts02.append(loft)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment