Python教程

RhinoPython镂空曲面

本文主要是介绍RhinoPython镂空曲面,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#coding:utf-8
import rhinoscriptsyntax as rs

def SrfPts(srf,intU,intV):
    ptDict={}

    #设定曲面的UV区间
    Udomain=rs.SurfaceDomain(srf,0)
    Vdomain=rs.SurfaceDomain(srf,1)
    print "Udomain:",Udomain
    print "Vdomain:",Vdomain

    #设定曲面UV方向的步长
    stepU=(Udomain[1]-Udomain[0])/intU
    stepV=(Udomain[1]-Udomain[0])/intV
    print "stepU:",stepU
    print "stepV:",stepV

    for i in range(intU+1):
        for j in range(intV+1):
            u=Udomain[0]+stepU*i
            v=Vdomain[0]+stepV*j

            point=rs.EvaluateSurface(srf,u,v)
            ptDict[(i,j)]=point
            # rs.AddPoint(point)

    for i in range(intU+1):
        for j in range(intV+1):
            if i>0 and j>0:
                center=findMidPt(ptDict[i,j],ptDict[i-1,j-1])
                curve1=rs.AddCurve((ptDict[i,j],center,ptDict[i,j-1]),3)
                curve2=rs.AddCurve((ptDict[i,j-1],center,ptDict[i-1,j-1]),3)
                curve3=rs.AddCurve((ptDict[i-1,j-1],center,ptDict[i-1,j]),3)
                curve4=rs.AddCurve((ptDict[i-1,j],center,ptDict[i,j]),3)

                outline=rs.JoinCurves([curve1,curve2,curve3,curve4],True)
                innerline=rs.AddCurve((ptDict[(i,j)],ptDict[(i,j-1)],ptDict[(i-1,j-1)],
                ptDict[(i-1,j)],ptDict[i,j]),3)
                rs.ScaleObject(innerline,center,(0.4,0.4,0.4))

                sweepline=rs.AddLine(ptDict[i,j-1],rs.CurveStartPoint(innerline))
                rs.AddSweep2([outline,innerline],[sweepline])
                rs.DeleteObject(sweepline)

            # rs.AddTextDot((i,j),ptDict[(i,j)])
            # rs.AddPoint(ptDict[i,j])


def findMidPt(point1,point2):
    midPt=((point1[0]+point2[0])/2,
    (point1[1]+point2[1])/2,
    (point1[2]+point2[2])/2,)
    return midPt


def main():
    strSrf=rs.GetObject("select a surface",rs.filter.surface)
    intU=rs.GetInteger("How many u intervals",8)
    intV=rs.GetInteger("How many v intervals",8)
    # rs.HideObject(strSrf)

    SrfPts(strSrf,intU,intV)

main()

 

这篇关于RhinoPython镂空曲面的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!