Sunday, April 25, 2010

Haley's Visual Python - Diver

Project Summery:

For my visual python project, I decided on one extensive project comprised of three smaller components. The project is of a diver, jumping on a spring board about a pivot and then going into projectile motion off a jump and then slowing down in the pool due to the drag force. The diver starts some distance away from the pivot point on the diving board and then oscillates in simple harmonic motion up and down for a wile, till jumping off the board and continuing in projectile motion in the x and y direction. Then the diver enters the pool, where both the drag force and the gravitational force act on it. This project is suppose to simulate the motions and different components of physics a diver goes through on a simple jump.

videos:
(oscillates longer in reality... but could not film and adjust frame at same time)





Code:

from __future__ import division # decimal rule
from visual import *

divingboard = frame()
spring = helix(frame=divingboard, pos=(-2,0,1), axis=(0,2,0), raduis=2.0, length=5, thickness=(1/4))
board = box(frame=divingboard, pos=(1,2,1), axis=(2,0,0), size=(18,0.5,3), color=color.blue)
pivot = cone(frame=divingboard, axis=(0,1.75,0), pos=(-6,0,1), radius=(1), length=(2))

diver = frame()
body = ellipsoid(frame=diver, pos=(0,0,0), axis=(1,0,0),length=.3, height=1.5, width=.75)
head = sphere(frame=diver, pos=(.0,.75,0), radius=.3)
armR = curve(frame=diver, pos=[(0,.18),(.4,0),(.3,-.5)], radius=0.03)
armL = curve(frame=diver, pos=[(0,.18),(-.4,0),(-.3,-.5)], radius=0.03)
legR = curve(frame=diver, pos=[(.07,-.5),(.3,-1),(.25,-1.5),(.5,-1.5)], radius=0.03)
legL = curve(frame=diver, pos=[(-.07,-.5),(-.3,-1),(-.25,-1.5),(-.5,-1.5)], radius=0.03)
diver.pos=(9.5,3.85,1)
diver.axis=(0,0,1)
diver.velocity=vector(0,0,0)

#constants
board.mass = 50
k = 30000.0
B = 100 # apt to change - drag constant

ground = frame()
floorL = box(frame=ground, pos=(-5.5,0,1), size=(10,0.2,30), color=color.orange, material=materials.rough)
floorR = box(frame=ground, pos=(34.5,0,1), size=(10,0.2,30), color=color.orange, material=materials.rough)
floorT = box(frame=ground, pos=(14.5,0,-15), size=(50,0.2,10), color=color.orange, material=materials.rough)
floorB = box(frame=ground, pos=(14.5,0,15), size=(50,0.2,10), color=color.orange, material=materials.rough)
poolT = box(frame=ground, pos=(15,-10,-10), size=(31,20,0.2), color=color.green)
poolB = box(frame=ground, pos=(15,-10,10), size=(31,20,0.2), color=color.green)
poolL = box(frame=ground, pos=(-0.5,-10,0), size=(0.2,20,20), color=color.green)
poolR = box(frame=ground, pos=(30,-10,0), size=(0.2,20,20), color=color.green)
poolfloor = box(frame=ground, pos=(15,-20,0), size=(31,0.2,20), color=color.green)


pool = frame()
water = box(frame=pool, pos=(14.5,-11,0), size=(30,18,20), color=color.cyan, opacity=0.5)


#costants for person
#mass
body.mass = 40
head.mass = 5
armR.mass = 7.5
armL.mass = 7.5
legR.mass = 10
legL.mass = 10
diver.mass = (body.mass+head.mass+armR.mass+armL.mass+legR.mass+legL.mass) #mass of the body total
g = 9.8 # magnitude of gravitational field in m/s^2
r = (diver.pos-pivot.pos) #radius of the moment arm

#forces
F_grav = vector(0,-diver.mass*g,0)*diver.mass # gravitational force



# constants of simulation - note upward and rightward are + (positive) in sign
g = 9.8 # magnitude of gravitational field in m/s^2
m = 1 # mass kilograms
dt = 0.01 # time step in seconds
t = 0 # elapsed time
omega = 0 # initial angular velocity
alpha = 0 # initial angular acceleration
theta = 0.0 # intial angle
# distances
a = 3.0 # pivot to spring
b = 7 # pivot to board cm
c = 16 # pivot to person
rotInertia = 25880 #constant 1/12*ml^2 + Sat-cm board + sat person

