简体   繁体   中英

How do I implement the weight of two balls in vpython?

How do I implement the weight of two balls in vpython?

I'll put the ball in the air and compare the drop velocity of the ball with its weight.

How do we implement this? If there is another library, please recommend it.

As an answer I posted a link to an extensive tutorial on how to make physics models using VPython, but my answer was erased because I necessarily had to give a link to that tutorial. So here is at least a simple example of a falling and bouncing ball:

floor = box(pos=vec(0,-5,0), size=vec(10,0.2,10), texture=textures.wood)
ball = sphere(pos=vec(-5,5,0), radius=0.3, 
    make_trail=True, color=color.cyan, emissive=True)
L = local_light(pos=ball.pos, color=ball.color)
m = 1
g = 9.8
p = m*vec(2,0,0) # initial momentum of the ball
dt = 0.01
t = 0
gr = gcurve(color=color.red)
while ball.pos.x < 12:
    rate(100)
    F = vec(0,-m*g,0)
    p = p + F*dt
    ball.pos = ball.pos + (p/m)*dt
    L.pos = ball.pos
    if ball.pos.y < floor.pos.y + ball.radius:
        p.y = -p.y
    t += dt
    gr.plot(t,p.y/m)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM