簡體   English   中英

Python蹦極繩模擬

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM