Write a VPython program to calculate and display the magnetic field due to a moving proton in region of space surrounding the path of the proton. Initial conditions: start the proton at location <-2e-10, 0, 0>, with velocity 3e5 m/s in the +x direction. A reasonable value for the radius of the sphere representing the proton is about 3e-12 m (reasonable in the sense that the proton will be visible in your display - physically the radius of a proton is much smaller!) At 64 observation locations located on a cylindrical surface surrounding the path of the proton, a distance of 3e-11 m radially outward from the proton's path, create arrows to visualize the magnetic field at each location. You will update these arrows each time you move the proton, so you see the magnetic field in space changing as the proton moves. You will need to scale the arrows, as usual, to make an understandable display.
VPython has a built-in cross product function to make it easy to find vector cross products.
= ___________________________
Note that the cross product produces a vector which is perpendicular to the plane containing the original vectors.
from visual import *
from __future__ import division
C = cross(A,B)
Why don't you see the arrow? _____________________
To calculate the magnetic field
at the observation location due to the moving proton at its current location,
you need a vector which, as usual,
extends from the source particle to the observation location.
Is the direction of the magnetic field you calculated correct? Check with the right-hand rule.
Do you in fact see a cyan arrow at the observation location, pointing in the appropriate direction?
A computer animation of the motion of an object uses the same principle as a movie or a flip book does. You display the object at successive locations, each at a slightly later time; to your eye, the motion can look continuous. You calculate the position of the object, and it is displayed in that position. You calculate where the object will be a very short time deltat later, and change its position to the new location, so it is displayed in the new location.
You will use the relation between velocity (a vector) and position (a vector) to calculate the position of a moving proton at successive times, separated by a short time step Dt. Remember that, in vector terms:
, or
In VPython, this translates to a statement like:
proton.pos = proton.pos + velocity*deltat
where velocity is a vector quantity which you have initialized earlier in the program.
This statement may look odd to
you if you have not had much programming experience. The equals sign here
has the meaning of ``assignment" rather than equality. This instruction tells
VPython to read up the old position of the proton, add to it the quantity
, and store
the new position as the current position of the proton. This will automatically
move the proton to the new position.
scene.autoscale = 0
As the proton moves, the magnetic field that it makes at the observation location changes. The program we are writing is different from the others we've written to calculate electric fields, because we want to observe the magnetic field at a particular location changing with time. We want to create only one arrow at the location, but change its magnitude and direction as necessary.
proton.pos = proton.pos + velocity*deltat
Did the magnetic field at the observation location increase in magnitude as the proton approached, and decrease as the proton moved away? ________________
Did you find yourself inside the magnetic field vector? You will need a different scale factor now.
We want to observe the magnetic field at more than one location as the proton moves.
obsarrows = []
for theta in arange(0,2*pi,pi/4):
for x in arange(-1.8e-10, 2.0e-10, 0.2e-10):
obsarrows.append(arrow(pos=(x,3e-11*sin(theta),3e-11*cos(theta)),
axis=vector(0,0,0), color=color.cyan))
You will need to modify your code inside the loop to calculate B at each location and update every arrow each time you move the proton one step. This will involve a nested loop (a loop inside a loop). Pay attention to indenting. The basic organization is:
while proton.pos.x < 1e-10:
## your code to move the proton here
for ba in obsarrows:
## put your code to calculate magnetic fields here. get indentation correct.
You may wish to increase deltat slightly if your program runs too slowly.