花样摆模型

陈海涛老师
2022-01-25 / 0 评论 / 468 阅读 / 正在检测是否收录...

经典物理情景

单摆受到扰动时会在空间中做复杂的运动:
单摆的速度为v$\text{(a,b,c),a、b、c}$为三个方向上的分量且为一定的数值时,单摆的运动情况不同。

程序演示


程序源码

g = 9.8;size=0.05;L=0.5;theta=5*pi/180;k=100000000.0;m=1.0;d = [ ]   
for i in range(5): 
    d.append(canvas(x=600*(i//3), y=30+200*(i % 3 ), width=300, height=400, 
                    background=vector(0.5,0.6,0.5)))    
def SpringForce(r):
    return - k*(mag(r)-L) * r / mag(r) 
v0 = sqrt(g*L*sin(theta)*tan(theta))
floors=[ ];balls=[ ];varr=[]
for i in range(5):
    floors.append(box(pos=vector(0,0,0), length=0.05, height=0.001,
              width=0.05, color=color.yellow,canvas=d[i]))
    balls.append(sphere(radius = size, color=color.red,make_trail=0.01,
                        canvas=d[i],v=vector(i-1,i-1,i*v0))) 
for ball in balls:
    ball.pos = vector(L*sin(theta), -L*cos(theta), 0) 
for i in range(5):
    varr.append(cylinder(pos=vector(0,0,0), radius=0.003, 
                      canvas=d[i],color=color.yellow))
dt = 0.0001 
while True:
     rate(10000) 
     for i in range(5):
         varr[i].axis = vector(balls[i].pos) 
         a = vector(0,-g,0) + SpringForce (varr[i].axis)/m
         balls[i].v += a*dt     
         balls[i].pos += balls[i].v*dt   
6

评论 (0)

取消