| Massdriver VPython Program |
|---|
from visual import * scene.background=(1,1,1) scene.autoscale=1 #Launch setup dt = 0.005 s0 = -0.10 s1 = -0.25 v1 = 0.0 k_rb = 30.0 m_load = 0.05 g_acc = 9.8 tri_y = 0.40 tri_x = 0.40 cos = tri_x/pow(tri_x*tri_x + tri_y*tri_y,0.5) sin = tri_y/pow(tri_x*tri_x + tri_y*tri_y,0.5) while (s1 < 0): if (s1 < s0): v2 = v1 + ((-k_rb*(s1-s0)-m_load*g_acc*sin)/m_load)*dt s2 = s1 + ((v2+v1)/2.0)*dt else: v2 = v1 + (-g_acc*sin)*dt s2 = s1 + ((v2+v1)/2.0)*dt v1 = v2 s1 = s2 print "Launch Velocity = ", v2, " m/s" v1_x = v2*cos v1_y = v2*sin range = v1_x*((v1_y+pow(v1_y*v1_y+2.0*g_acc*tri_y,0.5))/g_acc) floor = box(length=2.25*range, height=0.05, width=1.0, color=(0.9,0.9,0.9)) triang = curve(pos=[(-tri_x,0),(0,0),(0,tri_y),(-tri_x,0)], color=color.red) scene.center = ((tri_x+range)/2.0,0.0,0.0) scene.autoscale=0 trail=curve() rad = 0.04 ball = sphere(pos=(0,tri_y,0), radius=rad, color=color.red) ball.velocity = vector(v1_x,v1_y,0) quit = 0 while (quit == 0): rate(100) ball.pos = ball.pos + ball.velocity*dt if (ball.y < rad): print "Range = ",ball.pos.x," m" quit = 1 else: ball.velocity.y = ball.velocity.y - 9.8*dt trail.append(pos=ball.pos, color=(0,0.9,0))