GlowScript 2.9 VPython
scene = display(width=800, height=600, center=vec(0, 0, 0), background=vec(0.2,0.5,0.2))
r=10.; v=10.
ac=v**2/r
ball0 = sphere(pos=vec(0,0,0), radius = 0.1, make_trail=True, color=color.red)
ball1 = sphere(pos=vec(r,0,0), radius = 0.2, make_trail=True, color=color.yellow)
ball1.v=vec(0,v,0)
dt = 0.01
t=0.
while True:
rate(50)
ball1.a=-ball1.pos/mag(ball1.pos)*ac
ball1.v += ball1.a*dt
ball1.pos += ball1.v*dt
t=t+dt
|
GlowScript 2.9 VPython
scene = display(width=800, height=800, center=vec(0, 0, 0), background=vec(0.2,0.5,0.2))
q=1; m=1; r=10.; v=10.
ball1 = sphere(pos=vec(r,0,0), radius = 0.1, make_trail=True, color=color.yellow)
arr=arrow(pos=vec(0,0,0),axis=vec(0,0,8),shaftwidth=0.1)
B=vec(0,0,1)
ball1.v=vec(0,-v,0.2)
t=0.; dt = 0.01; NR=int(1./dt)
while True:
rate(NR)
ball1.a=q*cross(ball1.v,B)/m
ball1.v += ball1.a*dt
ball1.pos += ball1.v*dt
t=t+dt
|
GlowScript 2.9 VPython
scene = display(width=800, height=800, center=vec(0, -12, 0), background=vec(0.2,0.5,0.2))
q=1; r=10.; v=10.
arrx=arrow(pos=vec(-20,0,0),axis=vec(40,0,0),shaftwidth=0.05,color=vec(0,0.5,0.5))
balls = [sphere(radius = 0.3, color=vec(0.3,0.5,0)*i, make_trail=True) for i in range(3)]
m=[]
for i in range(3):
balls[i].pos=vec(r,5,0)
balls[i].v=vec(0,-v,0)
m.append(1.+0.2*i)
vB=arrow(pos=vec(0,0,0),axis=vec(0,0,8),shaftwidth=0.1)
B=vec(0,0,1)
t=0.; dt = 0.01; NR=int(1./dt)
while t < 5:
rate(NR/2)
for i in range(3):
if(balls[i].pos.y > 0. and balls[i].v.y > 0.) : continue
if(balls[i].pos.y > 0.): a=vec(0,0,0)
else: a=q*cross(balls[i].v,B)/m[i]
balls[i].v += a*dt
balls[i].pos += balls[i].v*dt
t=t+dt
|
GlowScript 2.9 VPython
def qvB():
global m,q,v,B
vb=cross(v,B)
a=q*vb/m
return a
R1=0.02; m=1.; q=1.; v0=1.; r0=1.
d=0.2; d2=d/2.; E=4.; xi=-d2+0.0001
acc=vec(q*E/m,0.,0.)
v=vec(0.,1.,0.)
B=vec(0.,0.,1.)
a=qvB()
scene = display(width=800, height=800, center=vec(0,-5,0), background=vec(0.2,0.5,0.2))
b1 = sphere(radius=0.0001,color=color.blue,make_trail=True, trail_radius=0.01)
b1.pos=vec(xi,0,0); b1.v=vec(0.0001,0.,0.)
arr1=arrow(pos=vec(-d2,-8,0),axis=vec(0,16,0),shaftwidth=0.01)
arr2=arrow(pos=vec(d2,-8,0),axis=vec(0,16,0),shaftwidth=0.01)
s='%10.3f'*6
t=0.
dt = 0.001
while t < 400.:
rate(1000)
if(t > 0.2):
if(abs(b1.pos.x+d/2) < 0.001 and b1.v.x > 0.) or (abs(b1.pos.x-d/2) < 0.001 and b1.v.x < 0.):
print ("{:12.4f} {:12.6f}".format(t,mag(b1.v)))
if(b1.pos.x > -d2 and b1.pos.x < d2 and b1.v.x > 0.):
b1.v += acc*dt
b1.pos += b1.v*dt
elif(b1.pos.x > -d2 and b1.pos.x < d2 and b1.v.x < 0.):
b1.v += -acc*dt
b1.pos += b1.v*dt
else:
v=b1.v
b1.a=qvB()
b1.v += b1.a * dt
b1.pos += b1.v * dt
t=t+dt
|
|
============輸出:=============
3.4560 1.266086
6.7290 1.792900
9.9700 2.196347
13.1980 2.540335
16.4130 2.844798
19.6220 3.117692
|