简体   繁体   中英

How to simulate multiple projectile trajectories in glowscript/VPython?

I am attempting to simulate multiple projectiles with random angle theta and speeds. However, I have no background in physics and am having a hard time with the math. I currently have the following code:

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)
  

Essentially you need to write a code to solve Newton's Second Law, which algorithm you will use its up to you. The force term may be module as you wish, just gravity, air resistance and many others.

To do your numerical simulation you may use Euler's algorithm, Adams Bashforth and many others.

If you look for those ingredients, certainly you will find a straightforward way to solve your problem.

Here there are some useful links:

Scientific Programming with Python , Introduction to Computational Physics , Numerical methods for ordinary differential equations

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM