CodeCodeCode

PYHS 272 - LAB02

Sep 7th, 2011
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.93 KB | None | 0 0
  1. from __future__ import division
  2. from visual import *
  3.  
  4. #Initial vals
  5. e = 1.6e-19
  6. oofpez = 9e9
  7. scalefactor = 1
  8. Obslocation = vector(1.8e-9,1e-9,0)
  9. theta = 0
  10. r = 2e-9
  11.  
  12.  
  13. #objects
  14. atom1 = sphere(pos=vector(.5e-9,0,0), radius=1e-10,color=color.blue)
  15. atom1.q = -e
  16. atom2 = sphere(pos = vector(-.5e-9,0,0), radius = 1e-10, color = color.red)
  17. atom2.q = e
  18. #atom3 = sphere(pos = vector(-171e-9,0,0), radius = 10e-9, color = color.blue)
  19. #atom3.q = -e
  20.  
  21. #Calculations
  22. while theta < 2*pi:
  23.     Obslocation = vector(sin(theta)*1e-8,.4*cos(theta)*1e-8,0)#sin(theta)*1e-8)
  24.     r1 = Obslocation - atom1.pos
  25.     r2 = Obslocation - atom2.pos
  26.     #r3 = Earrow.pos - atom3.pos
  27.     r1mag = mag(r1)
  28.     r2mag = mag(r2)
  29.     #r3mag = mag(r3)
  30.     r1hat = r1 / r1mag
  31.     r2hat = r2 / r2mag
  32.     #r3hat = r3 / r3mag
  33.     E1 = oofpez * (atom1.q / r1mag**2) * r1hat
  34.     E2 = oofpez * (atom2.q / r2mag**2) * r2hat
  35.     #E3 = oofpez * (atom3.q / r3mag**2) * r3hat
  36.     Enet = E1 + E2# + E3
  37.     scalefactor = 1e-9/mag(Enet)
  38.     #Earrow.axis = scalefactor*Enet
  39.     Earrow = arrow(pos = Obslocation, axis = Enet*scalefactor, color = color.orange)
  40.     Obslocation2 = vector(sin(theta)*1e-8,0,.4*cos(theta)*1e-8)
  41.     Earrow = arrow(pos = Obslocation2, axis = Enet*scalefactor, color = color.orange)
  42.     theta = theta + pi/6
  43.     print "The observation location (XY) is ", Obslocation, "m"
  44.     print "The observation location (XZ) is ", Obslocation2, "m"
  45.     print "The magnitude of E1 field = ",mag(E1),"N/C"
  46.     print "The magnitude of E2 field = ",mag(E2),"N/C"
  47.     #print "The magnitude of E3 field =",mag(E3),"N/C"
  48.     print "Enet = ",Enet,"N/C"
  49.     print "------------------------------------------------------------"
  50. #output
  51. #print "The observation location is ", Obslocation, "m"
  52. #print "The magnitude of E1 field = ",mag(E1),"N/C"
  53. #print "The magnitude of E2 field = ",mag(E2),"N/C"
  54. #print "The magnitude of E3 field =",mag(E3),"N/C"
  55. #print "Enet = ",Enet,"N/C"
Advertisement
Add Comment
Please, Sign In to add comment