[英]Python Bungee Cord Simulation
我正在尝试使用视觉效果模拟蹦极跳线(我尝试在此处搜索非常相似的答案,但未提供答案)。 我的代码是
def animateBungeeJump(mass, deltaT, simulationTime, surfaceArea, unstretchedBungeeLength):
g = 9.8
k = 21.7
vel = 0.0
accel = 0.0
distance = unstretchedBungeeLength
time_start = 0.0
d = 0.0
while(time_start <= simulationTime):
Fg = mass * g
Ff = (-0.65) * surfaceArea * vel * abs(vel)
Fs = (-1) * k * d
Ft = Fg + Ff + Fs
accel = Ft / mass
vel = accel * time_start
d += vel * time_start
print "Accel", accel
print "D:", d
print "Vel:", vel
print ""
time_start += deltaT
animateBungeeJump(60, 0.1, 5.0, 0.2, 30)
我想在调试时看到的结果是看到加速度如何弹跳,并且通常应该在上下距离(d)弹跳,但是在不断运行代码的情况下,如果我使用了10s或更长时间的SimulationTime,它将变为-inf和inf。 我不知道我是否在正确地进行所有数学运算。 抱歉,如果我的代码看起来很愚蠢,我正在学习。
大约5秒钟时结束的示例输出:
Accel -4.29956602269e+105 D: -1.07489150567e+107 Vel: -2.14978301134e+106
我很确定速度不应该那么低
您的增量更改未正确完成。 速度是自上次以来的变化; 速度和距离都应根据时间跨度而不是整个运行时间进行更新。 试试这些:
vel += accel * deltaT
d += vel * deltaT
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.