Instantly share code, notes, and snippets.

# orzelc/tape_sim_toy.py Created Jan 18, 2014

What would you like to do?
VPython mock-up of charged tape problem as a mass-on-a-spring, because the equations are easier to deal with.
 from visual import * # Constants and other definitions e=1.6e-19 k=9e9 g=9.80 length=0.21 height=0.3 sep=0.1524 mass=0.0003 charge=2.0e-8 scale=1 spring=100 drag=0.001 # Pivot points for the pendulums pivot1=sphere(pos=vector(sep/2,height,0), radius=0.02, color=color.white) pivot2=sphere(pos=vector(-sep/2,height,0), radius=0.02, color=color.white) # The suspended point charges that stand in for charged tapes mass1=sphere(pos=vector(sep/2, height-length,0), radius=0.02, color=color.green) mass1.m=mass mass1.q=charge mass1.p=vector(0,0,0) mass1.pos.y=mass1.pos.y-mass1.m*g/spring #stretch to account for the mass mass2=sphere(pos=vector(-sep/2,height-length,0), radius=0.02, color=color.yellow) mass2.m=mass mass2.q=charge mass2.p=vector(0,0,0) mass2.pos.y=mass2.pos.y-mass2.m*g/spring #stretch to account for the mass # Strings for the pendulum, to make it look pretty string1=cylinder(pos=pivot1.pos, axis=mass1.pos-pivot1.pos, radius=0.005, color=color.white) string2=cylinder(pos=pivot2.pos, axis=mass2.pos-pivot2.pos, radius=0.005, color=color.white) # Gravitational forces fgrav1=mass1.m*g*vector(0,-1,0) fgrav2=mass2.m*g*vector(0,-1,0) # Treating the strings as springs to get the right tension force stretch1=string1.axis.mag-length stretch2=string2.axis.mag-length ft1=-(spring*stretch1)*(string1.axis/string1.axis.mag) ft2=-(spring*stretch2)*(string2.axis/string2.axis.mag) # Electrostatic force between the charged balls r=mass1.pos-mass2.pos rhat=r/r.mag felec1=-(k*mass1.q*mass2.q/r.mag2)*rhat felec2=-felec1 # Arrows showing the force fgarr1=arrow(pos=mass1.pos, axis=scale*fgrav1, color=color.blue) fgarr2=arrow(pos=mass2.pos, axis=scale*fgrav2, color=color.blue) ftarr1=arrow(pos=mass1.pos, axis=scale*ft1, color=color.magenta) ftarr2=arrow(pos=mass2.pos, axis=scale*ft2, color=color.magenta) felarr1=arrow(pos=mass1.pos, axis=scale*felec1, color=color.cyan) felarr2=arrow(pos=mass2.pos, axis=scale*felec2, color=color.cyan) # Loop parameters tmax=5 t=0 dt=0.001 while t