t = 0
while (t < 10):
rate(100)
t = t + dt
# calculate torques
torque = -k*a**2*sin(theta)*cos(theta)+(diver.mass*b*g*cos(theta))+(board.mass*c*g*cos(theta))
# calculate angular acceleration
alpha = torque / rotInertia #
omega = omega + alpha*dt
theta = theta + omega*dt
# rotate the system a little bit
divingboard.rotate(angle = omega*dt, axis = (0,0,1), origin = (-6,0,1))
diver.rotate(angle = omega*dt, axis = (0,0,1), origin = (-6,0,1))
spring.length = 1+a*sin(theta)


#projectile motion
t = 0
while diver.pos.y>-2:
t = t + dt
rate(100)
#diver.pos.x = diver.pos.x + diver.velocity*cos(theta)*t
#diver.pos.y = diver.pos.y + diver.velocity*sin(theta)*t+1/2*g*t**2
alpha = torque/rotInertia
acceleration = c*alpha
accelerationX = acceleration*cos(theta)
if t==5:
accelerationY = acceleration*sin(theta)
else:
accelerationY = -9.8
diver.velocity.x = diver.velocity.x + accelerationX*t
diver.velocity.y = diver.velocity.y + accelerationY*t
diver.pos.x = diver.pos.x + diver.velocity.x*dt + 1/2*accelerationX*dt**2
diver.pos.y = diver.pos.y + diver.velocity.y*dt + 1/2*accelerationY*dt**2





t=0
while diver.pos.y<=-2:
t = t + dt
rate(100)
F_grav = diver.mass*g
F_drag = B*diver.velocity.y #sqrt(diver.velocity.y**2+diver.velocity.x**2)
#F_netx = F_drag*cos(theta)
F_nety = F_drag*sin(theta) - F_grav
#accelerationX = F_netx/diver.mass
accelerationY = F_nety/diver.mass
#diver.velocity.x = diver.velocity.x + accelerationX*t
diver.velocity.y = diver.velocity.y + accelerationY*t
#diver.pos.x = diver.pos.x + diver.velocity.x*dt + 1/2*accelerationX*dt**2
diver.pos.y = diver.pos.y + diver.velocity.y*dt + 1/2*accelerationY*dt**2
if diver.pos.y<-17.5:
diver.velocity.y = -1*diver.velocity.y
else:
diver.velocity.y = diver.velocity.y

Monday, April 12, 2010

Description: This is a project on a bird pooping on a statue and the statue attempting to defend itself with a cannon aimed in the air at an angle. The bird flies in at a constant velocity in the x and y directions. At a specified time, different poop particles, each of different mass, are dropped from the bird. Then, with gravity, drag and eventually friction and normal forces acting on them, the poos drop toward the statue (or at least near it). Meanwhile the statue fires its gun at the bird in anticipation of its fly over and attempts to hit it with two bullets of different mass. These encounter the same force as the poo particles.

Code:
from __future__ import division
from visual import*

#bird
bird=frame()
headb= sphere(frame=bird, pos=(0,0,0), radius=1, color=color.blue)
bodyb= sphere(frame=bird, pos=(-3,0,0), radius=2, color=color.blue)
tailb= pyramid(frame=bird, pos=(4.5,0,0), size=(2,.125,2), color=color.blue)
tailb.rotate(angle=3.142, axis=(0,0,-1), origin=(0,0,0))
wing=pyramid(frame=bird, pos=(2,0,0), size=(2.5,.125,12), color=color.blue)
wing.rotate(angle=3.142, axis=(0,0,-1), origin=(0,0,0))
beak= cone(frame=bird, pos=(-1,0,0), axis=(3,0,0), radius=.5, color=color.blue)
bird.pos=(-50,20,0)
bird.velocity=vector(5,0,0)

