Tuesday, April 24, 2012

Rhombus tessellation on NURBS surface


import rhinoscriptsyntax as rs
import math as m


def samplesurface(surf):
    
    
    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
    
    cntrl_pts_surf = []
    for i in rs.frange(d_u[0],d_u[1]+d_u_len,d_u_len):
        row_list = []
        for j in rs.frange(d_v[0],d_v[1],d_v_len):
            row_list.append(rs.EvaluateSurface(surf,i,j))
        cntrl_pts_surf.append(row_list)
    return cntrl_pts_surf


surf = rs.GetObject("surface",8)
cntrl_pts_surf = samplesurface(surf)


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])
        


poly = []
poly_surf = []
for i in range(0, len(cntrl_pts_surf)-1,2):
    for j in range(0,len(cntrl_pts_surf[i])-1,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]),(cntrl_pts_surf[i][j+1])]
        p = [(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.append(rs.AddPolyline(points))
        poly_surf.append(rs.AddSrfPt(p))


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]),(cntrl_pts_surf[i+1][j+2])]
        p = [(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.append(rs.AddPolyline(points))
        poly_surf.append(rs.AddSrfPt(p))


No comments:

Post a Comment