Tuesday, March 31, 2015

Introduction to 3D Modeling with Vpython Lab

The purpose of this lab was to gain knowledge of how to properly use the Vpython 3D modeling program.

Pictured below is the result of my attempts to solve the first challenge, which involved creating 3 spheres with an arrow pointing out of each one in a specific direction.



Below is the code I used to create this picture:

from __future__ import division
from visual import *

sphere(pos = vector(0,0.5,0), radius = 0.2, color = color.blue)
sphere(pos = vector(0,-0.5,0), radius = 0.2, color = color.cyan)
sphere(pos = vector(-1,0,0), radius = 0.2, color = color.white)
arrow(pos = vector (0,0.5,0), axis = vector (-0.5,0,0), color = color.blue)
arrow(pos = vector (0,-0.5,0), axis = vector (0.5,0.5,0), color = color.cyan)
arrow(pos = vector (-1,0,0), axis = vector (0,-0.5,0), color = color.white)

The following is my attempt to solve the second challenge, which tasked me to create interlocking arrows between the 3 spheres going in a counterclockwise direction.



The code I used for this part of the lab is shown below:

from __future__ import division
from visual import *

Jack=sphere(pos = vector(0,0.5,0), radius = 0.2, color = color.blue)
Crack=sphere(pos = vector(0,-0.5,0), radius = 0.2, color = color.cyan)
Cadillac=sphere(pos = vector(-1,0,0), radius = 0.2, color = color.white)


arrow(pos = vector (0,0.5,0), axis = Cadillac.pos-Jack.pos, color = color.blue)
arrow(pos = vector (0,-0.5,0), axis = Jack.pos-Crack.pos, color = color.cyan)
arrow(pos = vector (-1,0,0), axis = Crack.pos-Cadillac.pos, color = color.white)



print(Jack.pos)

Thursday, March 26, 2015

Dipole Moments, Torque, Electric Fields, and Flux (3/26/2015)

Prediction of the path an electron will take when shot through two oppositely charged layers.






Work and calculations for the electric dipole moment and calculating work done by torque between two oppositely charged particles.


Prediction for the 3D representation of the electric field of a dipole.


3D representations of the electric field of a dipole. The code for which is shown below:
from __future__ import division
from visual import *
 
## constants
k = 9e9 # stands for One Over Four Pi Epsilon-Zero
qe = 1.6e-19  # proton charge
s = 4e-11    # charge separation
R = 3e-10  # display Enet on a circle of radius R
V = 2e-10
scalefactor = 1e-20 # for scaling arrows to represent electric field

## objects
## Represent the two charges of the dipole by red and blue spheres:
plus = sphere(pos=vector(s/2,0,0), radius=1e-11, color=color.red)
qplus = qe   # charge of positive particle
neg = sphere(pos=vector(-s/2,0,0), radius=1e-11, color=color.blue)
qneg = -qplus  # charge of negative particle
 
## calculations
theta = 0
while theta < 2*pi:
    rate(50)   # tell computer to go through loop slowly
    ## Calculate observation location (tail of arrow) using current value of theta:
    Earrow1 = arrow(pos=R*vector(cos(theta),sin(theta),0), axis=vector(1e-10,0,0), color=color.orange)
    
    R1= Earrow1.pos-plus.pos
    R2= Earrow1.pos-neg.pos
    Ef1=((k*qplus)/(mag(R1)**3))
    Ef2=((k*qneg)/(mag(R2)**3))
    Earrow1.axis= ((Ef1*R1)+(Ef2*R2))*scalefactor
    print "Ef1: ", Ef1
    
    ## write instructions below to tell the computer how to calculate the correct
    ## net electric field Enet at the observation location (the position of Earrow):
 
    ## change the axis of Earrow to point in the direction of the electric field at that location
    ## and scale it so it looks reasonable
 
    ## Assign a new value to theta
    theta = theta + pi/12

