Jorin 发表于 2013-10-11 11:38
看了楼主的代码,龙卷风已经有了,接下来是否可以让圆环们逐渐变大,顶部圆环大到一个值以后,圆环数量从底 ...
多谢Jorin...我们改进了一些。下面的代码模拟点云形成的龙卷风,准备加上trail,显示龙卷风的轨迹。。我们还没有考虑消散的问题:)
import rhinoscriptsyntax as rs
def Main():
#GET CENTER
Points=rs.GetObjects("get your agents to start a tornado",rs.filter.point)
rotation=rs.GetReal ("type rotation",15)
gens=rs.GetInteger ("type number of generations",5)
#CurGen=[]
#CurGen.extend(Points)
###get cener axis center point z direction) vec=([Cenx,Ceny,0],[0,0,0])
PtCoordsx=[]
PtCoordsy=[]
PtCoordsz=[]
for pt in Points:
PtCoord=rs.PointCoordinates(pt)
PtCoordsx.append(PtCoord[0])
PtCoordsy.append(PtCoord[1])
PtCoordsz.append(PtCoord[2])
Cenx=sum(PtCoordsx)/len(PtCoordsx)
Ceny=sum(PtCoordsy)/len(PtCoordsy)
Cenz=sum(PtCoordsz)/len(PtCoordsz)
Centercoord=[Cenx,Ceny,Cenz]
Center=rs.AddPoint([Cenx,Ceny,Cenz])
attr=rs.PointAdd(Centercoord,[0,0,-100])
for i in range(gens):
for pt in Points:
newpt=movement(pt,attr,Centercoord,rotation)
Points.remove(pt)
Points.append(newpt)
def movement(point,attractor,center,angle):
Pointcoord=rs.PointCoordinates(point)
vecbase=rs.VectorCreate(attractor,Pointcoord)
Attractor=rs.AddPoint(attractor)
dist=rs.Distance (Attractor,point)
scale=3/dist
vec=rs.VectorScale (vecbase,scale)
temppt=rs.PointAdd(Pointcoord,vec)
tempptid=rs.AddPoint(temppt)
newpt=rs.RotateObject(tempptid,center,angle,axis=None,copy=False)
return(newpt)
Main() |