如何在glowscript/VPython中模拟多个弹丸轨迹?

时间:2021-06-12 05:11:53

标签: python physics vpython

我正在尝试模拟具有随机角度θ和速度的多个射弹。但是,我没有物理学背景,并且在数学方面遇到困难。 我目前有以下代码:

GlowScript 3.1 VPython
import random
ground=box(pos=vector(0, -.2, 0), size=vector(10, .4, 3), color=color.green)
start = sphere(pos=vector(0, 0, 0), radius=.1, color=color.red)
g=vector(0, -9.8, 0)
nails={}
for i in range(20):
  v0 = random.randint(100, 250)
  theta = random.randint(0, 180)*pi/180
  mass=0.2
  proj=sphere(pos=vector(0, 0, 0), radius=.1, color=color.blue)
  proj.p=proj.m*v0*vector(cos(theta),sin(theta),0)
  

1 个答案:

答案 0 :(得分:0)

本质上,您需要编写代码来解决牛顿第二定律,您将使用哪种算法取决于您。力项可以是你想要的模数,只是重力、空气阻力和许多其他的。

要进行数值模拟,您可以使用 Euler 算法、Adams Bashforth 和许多其他算法。

如果您寻找这些成分,您肯定会找到解决问题的直接方法。

这里有一些有用的链接:

Scientific Programming with Python Introduction to Computational PhysicsNumerical methods for ordinary differential equations

相关问题