我有一个项目可以使“带有空气阻力的自由落体运动”,但是我的代码在运行时并没有像自由落体运动那样工作,球只是穿过地板而不在上面弹跳。请帮助
from vpython import *
import math as ma
ball = sphere( pos=vector(0,5,0), radius=1, color=color.red)
floor = box(pos=vector(0,-5,0), length=8, height=0.2, width=4)
ball.velocity=vector(0,0,0)
time = 0
m= 1
g = 9.81
k = 0.25
dt = 0.01
v = ma.sqrt(m*g/k)*ma.tanh(time/(ma.sqrt(m*g/k)))
while (time<=100) :
rate(60)
ball.velocity.y = ball.velocity.y + v
ball.pos= ball.pos.y - m*ma.log(ma.cosh(time/(ma.sqrt(m*g/k))))
if ball.pos.y <= floor.pos.y + ball.radius:
ball.velocity.y=-ball.velocity.y
time = time + dt