Web VPython 3.2
g=9.8; h=25.0; y_0=h; v_0=0.;
y=y_0; v=v_0
scene = canvas(width=600, height=600,center=vec(0,12,0),
background=vec(0.0,0.0,0.0))
ball1= sphere(pos=vec(0,y_0,0), radius=0.5, color=color.yellow)
varr1=arrow(pos=ball1.pos,axis=vec(0,-0.0,0),
shaftwidth=0.1,color=color.red)
floor=box(pos=vector(0,0,0),size=vector(20,0.5,20),
color=color.blue,opacity=0.5)
scene.camera.pos=vec(0,10,50)
scene.pause('click')
t=0.; dt=0.01
NR=int(1./dt); NR=50
while True:
rate(NR)
y=h-0.5*g*t**2 #自由落體的精確解
v+=-g*t #自由落體的精確解
ball1.pos=vector(0,y,0)
varr1.pos=ball1.pos
varr1.axis=vec(0,v*0.002,0)
if(ball1.pos.y < 0): break
t+=dt
Web VPython 3.2
g=9.8; h=25.0; y_0=h; v_0=0.;
y=y_0; v=v_0; v2=0
scene = canvas(width=600, height=600,center=vec(0,12,0),
background=vec(0.0,0.0,0.0))
ball1= sphere(pos=vec(0,y_0,0), radius=0.5, color=color.yellow)
varr1=arrow(pos=ball1.pos,axis=vec(0,-0.0,0),
shaftwidth=0.1,color=color.red)
ball2= sphere(pos=vec(1.2,y_0,0), radius=0.5, color=color.cyan)
floor=box(pos=vector(0,0,0),size=vector(20,0.5,20),
color=color.blue,opacity=0.5)
scene.camera.pos=vec(0,10,50)
scene.pause('click')
t=0.; dt=0.05
NR=int(1./dt);
while True:
rate(NR)
y=h-0.5*g*t**2 #自由落體的精確解
v+=-g*t #自由落體的精確解
ball1.pos=vector(0,y,0)
varr1.pos=ball1.pos
varr1.axis=vec(0,v*0.002,0)
|
![]() |
Web VPython 3.2
g=9.8; h=25.0; y_0=h; v_0=0.;
y=y_0; v=v_0; v2=0
scene = canvas(width=600, height=600,center=vec(0,12,0),
background=vec(0.0,0.0,0.0))
ball1= sphere(pos=vec(0,y_0,0), radius=0.5, color=color.yellow)
ball1.arr=arrow(pos=ball1.pos,axis=vec(0,-0.0,0),
shaftwidth=0.1,color=color.red)
ball1.v=vec(0,v_0,0)
floor=box(pos=vector(0,0,0),size=vector(20,0.5,20),
color=color.blue,opacity=0.5)
scene.camera.pos=vec(0,10,50)
scene.pause('click')
t=0.; dt=0.01
NR=int(1./dt/2);
while t < 20:
rate(NR)
ball1.v.y += -g*dt
ball1.pos.y += ball1.v.y*dt #自由落體的差分近似
ball1.arr.pos=ball1.pos
ball1.arr.axis=ball1.v*0.2
|
![]() |
Web VPython 3.2
g=9.8; h=25.0; y_0=h; v_0=0.; gv=vec(0,9.8,0); C=0.3
y=y_0; v=v_0; v2=0
scene = canvas(width=600, height=600,center=vec(0,12,0),
background=vec(0.0,0.0,0.0))
ball1= sphere(pos=vec(0,y_0,0), radius=0.5, color=color.yellow)
ball1.v=vec(0,v_0,0)
ball2= sphere(pos=vec(2,y_0,0), radius=0.5, color=color.cyan)
ball2.v=vec(0,v_0,0)
floor=box(pos=vector(0,0,0),size=vector(20,0.5,20),
color=color.blue,opacity=0.5)
scene.camera.pos=vec(0,10,50)
scene.pause('click')
t=0.; dt=0.01
NR=int(1./dt);
while t < 20:
rate(NR)
ball1.v.y += -g*dt
ball1.pos.y += ball1.v.y*dt #自由落體的差分近似
|
![]() |