今天有人问如何在多重曲面内生成随机点,大概写个案例。有兴趣的可以看看。
- #coding=utf-8
- import rhinoscriptsyntax as rs
- import random
- import Rhino.Geometry as rg
- def ptRange(pt01,pt02):
- xB = random.uniform(pt01[0],pt02[0])
- yB = random.uniform(pt01[1],pt02[1])
- zB = random.uniform(pt01[2],pt02[2])
- return xB,yB,zB
- randomPtsNum = rs.GetInteger("输入生成的随机点数")
- brep = rs.GetObject("选择要生成随机点的多重曲面",rs.filter.polysurface)
- geo_brep = rs.coercebrep(brep)
- box = geo_brep.GetBoundingBox(True)
- random_pt = []
- while (len(random_pt)<= randomPtsNum):
- pt = ptRange(box.Min,box.Max)
- if rs.IsPointInSurface(brep,pt,True,3):
- random_pt.append(pt)
- for pot in random_pt:
- rs.AddPoint(pot)
复制代码
|