VPython - example - 模拟斜上抛运动 (X - Y 轴)

本作品采用知识共享署名-非商业性使用-相同方式共享 3.0 Unported许可协议进行许可。允许非商业转载,但应注明作者及出处。


作者:liuyuan_jq

2011-04-10


Fromhttp://wiki.showmedo.com/index.php/PythonThompsonVPythonSeries


from visual import * scene.width = 400 scene.height = 300 scene.autoscale = 0 scene.range = (100,100,100) scene.center = (50,40,0) ball = sphere(pos=(0,2,0),radius=2, color=color.green) ground = box(pos=(50,-1,0),size=(100,2,10)) gravity = 9.8 # m/s**2 velocity = 25 # m/s angle = 45 # degrees angle = angle * (pi/180) # converted to radians # sin = opp / hyp # cos = adj / hyp # therefore # opp = hyp * sin # adj = hyp * cos VelocityY = velocity * sin(angle) VelocityX = velocity * cos(angle) 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 ballY = 2 + VelocityY * seconds - .5 * gravity * seconds**2 ballX = VelocityX * seconds ball.pos = vector(ballX,ballY,0) if ballY - 2 <= 0: finished = True print "initial velocity: " + str(velocity) print "angle thrown: " + str(angle) print "seconds in flight: " + str(seconds) print "distance in the x direction: " + str(ballX)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值