Skip to content

Instantly share code, notes, and snippets.

@xbeastguyx
Created November 14, 2019 18:52
Show Gist options
  • Save xbeastguyx/a34cd25b403e3559ed7eb42b52958e0e to your computer and use it in GitHub Desktop.
Save xbeastguyx/a34cd25b403e3559ed7eb42b52958e0e to your computer and use it in GitHub Desktop.
from __future__ import division
from visual import *
from physutil import *
from visual.graph import *
#Window setup
scene.center = (0,0,0)
scene.range = 2000
#Objects
Station = cylinder(pos=(0,0,0), radius=500, axis=(0,-30,0), material=materials.silver)
DP = sphere(pos=vector(0,0,0), radius=30, color=color.green)
AP = sphere(pos=vector(-500,900,0), radius=90, color=color.red)
#Parameters and Initial Conditions
mAP = 100
vAP = vector(225,-400,0)
pAP = mAP*vAP
finalV = vector(-450,800,0)
vDP = ((120 * finalV)- pAP)/ 20
APRadius = vector(AP.radius, AP.radius, AP.radius)
#Time and time step
t = 0
dt = 0.001
#Graph
eGraph = PhysGraph()
#Calculation Loop
while t >= 0:
rate(500)
if(mag(DP.pos-AP.pos)>= DP.radius + AP.radius):
AP.pos = AP.pos + (pAP/mAP)*dt
DP.pos = DP.pos + (vDP*dt)
KE = 0.5*mag(finalV)**2/mAP
eGraph.plot(t, KE)
else:
AP.pos = AP.pos + (finalV *dt)
DP.pos = DP.pos + (finalV *dt)
KE = 0.5*mag(vAP)**2/mAP
eGraph.plot(t, KE)
t = t + dt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment