欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

python自由落体_VPython - example - 模拟自由落体运动

发布时间:2024/7/5 58 豆豆
生活随笔 收集整理的这篇文章主要介绍了 python自由落体_VPython - example - 模拟自由落体运动 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

作者:liuyuan_jq

2011-04-10

from visual import *

scene.width = 400

scene.height = 300

scene.autoscale = 0

scene.range = (100,100,100)

scene.center = (0,40,0)

ball = sphere(pos=(0,100,0),radius=2)

ground = box(pos=(0,-1,0),size=(10,2,10))

gravity = 9.8 # m/s**2

seconds = 0

dt = .01

finished = False

while not finished:

rate(100) # go thru the loop no more than 100 times/s

seconds += dt

# position equation: y(t) = y0 + v0*t + .5 * a * t**2

ballHeight = 100 - .5 * gravity * seconds**2

ball.pos = vector(0,ballHeight,0)

if ballHeight - 2 < 0:

finished = True

print "seconds to fall: " + str(seconds)

总结

以上是生活随笔为你收集整理的python自由落体_VPython - example - 模拟自由落体运动的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。