VPython - example - 圆柱体斜上抛滑行运动(X - Y 轴)

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


作者:liuyuan_jq

2011-04-10


From http://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) puck = cylinder(pos=(0,0,0),axis=(0,2,0), radius=2, color=color.green) puck.mass = 1 # kg ground = box(pos=(50,-1,0),size=(100,2,50)) mylabel = label(pos=(50,60,0),text="velocity x: ",height=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) VelocityZ = 0 VelocityThrown = vector(VelocityX,VelocityY,0) VelocityWind = vector(0,0,0) TotalVelocity = VelocityThrown + VelocityWind puckVelocityY = TotalVelocity.y seconds = 0 dt = .01 finished = False while not finished: rate(100) # go thru the loop no more than 100 times/s seconds += dt puckY = TotalVelocity.y * seconds - .5 * gravity * seconds**2 if puckY <= 0: puckY = 0 # Force Due To Kinetic Friction = Normal Force * CoefficientKinetic CoefficientOfKineticFriction = .45 # Newton's second law: Force = mass * acceleration ForceDown = puck.mass * gravity # Newton's third law: forces come in pairs, and these two # forces are equal in magnitude and opposite in direction ForceNormal = ForceDown ForceKineticFriction = ForceNormal * CoefficientOfKineticFriction AccelerationDueToKineticForce = ForceKineticFriction / puck.mass # velocity = initial velocity * acceleration * time TotalVelocity.x += -AccelerationDueToKineticForce * dt puckX = puck.pos.x + TotalVelocity.x * dt else: puckX = TotalVelocity.x * seconds # position equation: y(t) = y0 + v0*t + .5 * a * t**2 puckZ = TotalVelocity.z * seconds puckVelocityY += -gravity * dt mylabel.text = "velocity x: " + str(TotalVelocity.x) + "/nvelocity y: " + str(puckVelocityY) puck.pos = vector(puckX,puckY,puckZ) if TotalVelocity.x <= 0: finished = True

 

VPython - example - 圆柱体斜上抛滑行运动(X - Y 轴)_第1张图片

你可能感兴趣的:(VPython - example - 圆柱体斜上抛滑行运动(X - Y 轴))