Python --- Python模拟龙卷风

[复制链接]
跳转到指定楼层
35789 大美在前方 发表于 2013-10-10 23:22:10 楼主
宾大的一个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()



分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享
关于大陆地区Rhino原厂培训中心
Jorin 发表于 2013-10-11 00:15:59
2
龙卷风!?厉害!明天起来了仔细看看。
筑梦NARUTO 发表于 2013-10-11 11:35:25
3
楼主宾大的?
Jorin 发表于 2013-10-11 11:38:46
4
看了楼主的代码,龙卷风已经有了,接下来是否可以让圆环们逐渐变大,顶部圆环大到一个值以后,圆环数量从底部开始减少,在减少的过程中没有被去掉的圆环继续增大,直到他们全部都消散。
 楼主| 大美在前方 发表于 2013-10-12 08:37:33
5
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:55
6
筑梦NARUTO 发表于 2013-10-11 11:35
楼主宾大的?

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

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

不知道你说的录下指的是什么?
您需要登录后才可以回帖 登录 | 注册成为会员

本版积分规则