本單元的參考程式 |
本單元的影片▶拋體運動解說影片▶拋體運動(VPYTHON) |
Web VPython 3.2
v0=20; theta=radians(60.); g=9.8; N=320; dt=0.01; NR=int(1./dt)
t=[dt*i for i in range(N)]
x=[v0*cos(theta)*i for i in t] #拋體運動之精確解
y=[v0*sin(theta)*i-0.5*g*i**2 for i in t] #拋體運動之精確解
z=[0 for i in range(N)]
scene = canvas(width=800, height=600, center=vec(20,10,0))
ball=sphere(pos=vec(x[0],y[0],z[0]),radius=0.3, color=color.yellow \
,make_trail=True)
Xaxis=arrow(pos=vec(0,0,0), axis=vec(40,0,0), shaftwidth=0.05 \
, headwidth=0.1, color=vec(0,1,0))
scene.pause('click to start')
for i in range(len(t)):
ball.pos=vec(x[i],y[i],z[i])
rate(NR)
|
![]() |
Web VPython 3.2
Web VPython 3.2
v0=20; theta=radians(60.); g=9.8; gv=vec(0,-g,0); N=600;
tm=0; dt=0.02; NR=int(1./dt)
t=[dt*i for i in range(N)]
x=[v0*cos(theta)*i for i in t] #拋體運動之精確解
y=[v0*sin(theta)*i-0.5*g*i**2 for i in t] #拋體運動之精確解
z=[0 for i in range(N)]
scene = canvas(width=800, height=600, center=vec(20,10,0))
ball1=sphere(pos=vec(x[0],y[0],z[0]),radius=0.3, color=color.yellow \
,make_trail=True)
Xaxis=arrow(pos=vec(0,0,0), axis=vec(40,0,0), shaftwidth=0.05 \
, headwidth=0.1, color=vec(0,1,0))
ball2=sphere(pos=vec(x[0],y[0],z[0]),radius=0.3, color=color.cyan \
,make_trail=True, opacity=0.5)
ball2.v=vec(v0*cos(theta),v0*sin(theta),0)
scene.pause('click to start')
i=0
while tm < 10:
rate(NR)
ball1.pos=vec(x[i],y[i],z[i])
ball2.v+=gv*dt #拋體運動之差分近似
ball2.pos+=ball2.v*dt #拋體運動之差分近似
if(ball2.pos.y < 0): break
tm+=dt; i+=1
|
![]() |
Web VPython 3.2
v0=20; theta=radians(60.); g=9.8; gv=vec(0,-g,0); N=600; C=0.3
t=0; dt=0.02; NR=int(1./dt)
scene = canvas(width=800, height=600, center=vec(20,10,0))
Xaxis=arrow(pos=vec(0,0,0), axis=vec(40,0,0), shaftwidth=0.05 \
, headwidth=0.1, color=vec(0,1,0))
ball1=sphere(pos=vec(0,0,0),radius=0.3, color=color.yellow \
,make_trail=True)
ball1.v=vec(v0*cos(theta),v0*sin(theta),0)
ball2=sphere(pos=vec(0,0,0),radius=0.3, color=color.cyan \
,make_trail=True, opacity=0.5)
ball2.v=vec(v0*cos(theta),v0*sin(theta),0)
scene.pause('click to start')
i=0
while t < 10:
rate(NR)
ball1.v+=gv*dt
ball1.pos+=ball1.v*dt
ball2.v+=(gv-C*ball2.v)*dt
ball2.pos+=ball2.v*dt
if(ball2.pos.y < 0): break
t+=dt
|
![]() |