#statue
stat=frame()
heads= sphere(frame=stat, pos=(0,0,0), radius=.5, color=color.red)
bodys= cylinder(frame=stat, pos=(0,-.5,0), axis=(0,-2,0), radius=1, color=color.red)
arm = cylinder(frame=stat, pos=(-2,-.75,0), axis=(4,0,0), radius=.25, color=color.red)
legL= cylinder(frame=stat, pos=(-.4,-2,0), axis=(0,-2,0), radius=.33, color=color.red)
legR= cylinder(frame=stat, pos=(.4,-2,0), axis=(0,-2,0), radius=.33, color=color.red)
stat.pos=(0,4,0)

#ground
ground=frame()
ground= box(frame=ground, pos=(0,0,0), size=(100,.25,100), color=color.green)

#dropping
dropping1= sphere(pos=(-50,20,0), radius=.25, color=color.white)
dropping1.velocity=vector(5,0,0)
dropping1.trail=curve(color=dropping1.color)

dropping2= sphere(pos=(-50,20,0), radius=.25, color=color.yellow)
dropping2.velocity=vector(5,0,0)
dropping2.trail=curve(color=dropping2.color)

dropping3= sphere(pos=(-50,20,0), radius=.25, color=color.orange)
dropping3.velocity=vector(5,0,0)
dropping3.trail=curve(color=dropping3.color)

#gun
gun=cylinder(frame=stat, pos=(4,-2,0), axis=(-1,-2,0), radius=.66, color=color.orange)

#bullett
bullet4= sphere(pos=(3.5,1,0), radius=.66, color=color.cyan)
bullet4.velocity=vector(4,30,0)
bullet4.trail=curve(color=bullet4.color)

bullet5= sphere(pos=(3.5,1,0), radius=.66, color=color.yellow)
bullet5.velocity=vector(4,20,0)
bullet5.trail=curve(color=bullet5.color)


#equation constants
deltat=.01
t=0
g = 9.8 # magnitude of gravitational field in m/s^2
m1= 1 # mass kilograms
m2=2
m3=3
m4=2
m5=1
dt = 0.01 # time step in seconds
b = 0.4 # drag force constant, where F_drag = -bv^n
n = 1.0 # drag force power, where (again) F_drag = -bv^n
coeff_restitution_g = 0.80# fractional decrease in speed at each collision
coeff_restitution_s = .8
coeff_friction = 0.15 # coefficient of rolling friction between dropping and ground

F_grav1 = vector(0,-m1*g,0) # gravitational force
F_drag1 = -norm(dropping1.velocity) *abs( b * math.pow(dropping1.velocity.mag, n))
F_fric1= vector(0,0,0)
F_net1 = F_grav1 +F_fric1
a1 = F_net1 / m1

F_grav2 = vector(0,-m2*g,0) # gravitational force
F_drag2 = -(norm(dropping2.velocity) * abs(b * math.pow(dropping2.velocity.mag, n)))
F_fric2= vector(0,0,0)
F_net2 = F_grav2 +F_fric2
a2= F_net2 / m2

F_grav3 = vector(0,-m3*g,0) # gravitational force
F_drag3 = - (norm(dropping3.velocity) * abs(b * math.pow(dropping3.velocity.mag, n)))
F_fric3= vector(0,0,0)
F_net3 = F_grav3 +F_fric3
a3= F_net3 / m3

F_grav4 = vector(0,-m4*g,0) # gravitational force
F_drag4 = - (norm(bullet4.velocity) * abs(b * math.pow(bullet4.velocity.mag, n)))
F_fric4= vector(0,0,0)
F_net4= F_grav4 +F_fric4
a4= F_net4 / m4

F_grav5= vector(0,-m5*g,0) # gravitational force
F_drag5= - (norm(bullet5.velocity) * abs(b * math.pow(bullet5.velocity.mag, n)))
F_fric5= vector(0,0,0)
F_net5= F_grav5 +F_fric5
a5= F_net5 / m5

