Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from __future__ import division
- from visual import *
- #Initial vals
- e = 1.6e-19
- oofpez = 9e9
- scalefactor = 1
- Obslocation = vector(1.8e-9,1e-9,0)
- theta = 0
- r = 2e-9
- #objects
- atom1 = sphere(pos=vector(.5e-9,0,0), radius=1e-10,color=color.blue)
- atom1.q = -e
- atom2 = sphere(pos = vector(-.5e-9,0,0), radius = 1e-10, color = color.red)
- atom2.q = e
- #atom3 = sphere(pos = vector(-171e-9,0,0), radius = 10e-9, color = color.blue)
- #atom3.q = -e
- #Calculations
- while theta < 2*pi:
- Obslocation = vector(sin(theta)*1e-8,.4*cos(theta)*1e-8,0)#sin(theta)*1e-8)
- r1 = Obslocation - atom1.pos
- r2 = Obslocation - atom2.pos
- #r3 = Earrow.pos - atom3.pos
- r1mag = mag(r1)
- r2mag = mag(r2)
- #r3mag = mag(r3)
- r1hat = r1 / r1mag
- r2hat = r2 / r2mag
- #r3hat = r3 / r3mag
- E1 = oofpez * (atom1.q / r1mag**2) * r1hat
- E2 = oofpez * (atom2.q / r2mag**2) * r2hat
- #E3 = oofpez * (atom3.q / r3mag**2) * r3hat
- Enet = E1 + E2# + E3
- scalefactor = 1e-9/mag(Enet)
- #Earrow.axis = scalefactor*Enet
- Earrow = arrow(pos = Obslocation, axis = Enet*scalefactor, color = color.orange)
- Obslocation2 = vector(sin(theta)*1e-8,0,.4*cos(theta)*1e-8)
- Earrow = arrow(pos = Obslocation2, axis = Enet*scalefactor, color = color.orange)
- theta = theta + pi/6
- print "The observation location (XY) is ", Obslocation, "m"
- print "The observation location (XZ) is ", Obslocation2, "m"
- print "The magnitude of E1 field = ",mag(E1),"N/C"
- print "The magnitude of E2 field = ",mag(E2),"N/C"
- #print "The magnitude of E3 field =",mag(E3),"N/C"
- print "Enet = ",Enet,"N/C"
- print "------------------------------------------------------------"
- #output
- #print "The observation location is ", Obslocation, "m"
- #print "The magnitude of E1 field = ",mag(E1),"N/C"
- #print "The magnitude of E2 field = ",mag(E2),"N/C"
- #print "The magnitude of E3 field =",mag(E3),"N/C"
- #print "Enet = ",Enet,"N/C"
Advertisement
Add Comment
Please, Sign In to add comment