Tuesday, April 24, 2012

sampling any surface


import rhinoscriptsyntax as rs
from math import *


#section one
#make grid of points
a=1
pointgrid=[]
for i in range (0,10):
    for j in range (0,20):
            pointgrid.append(rs.AddPoint(i,j,a*sin(pi/2*i)))
#add surface
count=10,20
srf=rs.AddSrfPtGrid(count,pointgrid)


#section two
#create surface
surface=rs.GetObject("select surface")
#you have to get the range in two directions
domainU=rs.SurfaceDomain(surface,0)
domainV=rs.SurfaceDomain(surface,1)
#print domainU (is always a float number)
#print domainV (is always a float number)
#evaluate surface
divisions=10 #number of divisions on the surface
stepU=(domainU[1]-domainU[0])/divisions #in the direction of U
stepV=(domainV[1]-domainV[0])/divisions #in the direction of V
for i in rs.frange (domainU[0],domainU[1],stepU): #put always rs.frange cause is a float number
    for j in rs.frange (domainV[0],domainV[1],stepV):
        pointscoord=rs.EvaluateSurface(surface,i,j) 
        rs.AddPoint(pointscoord)

No comments:

Post a Comment