#motion
while t<20:
rate(500)
bird.pos=bird.pos+bird.velocity*deltat
t=t+deltat
dropping1.pos=dropping1.pos+dropping1.velocity*deltat
dropping2.pos=dropping2.pos+dropping2.velocity*deltat
dropping3.pos=dropping3.pos+dropping3.velocity*deltat
if bird.pos.x>-8.748:
dropping2.velocity=dropping2.velocity+a2*deltat
if bird.pos.x>-11:
dropping1.velocity=dropping1.velocity+a1*deltat
if bird.pos.x>-6:
dropping3.velocity=dropping3.velocity+a3*deltat
if -2< dropping1.pos.x <2:
if dropping1.pos.y<=stat.pos.y:
dropping1.velocity.y=-dropping1.velocity.y
if -2< dropping2.pos.x <2:
if dropping2.pos.y< stat.pos.y:
dropping2.velocity.y=-dropping2.velocity.y
if -2 < dropping3.pos.x <2:
if dropping3.pos.y < stat.pos.y:
dropping3.velocity.y=-dropping3.velocity.y
if dropping1.pos.y < ground.pos.y:
dropping1.velocity.y=-dropping1.velocity.y*coeff_restitution_g
if dropping2.pos.y < ground.pos.y:
dropping2.velocity.y=-dropping2.velocity.y * coeff_restitution_g
if dropping3.pos.y < ground.pos.y:
dropping3.velocity.y=-dropping3.velocity.y*coeff_restitution_g
if bird.pos.x > -6:
bullet4.velocity= bullet4.velocity+a4*deltat
bullet4.pos=bullet4.pos+bullet4.velocity*deltat
if bird.pos.x > -8:
bullet5.velocity= bullet5.velocity+a5*deltat
bullet5.pos=bullet5.pos+bullet5.velocity*deltat
if bullet4.pos.y < ground.pos.y:
bullet4.velocity.y=-bullet4.velocity.y*coeff_restitution_g
if bullet5.pos.y < ground.pos.y:
bullet5.velocity.y=-bullet5.velocity.y
dropping1.trail.append(pos=dropping1.pos)
dropping2.trail.append(pos=dropping2.pos)
dropping3.trail.append(pos=dropping3.pos)

Sunday, February 21, 2010

SUCCESS

Quick update first...

We came in early on Tuesday and Wednesday morning to slave over our engine... we needed to find a way to attach the metal cross bar to the needle.. and well that proved to be harder then it sounds. First of all ~ we tried bending the needle but got frightened when we had a slight chip of the needle - and seeing our history with needles this did not seem like the brightest idea - so we decided to use JB Welds, and to say the least this also failed us and proved to be even more problematic. So the JB Welds decided to not hold the cross bar in place but drip down and seal the needle in place and shut. (uh oh). So we took off the JB Welds (and accidental detached the bolt and piece of metal -- easily fixed with super glue). After this debacle we decided to use RTV (a much safer choice) and then we had to let that dry.

Oh but before we did the RTV we tried to wrap copper wire around it (because there was still a little JB Welds to hold it in place) we found out that our engine kept getting caught at this point (another big UH OH) but then we detached the metal and decided to also detached the balloon and then shift around the displacer.

So at this point all seems lost and the deadline is creeping closer - we have detached our balloon - which took all of 30 seconds to reattach (but that is besides the point). Then we moved around the displacer until it was on a smoother path - and then we attached the RTV.

After the RTV dried -- we hooked up the copper wire to the crank shaft and the wire to the balloon. Tape was our savior - we used it to attach the balloon and cooper wire and around the copper wire to make sure it did not bend. Then it was time to test the engine....

The tea candle was not enough heat so we added 7 more candles.


http://www.youtube.com/watch?v=J9xM3HAD644

Tuesday, February 16, 2010

sticky fingers





Well day 5/6 are now combined into one blog entry sorry for any inconvience this may cause you, who ever you are. Anyhow yesterday we found that we had left the RTV at school which is still lost in the physics lab/room and we have given up all hope of recovering it. So today we decided that we would swoop/barrow Mikes. Thank you Mike. So yesterday we used JB welds to attach the top to the can and seel it off - and then today covered the enitre thing with RTV - which is really really really really really sticky - and is now all over my hands - hence the title of this entery.

