Rhino(犀牛)中国技术支持与推广中心

标题: Python模拟龙卷风 [打印本页]

作者: 大美在前方    时间: 2013-10-10 23:22
标题: Python模拟龙卷风
宾大的一个python课,我们想用python去模拟单个龙卷风的形成、消散,以及到多个龙卷风的相互干扰过程。这是昨晚写的很初级的脚本,大神可以提个意见以及以后发展的思路。:)

import rhinoscriptsyntax as rs



def Main():
    strcir=rs.GetObject ("select a circle to start a tornado")
    mvnt=rs.GetReal ("type distance",1)
    rotation=rs.GetReal ("type rotation",30)
    gens=rs.GetInteger  ("type number of generations",100)
    strptcl=rs.DivideCurve(strcir,10)
    CurGen=[]
    CurGen.append(strcir)
    for i in range(gens):
        NewGen=[]
        for circle in CurGen:
             Newcircle= transmition(circle,mvnt,rotation)
             Newptcld=rs.DivideCurve(Newcircle,10)
             NewGen.extend(Newcircle)

        CurGen=NewGen

def transmition(circle,movement,rotation):
    cenpt=rs.CircleCenterPoint(circle)
    vec=rs.VectorCreate([0,0,0],[0,1,1])
    radius=rs.CircleRadius(circle)

    #scaleofradius=rs.GetReal ("type the number for next radius scale",0.9)
    newradius=radius*0.9
    newcenpt=rs.PointAdd(cenpt,vec)


    newcir1=rs.AddCircle(newcenpt,newradius)
    newcir2=rs.RotateObject(newcir1,newcenpt,15,[0,1,0],copy=True)
    newptcld=rs.DivideCurve(newcir2,10)
    return[newcir2]


Main()




作者: Jorin    时间: 2013-10-11 00:15
龙卷风!?厉害!明天起来了仔细看看。
作者: 筑梦NARUTO    时间: 2013-10-11 11:35
楼主宾大的?
作者: Jorin    时间: 2013-10-11 11:38
看了楼主的代码,龙卷风已经有了,接下来是否可以让圆环们逐渐变大,顶部圆环大到一个值以后,圆环数量从底部开始减少,在减少的过程中没有被去掉的圆环继续增大,直到他们全部都消散。
作者: 大美在前方    时间: 2013-10-12 08:37
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()
作者: 大美在前方    时间: 2013-10-12 08:38
筑梦NARUTO 发表于 2013-10-11 11:35
楼主宾大的?

是的,建筑与景观双学位
作者: 筑梦NARUTO    时间: 2013-10-13 17:34
大美在前方 发表于 2013-10-12 08:38
是的,建筑与景观双学位

这个厉害。。
作者: 沮丧的疯子    时间: 2013-10-31 10:50
擦 真正的海龟啊
作者: eleanore    时间: 2013-12-4 03:04
楼主你好,我有一个脚本是动态模型。播放之后。转动鼠标它就会自己生长的这种模型。请问你知道如何录下来它生长过程么。python 能做到么?
作者: Jorin    时间: 2013-12-4 11:00
eleanore 发表于 2013-12-4 03:04
楼主你好,我有一个脚本是动态模型。播放之后。转动鼠标它就会自己生长的这种模型。请问你知道如何录下来它 ...

不知道你说的录下指的是什么?




欢迎光临 Rhino(犀牛)中国技术支持与推广中心 (http://bbs.rhino3d.asia/) Powered by Discuz! X3.2