import rhinoscriptsyntax as rs
import math as m
# DIVIDE THE SURFACE INTO GRID POINTS
surf = rs.GetObject("surface",8)
d_u = rs.SurfaceDomain(surf,0)
d_v = rs.SurfaceDomain(surf,1)
d_u_len = (d_u[1] - d_u[0])/10
d_v_len = (d_v[1] - d_v[0])/10
listofnormals = []
cntrl_pts_surf = []
vector_scale = 5
for i in rs.frange(d_u[0],d_u[1]+d_u_len,d_u_len):
row_list = []
normaltemplist = []
for j in rs.frange(d_v[0],d_v[1],d_v_len):
pt = rs.EvaluateSurface(surf,i,j)
normal_vector = rs.SurfaceNormal(surf,[i,j])
normal_vector = rs.VectorUnitize(normal_vector)
normal_vector = rs.VectorScale(normal_vector,vector_scale)
normal_vector_pt = rs.VectorAdd(pt,normal_vector)
normaltemplist.append(normal_vector_pt)
row_list.append(pt)
rs.AddPoint(normal_vector_pt)
cntrl_pts_surf.append(row_list)
listofnormals.append(normaltemplist)
# ADDS THE GRID POINTS
for i in range(0, len(cntrl_pts_surf)):
for j in range(0,len(cntrl_pts_surf[i])):
rs.AddPoint(cntrl_pts_surf[i][j])
# RHOMBUS TESSELLATION
rhombus_pts_1 = []
rhombus_pts_2 = []
poly_surf = []
for i in range(0, len(cntrl_pts_surf)-2,2):
for j in range(0,len(cntrl_pts_surf[i])-2,2):
points = [(cntrl_pts_surf[i][j+1]),(cntrl_pts_surf[i+1][j+2]),(cntrl_pts_surf[i+2][j+1]),(cntrl_pts_surf[i+1][j])]
poly_surf.append(rs.AddSrfPt(points))
rhombus_pts_1.append(points)
for i in range(0, len(cntrl_pts_surf)-3,2):
for j in range(0,len(cntrl_pts_surf[i])-3,2):
points = [(cntrl_pts_surf[i+1][j+2]),(cntrl_pts_surf[i+2][j+1]),(cntrl_pts_surf[i+3][j+2]),(cntrl_pts_surf[i+2][j+3])]
poly_surf.append(rs.AddSrfPt(points))
rhombus_pts_1.append(points)
# RHOMBUS DOUBLE TESSELLATION
for i in range(0, len(listofnormals)-2,2):
for j in range(0,len(listofnormals[i])-2,2):
points = [(listofnormals[i][j+1]),(listofnormals[i+1][j+2]),(listofnormals[i+2][j+1]),(listofnormals[i+1][j])]
poly_surf.append(rs.AddSrfPt(points))
rhombus_pts_2.append(points)
for i in range(0, len(listofnormals)-3,2):
for j in range(0,len(listofnormals[i])-3,2):
points = [(listofnormals[i+1][j+2]),(listofnormals[i+2][j+1]),(listofnormals[i+3][j+2]),(listofnormals[i+2][j+3])]
poly_surf.append(rs.AddSrfPt(points))
rhombus_pts_2.append(points)
# CENTER POINT OF EACH RHOMBUS WITH SPHERE
def centre_point(rhombus_pts):
i = 0
j = 0
k = 0
for n in range(0,len(rhombus_pts)):
i = i + rhombus_pts[n][0]
j = j + rhombus_pts[n][1]
k = k + rhombus_pts[n][2]
i = i / len(rhombus_pts)
j = j / len(rhombus_pts)
k = k / len(rhombus_pts)
rs.AddPoint([i,j,k])
rs.AddSphere([i,j,k],0.5)
return i,j,k
for i in range(0, len(rhombus_pts_1)):
centre_point(rhombus_pts_1[i])
for i in range(0, len(rhombus_pts_2)):
centre_point(rhombus_pts_2[i])
No comments:
Post a Comment