theta = 0
while theta < 2*pi:
    rate(50)   # tell computer to go through loop slowly
    ## Calculate observation location (tail of arrow) using current value of theta:
    Earrow1 = arrow(pos=R*vector(cos(theta),0,sin(theta)), axis=vector(1e-10,0,0), color=color.orange)
    
    R1= Earrow1.pos-plus.pos
    R2= Earrow1.pos-neg.pos
    Ef1=((k*qplus)/(mag(R1)**3))
    Ef2=((k*qneg)/(mag(R2)**3))
    Earrow1.axis= ((Ef1*R1)+(Ef2*R2))*scalefactor
    print "Ef1: ", Ef1
    
    ## write instructions below to tell the computer how to calculate the correct
    ## net electric field Enet at the observation location (the position of Earrow):
 
    ## change the axis of Earrow to point in the direction of the electric field at that location
    ## and scale it so it looks reasonable
 
    ## Assign a new value to theta
    theta = theta + pi/12

theta = 0
while theta < 2*pi:
    rate(50)   # tell computer to go through loop slowly
    ## Calculate observation location (tail of arrow) using current value of theta:
    Earrow1 = arrow(pos=R*vector(0,cos(theta),sin(theta)), axis=vector(1e-10,0,0), color=color.orange)
    
    R1= Earrow1.pos-plus.pos
    R2= Earrow1.pos-neg.pos
    Ef1=((k*qplus)/(mag(R1)**3))
    Ef2=((k*qneg)/(mag(R2)**3))
    Earrow1.axis= ((Ef1*R1)+(Ef2*R2))*scalefactor
    print "Ef1: ", Ef1
    
    ## write instructions below to tell the computer how to calculate the correct
    ## net electric field Enet at the observation location (the position of Earrow):
 
    ## change the axis of Earrow to point in the direction of the electric field at that location
    ## and scale it so it looks reasonable
 
    ## Assign a new value to theta
    theta = theta + pi/12




theta = 0
scalefactor= 1*(10**(-20.5))
while theta < 2*pi:
    rate(50)   # tell computer to go through loop slowly
    ## Calculate observation location (tail of arrow) using current value of theta:
    Earrow1 = arrow(pos=V*vector(cos(theta),sin(theta),0), axis=vector(1e-10,0,0), color=color.red)
    
    R1= Earrow1.pos-plus.pos
    R2= Earrow1.pos-neg.pos
    Ef1=((k*qplus)/(mag(R1)**3))
    Ef2=((k*qneg)/(mag(R2)**3))
    Earrow1.axis= ((Ef1*R1)+(Ef2*R2))*scalefactor
    print "Ef1: ", Ef1
    
    ## write instructions below to tell the computer how to calculate the correct
    ## net electric field Enet at the observation location (the position of Earrow):
 
    ## change the axis of Earrow to point in the direction of the electric field at that location
    ## and scale it so it looks reasonable
 
    ## Assign a new value to theta
    theta = theta + pi/12

theta = 0
while theta < 2*pi:
    rate(50)   # tell computer to go through loop slowly
    ## Calculate observation location (tail of arrow) using current value of theta:
    Earrow1 = arrow(pos=V*vector(cos(theta),0,sin(theta)), axis=vector(1e-10,0,0), color=color.red)
    
    R1= Earrow1.pos-plus.pos
    R2= Earrow1.pos-neg.pos
    Ef1=((k*qplus)/(mag(R1)**3))
    Ef2=((k*qneg)/(mag(R2)**3))
    Earrow1.axis= ((Ef1*R1)+(Ef2*R2))*scalefactor
    print "Ef1: ", Ef1
    
    ## write instructions below to tell the computer how to calculate the correct
    ## net electric field Enet at the observation location (the position of Earrow):
 
    ## change the axis of Earrow to point in the direction of the electric field at that location
    ## and scale it so it looks reasonable
 
    ## Assign a new value to theta
    theta = theta + pi/12

theta = 0
while theta < 2*pi:
    rate(50)   # tell computer to go through loop slowly
    ## Calculate observation location (tail of arrow) using current value of theta:
    Earrow1 = arrow(pos=V*vector(0,cos(theta),sin(theta)), axis=vector(1e-10,0,0), color=color.red)
    
    R1= Earrow1.pos-plus.pos
    R2= Earrow1.pos-neg.pos
    Ef1=((k*qplus)/(mag(R1)**3))
    Ef2=((k*qneg)/(mag(R2)**3))
    Earrow1.axis= ((Ef1*R1)+(Ef2*R2))*scalefactor
    print "Ef1: ", Ef1
    
    ## write instructions below to tell the computer how to calculate the correct
    ## net electric field Enet at the observation location (the position of Earrow):
 
    ## change the axis of Earrow to point in the direction of the electric field at that location
    ## and scale it so it looks reasonable
 
    ## Assign a new value to theta
    theta = theta + pi/12