We also made the crankshaft arms yesterday and I, Haley, was able to use the power tools. This was quite and exciting momnet because no one in their right mind has ever trusted me with power tools before - big mistake on their part, because I discovered that it is actually one of my new talents. So I drilled two holes into the metal slim fast cans and did not injury ANYONE. This is kind of a big deal, seeing how accident prone I am. Then we attached the balloon - which we deattached today and super glued - not our brightested idea - and it just may fail us miserably - but we always have a backup ballon just incase we have to disembody the superglued one.

Ohhh, I almost forgot we RTVed all of the stirling engine so illuminate all leeks - i hope and now we are waiting for it to dry. Ciao.

Tuesday, February 9, 2010

Circuits Lab






Yesterday we worked for a few minutes doing a brief circuit lab. We did three different circuits, a lemon battery, a solar panel, and a hand crank.
First, we examined the solar panel circuit. This circuit works by utilizing semi-conductors such as silicon. Using the silicon (and like materials) allows for a lattice life structure due to the orginization of the electrons. As Silicon has four electrons, the different molecules share the electrons equally in an attempt to reach that more stable level of eight electrons. However in the silicon that is utilized, there are "impurities" which dont have the four valence electrons of silicon. These have either excess or fewer electrons which allow the solar panel to work. The sunlight, in the form of photons, enters the semi-conductor and this inflow of energy knocks off some of the electrons of the impurities. These "knocked" off electrons create a current, as desired. As we moved the panel closer to the light source, the voltage increased because of a greater exposure to light.
Second, we worked with the lemon battery. This was made up of a lemon, a copper penny, a nail, and a wire which connects the penny and nail. When stuck in the lemon, both the nail and penny are exposed to the citric acid which is in the lemon. The acid steadily eats away at the molecules which make up the nail and this chemical reaction releases the excess electrons. The excess electrons bond with the hydrogen ions in the acid. The electrons in the copper want to do the same thing, but find it easier near the acid eaten nail. So they flow through the wire, creating a current.
We finished up with the crank shaft. This circuit works by the movement of a magnet through coils of wire. The magnet is moved by the hand-powered crank. The motion of the magnet creates a movement in the magnetic field in the coils and through induction a current is created to counter this change. In order to counter this change in magnetic field, a current is created in the coils. The magnetic field is constantly changing, so depending on where the magnet is at any given point, the current will flow to the left or right in the coils. As the current flows it will eventually leave the coils and enter the resistor (the light bulb).

Sunday, February 7, 2010

ooopsie daisies

PVC pipe - most exciting part

Broken beer can -- after the needle malfunction
Broken needle - ooopsie daisy - I have no logical explanation for this one
Broken needle - ooopsie daisy - I have no logical explanation for this one

Super Bowl Sunday - meltdown (but only sorta - not really)

Well today is (unofficial) day 4 - this is because we are not at school - but that is okay. Today started out lovely, the sun was shining there was no more rain it was the morning of the super bowl, and all was good. So we decided to attach the displacer top to the displacer bottom- and what a mistake that was. It started out great - we made sure we used JB Welds and that it was on the inside of it, but then the problems started. No, there were no major injuries, but the needle was tilted! So we decided to try and move the displacer top ever so slightly to level it, but it was too late the JB Welds was to strong and well it was just not going to budge. So then Peter came up the the ingenious idea of moving the needle. Well - what seemed like a good idea at the time ended up being a recipe for disaster. The needle broke, and when I say broke - i literally mean snapped in half.

So we decided to re-do the displacer tomorrow in class. So then we continued on to shave/file down the PVC pipe (I just found out that this is what it is called - and now I am really excited) any how, that was not the point of that sentence- the point was we sanded it down and it looks beautiful - well as beautiful as a PVC pipe can look. We are planning on JB Welding/RTVing (that reminds me of ATVs - which i mistakenly called RTVs oopsie daisy) - we will do that tomorrow - i think.

Next and most importantly of the day - we drilled the hole into the steel slim fast can with out denting or deforming it. And on top of that we sanded it down so there where no shards sticking out to possible rupture the displacer - if we ever get that fixed. Over all that was perhaps the second most exciting part of the day - the first still being i now know what the pipe is officially called.

Happy Super Bowl Day!