Professional Documents
Culture Documents
7 VPython
GlowScript 2.6 VPython
from visual import *
# - CODE ANNOTATIONS -
# We are interested in your physical interpretation of the code below (except in 'Annotation
9').
# With that in mind, your answers should reflect your understanding of the relevant physics
ideas.
# Write 3-5 sentences (at most!) responding to the questions associated with each of the
ten annotations.
# Write your response after the 'Ans:' prompt below each annotation.
#
# ANNOTATION 1 - What is the purpose of the following three lines? Why do you need a
scale factor? What happens if you change the scale factor?
# Ans: oofpez: Capability of a vaccuum to permit electric field lines (1/4 pi epsilon zero)
qproton: Charge of the proton. Scale factor: how much the arrow/resultant vector is
enlarged or decreased by. S.F. represents arrows magnitude and desired length. We need
this to show the resultant vector (magnitude and direction of "r" vector). Changing the scale
factor will change the position of the "r" vector.
oofpez=9e9
qproton=1.6*10**-19
scalefactor=1e-20
# NOTE: in glowscript, you can right click and drag to rotate the view
# NOTE: We can bring the sphere's properties back up later using lines of code such as:
# position = particle.pos
# radius = particle.radius
# color=particle.color
# We can also change these values after the fact, if we want! (For example, we could
change the position using 'particle.pos = vector(1,0,0)')
# ANNOTATION 6 - What does this arrow represent? What are the arrow's important
features?
# Ans: Direction of the travel of the proton. The important features of is length and the
direction. Both these features give us a vector which has a direction and a magnitude.
ra = arrow(pos=(particle.pos), axis=(r), color=color.green)
rmag = r.mag # NOTE: This calculates the magnitude of the relative position vector
# 'vector.mag' is the easy way to do this, but you could also calculate it explicitly:
#
# rmag=sqrt(r.x**2 + r.y**2 + r.z**2), where r.x, r.y and r.z are the x, y and z components of
the vector r, respectively.
print ("The magnitude of r is", rmag)
# ANNOTATION 9 - Code: how would you change this line to print the size of the electric
field instead?
# Ans: print(vector.mag)
print ("The Electric field vector at the observation location is", E)
# ANNOTATION 10 - What does this create? What does the scale factor do?
# Ans: This creates the resulatant vector. The resultant vector should show the direction of
the electric field and its corresponding value (magnitude).
ea = arrow(pos=(obslocation), axis=scalefactor*E, color=color.orange)
# -----------------\
# <~> EXTENSION <~> |
# _________________/
veclist=[]
obsdist=3*10**(-10)
# So, for my nested for-loops, I know I need observation locations that are both + and -3e-
10m away from the particle along the x,
# y and z axes. I need to account for both the + and - directions (two cases) along the three
axes (three cases)
# So that's
for direction in range(2): # 0 = negative direction, 1 = positive direction
for axis in range(3): # 0 = x axis, 1 = y axis, 2 = z axis
tempvec=[0,0,0]#vector(0,0,0) # This starts me off with a list of three 0s (0,0,0)
tempvec[axis]=(2*direction - 1)*obsdist # I then replace the value in slot 'axis' (see
above where I define which number
# is which axis) with the position of the observation location
along that axis
my_vec=vector(tempvec[0],tempvec[1],tempvec[2]) # I then use the three tempvec
entries to define my observation location!
veclist.append(my_vec+particle.pos) # we then each observation location to the list of
observation locations
# By the end of these for-loops, every obsloc we need will have been added to the list!
for obs in veclist: # This for-loop sets 'obs' equal to a different item in 'veclist' each loop, and
uses that value of obs
# for the code located in the loop itself
r=obs-particle.pos
E=oofpez*qproton*r/r.mag**3
obsarrow=arrow(pos=obs,axis=E*1e-20,color=color.orange) # The rest of this is what we
did earlier!