Wednesday, May 20, 2015

VPython Assignment

from __future__ import print_function, division
from visual import *

#Constants
k = 8.988e9

#Charged Rod 1
rod1 = cylinder(pos=(1,-2,0),axis=(0,4,0),radius=.1,color=color.red)
q1 = 1e-9

#Charged Rod 2
rod2 = cylinder(pos=(-1,-2,0),axis=(0,4,0),radius=.1,color=color.blue)
q2 = -1e-9

#Observation Locations
p = vector(0,0,0)
r1= mag(p-rod1.pos)
r2= mag(p-rod2.pos)
V1=k*q1/r1
V2=k*q2/r2
Vnet=V1+V2

while p.y < 1 and p.x < 1:
    sphere(pos=p,radius=.1)
    label(pos=p,xoffset=-20,yoffset=20,text="V=%1.2f" % Vnet)
    p.x += .2
    p.y += .2
I was supposed to get values other than all zeros, but I couldn't figure out how to put the charges on the rods, which is what I think the problem is.

No comments:

Post a Comment