Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Here is a vpython model that looks at a collision between two objects.

View fluker_collision.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
from visual import *
from visual.graph import *
 
gra=gcurve(color=color.cyan)
 
dj=sphere(pos=(-2,0,0), radius=0.15, color=color.red)
dude=sphere(pos=(0,0,0), radius=0.1, color=color.cyan)
 
dj.m=100
dude.m=65
v=5.5
dj.p=vector(v,0,0)*dj.m
dude.p=vector(0,0,0)
 
k=100000 #spring constant for the interaction
sk=0.2 #the distance at which the spring starts to push
 
t=0
dt=0.001
 
while dude.pos.x<1.0:
rate(1000)
F=vector(0,0,0)
if mag(dj.pos-dude.pos)<=sk:
F=k*(sk-mag(dj.pos-dude.pos))*norm(dude.pos-dj.pos)
dt=0.00001
else:
dt=0.001
dj.p=dj.p-F*dt
dude.p=dude.p+F*dt
 
dj.pos=dj.pos+dj.p*dt/dj.m
dude.pos=dude.pos+dude.p*dt/dude.m
t=t+dt
gra.plot(pos=(t,mag(F)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.