好玩的双球摆

陈海涛老师
2022-02-24 / 0 评论 / 86 阅读 / 正在检测是否收录...

双球摆背景

  双摆是将一根单摆连接在另一个单摆的尾部所构成的系统。双摆同时拥有着简单的构造和复杂的行为。高能量双摆的摆动轨迹表现出对于初始状态的极端敏感。两个初始状态差异极小的双摆在一段时间的运行后表现非常不同,是一种具有混沌性质的简单动力系统。

程序演示


代码

g = 9.8; size = 0.03; L = 0.25; k = 100000; m = 0.1; theta = 30 * pi/180     
Fg = m*vector(0,-g,0)  

def SpringForce(r,L):
    return -k*(mag(r)-L)*r/mag(r)

scene = canvas(width=300, height=300, center=vector(0, -L*0.8, 0), range=1,background=vector(0.5,0.6,0.4))
ceiling = box(length=0.1, height=0.005, width=0.1, opacity = 0.6)
ball1 = sphere(radius = size,  color=color.red, make_trail = True)
ball2 = sphere(radius = size,  color=color.green, make_trail = True)
rod1 = cylinder(radius=size/10)
rod2 = cylinder(radius=size/10)

ball1.pos = vector(L, 0, 0)  
ball2.pos = vector(2*L, 0, 0)                         
rod1.pos = vector(0, 0, 0)   
rod2.pos = vector(L, 0, 0)                       
ball2.v=vector(0,0,0)
ball1.v=vector(0,0,0)

dt = 0.0001    
t = 0.0       

while t<2:
    rate(1000)
    t=t+dt
    rod2.pos = ball1.pos                 
    rod1.axis = ball1.pos               
    rod2.axis = ball2.pos - ball1.pos  

    F1 = vector(0, -m*g, 0) + SpringForce(rod1.axis,L) - SpringForce(rod2.axis,L) 
    F2 = vector(0, -m*g, 0) + SpringForce(rod2.axis,L) 

    ball1.v += F1/m*dt
    ball1.pos += ball1.v*dt
    ball2.v += F2/m*dt
    ball2.pos += ball2.v*dt
1

评论 (0)

取消