Depictions for the electric field lines and flux activity.


Flux demonstration. The nails are the electric field lines, and the wire hoop is used to show how position affects the amount of field lines that are able to pass through a given surface.


Calculations for the mathematical representation of flux.



Calculations and work done for flux through a cube.

Tuesday, March 24, 2015

Electric Fields and 3D Modeling (3/24/2015)

Redefining gravitational field definitions in terms of electrical fields.

Derived formula of an electric field.

2D representation of the electric field of a single charged particle. The point was to show how difficult it is to see on a board. 3D modeling will be used later.






More work and calculations done for the Calculating and Displaying the Electric Field of a Single Charged Particle lab. This is the Whiteboard Work part of the activity.









Work done for part 4 and 5 of the Electric Field lab. The coding for this activity is as follows:
from visual import *

## CONSTANTS
k = 9e9   ## OneOverFourPiEpsilonZero
q1 = 1.6e-19
## OBJECTS
particle = sphere(pos=vector(1e-10, 0, 0), radius = 2e-11, color=color.red)
xaxis = cylinder(pos=(-5e-10,0,0), axis=vector(10e-10,0,0),radius=.2e-11)
yaxis = cylinder(pos=(0,-5e-10,0), axis=vector(0,10e-10,0),radius=.2e-11)
zaxis = cylinder(pos=(0,0,-5e-10), axis=vector(0,0,10e-10),radius=.2e-11)
## the position of the arrow is the observation location:
Earrow1 = arrow(pos=vector(3.1e-10,-2.1e-10,0), axis = vector(1e-10,0,0), color=color.orange)
Earrow2 = arrow(pos=vector(3.1e-10,2.1e-10,0), axis = vector(1e-10,0,0), color=color.orange)
Earrow3 = arrow(pos=vector(-1.1e-10,-2.1e-10,0), axis = vector(1e-10,0,0), color=color.orange)
Earrow4 = arrow(pos=vector(-1.1e-10,2.1e-10,0), axis = vector(1e-10,0,0), color=color.orange)
Earrow5 = arrow(pos=vector(1e-10,0,3e-10), axis = vector(1e-10,0,0), color=color.orange)
Earrow6 = arrow(pos=vector(1e-10,0,-3e-10), axis = vector(1e-10,0,0), color=color.orange)
## CALCULATIONS
R1=Earrow1.pos-particle.pos
R2=Earrow2.pos-particle.pos
R3=Earrow3.pos-particle.pos
R4=Earrow4.pos-particle.pos
R5=Earrow5.pos-particle.pos
R6=Earrow6.pos-particle.pos

Ef1=((k*q1)/(mag(R1)**3))
Ef2=((k*q1)/(mag(R2)**3))
Ef3=((k*q1)/(mag(R3)**3))
Ef4=((k*q1)/(mag(R4)**3))
Ef5=((k*q1)/(mag(R5)**3))
Ef6=((k*q1)/(mag(R6)**3))


## write instructions below to tell the computer how to calculate the correct
## electric field E1 at the observation location (the position of Earrow1):
## change the axis of Earrow1 to point in the direction of the electric field at that location
## and scale it so it looks reasonable

scalefactor= 1e-20
Earrow1.axis= Ef1*R1*scalefactor
Earrow2.axis= Ef2*R2*scalefactor
Earrow3.axis= Ef3*R3*scalefactor
Earrow4.axis= Ef4*R4*scalefactor
Earrow5.axis= Ef5*R5*scalefactor
Earrow6.axis= Ef6*R6*scalefactor

print "Ef1: ", Ef1
print "Ef2: ", Ef2
print "Ef3: ", Ef3
print "Ef4: ", Ef4
print "Ef5: ", Ef5
print "Ef6: ", Ef6







## additional observation locations; do the same thing for each one




Work and calculations for the electric field from two point charges question.




Data from the excel portion of the problem shown four pictures above.






Work done answering the "Electric Field Due to a Differential Charge" activity.