lab6 - d scene.autoscale=0 #Turns off autoscaling. Set to 1...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
from __future__ import division from visual import * f ## Constants # # In this section, define any constants you may need mofp = 1e-7 q = 1.6e-19 bscale = .5e-8 b ## Objects # #Change the initial vector position of the proton below: proton = sphere(pos=vector(-4e-10,0,0), radius=1e-11, color=color.red) p #Change the observation location (position of the tail of the arrow) below: barrow1=arrow(pos=vector(0,8e-11,0), axis=vector(0,0,0), color=color.cyan) b #Add more arrows to find magnetic field at other observation locations. barrow2=arrow(pos=vector(0,-8e-11,0), axis=vector(0,0,0), color=color.cyan) barrow3=arrow(pos=vector(0,0,8e-11), axis=vector(0,0,0), color=color.cyan) barrow4=arrow(pos=vector(0,0,-8e-11), axis=vector(0,0,0), color=color.cyan) #Set axis to (0,0,0) initially and update it in the loop. # ## Initial values # velocity = vector(4e4,0,0) # Enter the proton's velocity deltat = 1e-16 # Adjust if program runs too slowly or too quickly
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: d scene.autoscale=0 #Turns off autoscaling. Set to 1 to turn it back on. s ## Loop # while proton.x<5e-10: rate(10) # For each magnetic field vector: # 1. Calculate r and rhat r1 = barrow1.pos - proton.pos rmag1 = mag(r1) rhat1 = r1/rmag1 r2 = barrow2.pos - proton.pos rmag2 = mag(r2) rhat2 = r2/rmag2 r3 = barrow3.pos - proton.pos rmag3 = mag(r3) rhat3 = r3/rmag3 r4 = barrow4.pos - proton.pos rmag4 = mag(r4) rhat4 = r4/rmag4 # 2. Calculate the magnetic field vector B1 = mofp*(q*cross(velocity, rhat1))/rmag1**2 B2 = mofp*(q*cross(velocity, rhat2))/rmag2**2 B3 = mofp*(q*cross(velocity, rhat3))/rmag3**2 B4 = mofp*(q*cross(velocity, rhat4))/rmag4**2 # 3. Calculate the new axis of the arrow. Scale it appropriately. barrow1.axis = B1*bscale barrow2.axis = B2*bscale barrow3.axis = B3*bscale barrow4.axis = B4*bscale # Update the proton's position proton.pos = proton.pos + velocity*deltat...
View Full Document

This note was uploaded on 09/12/2011 for the course PHYISCS 2212 taught by Professor Shatz during the Spring '10 term at Georgia Institute of Technology.

Page1 / 2

lab6 - d scene.autoscale=0 #Turns off autoscaling. Set to 1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online