this python code is supposed to graph the motion of a projectile but i do not know how to stop it from 'sinking' (it goes below the x axis a bit) and i don't know if it is accurate.i also want it in Si units but i don't think it is doing that right.
from __future__ import division
from visual import *
from visual.graph import *
print"""
type stat(p1,p2,p3,v1,v2,v3,a1,a2,a3)
then type run()
an example is stat(0,4,0,1,2,0,0,-9,0)"""
def stat(pos_x,pos_y,pos_z,vel_x,vel_y,vel_z,acc_x,acc_y,acc_z):
pos = vector(0,0,0)
pos.x = pos_x
pos.y = pos_y
pos.z = pos_z
velocity = vector(0,0,0)
velocity.x = vel_x
velocity.y = vel_y
velocity.z = vel_z
acceleration = vector(0,0,0)
acceleration.x = acc_x
acceleration.y = acc_y
acceleration.z = acc_z
dt=.0001
t=0
posgraph=gcurve(color=color.green)
while pos.y>=0:
pos+=t*velocity+(t*t*acceleration)/2
posgraph.plot(pos=(pos.x,pos.y))
t+=dt
if pos.y<0:
print "time:" ,t
print 'Position',pos
#print 'velocity',velocity
print " "
when i run it with this
stat(0,4,0,1,2,0,0,-9,0)
it outputs this:
time: 0.6674
Position <2226.78, -0.564899, 0>