Monday, April 12, 2010

Additional Video

Here's another video for the bowling ball simulation. I tried avoiding the watermark as much as possible on this one.

Winston's Visual Python Project

Sorry about the watermark.
Description: This program simulates a bowling ball rolling down the lane and hitting pins. The bowling ball starts moving due to an initial force. It can be moved to different starting positions and be pushed at different angles to try and hit as many pins as possible. As it rolls, it experiences a frictional force which slows the ball down and also causes it to roll without slipping at different distances depending on the initial force. Lastly, the ball hits pins and knocks them over.

from __future__ import division
from visual import *
from visual.controls import *


Xposition = 0 #ball position start
ball = sphere(pos=(Xposition,1,-20), radius=1.0, material=materials.earth)
floor = box(pos = (0,0,-5), size=(8,.2,40), color = (.48,.20,.10))
pin7 = frame()
pin7t = sphere(frame = pin7, pos = (-2.4,1.9,10), radius = .35)
pin7m = box(frame = pin7, pos = (-2.4,1.5,10), size = (.4,.4,.4), color=color.red, opacity=.8)
pin7b = cylinder(frame = pin7, pos = (-2.4,0,10), axis = (0,1.35,0), radius = .35)
pin10 = frame()
pin10t = sphere(frame = pin10, pos = (2.4,1.9,10), radius = .35)
pin10m = box(frame = pin10, pos = (2.4,1.5,10), size = (.4,.4,.4), color=color.red, opacity=.8)
pin10b = cylinder(frame = pin10, pos = (2.4,0,10), axis = (0,1.35,0), radius = .35)
pin8 = frame()
pin8t = sphere(frame = pin8, pos = (-.8,1.9,10), radius = .35)
pin8m = box(frame = pin8, pos = (-.8,1.5,10), size = (.4,.4,.4), color=color.red, opacity=.8)
pin8b = cylinder(frame = pin8, pos = (-.8,0,10), axis = (0,1.35,0), radius = .35)
pin9 = frame()
pin9t = sphere(frame = pin9, pos = (.8,1.9,10), radius = .35)
pin9m = box(frame = pin9, pos = (.8,1.5,10), size = (.4,.4,.4), color=color.red, opacity=.8)
pin9b = cylinder(frame = pin9, pos = (.8,0,10), axis = (0,1.35,0), radius = .35)
pin6 = frame()
pin6t = sphere(frame = pin6, pos = (1.6,1.9,9), radius = .35)
pin6m = box(frame = pin6, pos = (1.6,1.5,9), size = (.4,.4,.4), color=color.red, opacity=.8)
pin6b = cylinder(frame = pin6, pos = (1.6,0,9), axis = (0,1.35,0), radius = .35)
pin5 = frame()
pin5t = sphere(frame = pin5, pos = (0,1.9,9), radius = .35)
pin5m = box(frame = pin5, pos = (0,1.5,9), size = (.4,.4,.4), color=color.red, opacity=.8)
pin5b = cylinder(frame = pin5, pos = (0,0,9), axis = (0,1.35,0), radius = .35)
pin4 = frame()
pin4t = sphere(frame = pin4, pos = (-1.6,1.9,9), radius = .35)
pin4m = box(frame = pin4, pos = (-1.6,1.5,9), size = (.4,.4,.4), color=color.red, opacity=.8)
pin4b = cylinder(frame = pin4, pos = (-1.6,0,9), axis = (0,1.35,0), radius = .35)
pin2 = frame()
pin2t = sphere(frame = pin2, pos = (-.8,1.9,8), radius = .35)
pin2m = box(frame = pin2, pos = (-.8,1.5,8), size = (.4,.4,.4), color=color.red, opacity=.8)
pin2b = cylinder(frame = pin2, pos = (-.8,0,8), axis = (0,1.35,0), radius = .35)
pin3 = frame()
pin3t = sphere(frame = pin3, pos = (.8,1.9,8), radius = .35)
pin3m = box(frame = pin3, pos = (.8,1.5,8), size = (.4,.4,.4), color=color.red, opacity=.8)
pin3b = cylinder(frame = pin3, pos = (.8,0,8), axis = (0,1.35,0), radius = .35)
pin1 = frame()
pin1t = sphere(frame = pin1, pos = (0,1.9,7), radius = .35)
pin1m = box(frame = pin1, pos = (0,1.5,7), size = (.4,.4,.4), color=color.red, opacity=.8)
pin1b = cylinder(frame = pin1, pos = (0,0,7), axis = (0,1.35,0), radius = .35)

G = 9.8 #m/s^2
Mball = 7.25 #kg
Mpin = 1.6 #kg
coefficient = .15 #friction


ball.velocity = vector(0,0,0)
Fpush = 100 #you can change the force of the push
degree = 0 #you can change the direction of the push
angle = degree * (2*pi)/180
Ffriction = Mball*G*coefficient

ball.acceleration = vector(0,0,0)
ball.acceleration.x = (Ffriction/Mball)
ball.acceleration.y = 0
ball.acceleration.z = (Ffriction)/(Mball)

pin1.velocity = vector(0,0,0)
pin2.velocity = vector(0,0,0)
pin3.velocity = vector(0,0,0)
pin4.velocity = vector(0,0,0)
pin5.velocity = vector(0,0,0)
pin6.velocity = vector(0,0,0)
pin7.velocity = vector(0,0,0)
pin8.velocity = vector(0,0,0)
pin9.velocity = vector(0,0,0)
pin10.velocity = vector(0,0,0)

dt = .01
t = 0

while ball.pos.z<18.5:
rate(100)
t = t + dt
if ball.velocity.z<0:
Ffriction=0
ball.velocity = vector(0,0,0)#makes sure that friction only acts when the ball is moving, also makes sure ball actually stops
if t<.75:
ball.acceleration.z = (Fpush*cos(angle))/(Mball)
ball.velocity.z = ball.velocity.z + ball.acceleration.z*dt
ball.pos.z = ball.pos.z + ball.velocity.z*dt#this is your initial force to get the ball moving
ball.acceleration.x = (Fpush*sin(angle))/Mball
ball.velocity.x = ball.velocity.x + ball.acceleration.x*dt
ball.pos.x = ball.pos.x + ball.velocity.x*dt
if t>.75:
ball.acceleration.z = -(Ffriction*cos(angle))/(Mball)
ball.velocity.z = ball.velocity.z + ball.acceleration.z*dt
ball.pos.z = ball.pos.z + ball.velocity.z*dt#friction
ball.acceleration.x = -(Ffriction*sin(angle))/Mball
ball.velocity.x = ball.velocity.x + ball.acceleration.x*dt
ball.pos.x = ball.pos.x + ball.velocity.x*dt
#pin1
if ball.pos.x + 1.2 >= pin1b.pos.x >= ball.pos.x - 1.2:
if ball.pos.z +1.2 >= pin1b.pos.z >= ball.pos.z -1.2:
ball.velocity = ball.velocity*.999
pin1.velocity = ball.velocity*1.5
pin1.rotate(angle = pi/55, axis = (1,0,0), origin = (pin1t.pos.x,pin1t.pos.y+1,pin1t.pos.z))

#pin2
if ball.pos.x + 1.2 >= pin2b.pos.x >= ball.pos.x - 1.2:
if ball.pos.z + 1.2 >= pin2b.pos.z >= ball.pos.z - 1.2:
ball.velocity = ball.velocity*.999
pin2.velocity = ball.velocity*1.5
pin2.rotate(angle = pi/55, axis = (1,0,0), origin = (pin2t.pos.x,pin2t.pos.y+1,pin2t.pos.z))

#pin3
if ball.pos.x + 1.2 >= pin3b.pos.x >= ball.pos.x - 1.2:
if ball.pos.z + 1.2 >= pin3b.pos.z >= ball.pos.z - 1.2:
ball.velocity = ball.velocity*.999
pin3.velocity = ball.velocity*1.5
pin3.rotate(angle = pi/55, axis = (1,0,0), origin = (pin3t.pos.x,pin3t.pos.y+1,pin3t.pos.z))

#pin4
if ball.pos.x + 1.2 >= pin4b.pos.x >= ball.pos.x - 1.2:
if ball.pos.z + 1.2 >= pin4b.pos.z >= ball.pos.z - 1.2:
ball.velocity = ball.velocity*.999
pin4.velocity = ball.velocity*1.5
pin4.rotate(angle = pi/55, axis = (1,0,0), origin = (pin4t.pos.x,pin4t.pos.y+1,pin4t.pos.z))

#pin5
if ball.pos.x + 1.2 >= pin5b.pos.x >= ball.pos.x - 1.2:
if ball.pos.z + 1.2 >= pin5b.pos.z >= ball.pos.z - 1.2:
ball.velocity = ball.velocity*.999
pin5.velocity = ball.velocity*1.5
pin5.rotate(angle = pi/55, axis = (1,0,0), origin = (pin5t.pos.x,pin5t.pos.y+1,pin5t.pos.z))


#pin6
if ball.pos.x + 1.2 >= pin6b.pos.x >= ball.pos.x - 1.2:
if ball.pos.z + 1.2 >= pin6b.pos.z >= ball.pos.z - 1.2:
ball.velocity = ball.velocity*.999
pin6.velocity = ball.velocity*1.5
pin6.rotate(angle = pi/55, axis = (1,0,0), origin = (pin6t.pos.x,pin6t.pos.y+1,pin6t.pos.z))

#pin7
if ball.pos.x + 1.2 >= pin7b.pos.x >= ball.pos.x - 1.2:
if ball.pos.z + 1.2 >= pin7b.pos.z >= ball.pos.z - 1.2:
ball.velocity = ball.velocity*.999
pin7.velocity = ball.velocity*1.5
pin7.rotate(angle = pi/55, axis = (1,0,0), origin = (pin7t.pos.x,pin7t.pos.y+1,pin7t.pos.z))

#pin8
if ball.pos.x + 1.2 >= pin8b.pos.x >= ball.pos.x - 1.2:
if ball.pos.z + 1.2 >= pin8b.pos.z >= ball.pos.z - 1.2:
ball.velocity = ball.velocity*.999
pin8.velocity = ball.velocity*1.5
pin8.rotate(angle = pi/55, axis = (1,0,0), origin = (pin8t.pos.x,pin8t.pos.y+1,pin8t.pos.z))

#pin9
if ball.pos.x + 1.2 >= pin9b.pos.x >= ball.pos.x - 1.2:
if ball.pos.z + 1.2 >= pin9b.pos.z >= ball.pos.z - 1.2:
ball.velocity = ball.velocity*.999
pin9.velocity = ball.velocity*1.5
pin9.rotate(angle = pi/55, axis = (1,0,0), origin = (pin9t.pos.x,pin9t.pos.y+1,pin9t.pos.z))
#pin10
if ball.pos.x + 1.2 >= pin10b.pos.x >= ball.pos.x - 1.2:
if ball.pos.z + 1.2 >= pin10b.pos.z >= ball.pos.z - 1.2:
ball.velocity = ball.velocity*.999
pin10.velocity = ball.velocity*1.5
pin10.rotate(angle = pi/55, axis = (1,0,0), origin = (pin10t.pos.x,pin10t.pos.y+1,pin10t.pos.z))
pin1.pos = pin1.pos + pin1.velocity*dt
pin2.pos = pin2.pos + pin2.velocity*dt
pin3.pos = pin3.pos + pin3.velocity*dt
pin4.pos = pin4.pos + pin4.velocity*dt
pin5.pos = pin5.pos + pin5.velocity*dt
pin6.pos = pin6.pos + pin6.velocity*dt
pin7.pos = pin7.pos + pin7.velocity*dt
pin8.pos = pin8.pos + pin8.velocity*dt
pin9.pos = pin9.pos + pin9.velocity*dt
pin10.pos = pin10.pos + pin10.velocity*dt

Torquefriction = Ffriction
AngularAcceleration = Torquefriction/(.4*Mball)
AngularVelocity = AngularAcceleration*t
if mag(ball.velocity) <>
ball.rotate(angle=.1, axis=(1,0,0), origin=ball.pos) #rolling without slipping

Monday, March 29, 2010

Matteo's Visual Python Project

Ball Bouncing Down Ramp

Video: http://www.youtube.com/watch?v=O54XjZGRnxU

Description: This program simulates a ball bouncing down an angled ramp. Each time the ball bounces it obeys the law of reflection. Included within the program are two graphs which display the ball's total, potential, and kinetic energy. It is easy to see from the graphs that energy is conserved and when potential energy decreases, kinetic energy increases. This simulation ignores friction and air resistance.

Code:
from __future__ import division
from visual import*
from visual.graph import*

ramp = box(pos=(0,6.8,0), axis=(-2,1,0), length=30, width=7, height=.1)
stand1 = cylinder(pos=(-10.5,.3,2.5), length=11.5, axis=(0,1,0), radius=.6)
stand2 = cylinder(pos=(-10.5,.3,-2.5), length=11.5, axis=(0,1,0), radius=.6)
stand3 = cylinder(pos=(-10.5,.3,0), length=11.5, axis=(0,1,0), radius=.6)
floor = box(pos=(10,.1,0), length=50, width=20, height=.2, color=color.green)
ball = sphere(pos=(-12.5,19.8,0), radius=.4, color=color.red)
ball.velocity=vector(0,0,0) #ball's initial velocity
ball.trail=curve(color=ball.color)
m = 1 #ball's mass
g = 9.8 #gravitational acceleration
time = 0 #time
dt = .01 #time step
U = m*g*(ball.pos.y - ball.radius) #gravitational potential energy measured from floor.pos.y = zero potential
E = U #total energy equals U since the initial velocity is zero
K = E-U #kinetic energy equals the total energy minus potential energy
graph1 = gdisplay(x=675, y=0, width=600, height=400, title='Potential Energy vs. Time',
xtitle='time (s)', ytitle='Total Energy and Potential Energy (J)', xmax=18, xmin=0,
ymax=1.2*U, ymin=0, foreground=color.black, background=color.white)
Ucurve = gcurve(gdisplay = graph1, color=color.black)
Ecurve = gcurve(gdisplay = graph1, color=color.black)
#total energy and gravitational potential energy graph
graph2 = gdisplay(x=675, y=400, width=600, height=400, title='Kinetic Energy vs. Time',
xtitle='time (s)', ytitle='Kinetic Energy (J)', xmax=18, xmin=0,
ymax=1.2*U, ymin=0, foreground=color.black, background=color.white)
Kcurve = gcurve(gdisplay = graph2, color=color.black)
#kinetic energy graph
while true:
rate(50)
time += dt
F_net=vector(0,-m*g,0) #force of gravity
a=F_net/m #Newton's 2nd law
U = m*g*(ball.pos.y - ball.radius)
K = E-U
ball.trail.append(pos=(ball.x,ball.y,ball.z)) #ball's tail
ball.velocity.y = ball.velocity.y - g*dt #turns gravity on
if ball.pos.y <= ramp.pos.y + (-1/2)*ball.pos.x + ramp.height*sin(atan(1/2))+.2:
ball.velocity.y = mag(ball.velocity)*sin(atan(1/2))
ball.velocity.x = mag(ball.velocity)*cos(atan(1/2))
#when the ball hits the ramp it bounces off at the angle obeying the law of reflection
if ball.pos.y <= floor.pos.y + ball.radius:
ball.velocity.y = -ball.velocity.y
ball.velocity.x = ball.velocity.x
#this ensures the ball won't go through the floor
if ball.pos.x >= floor.pos.x + .5*floor.length:
ball.pos.x = -12.5
ball.pos.y = 19.8
ball.pos.z = 0
ball.velocity.x = 0
ball.velocity.y = 0
ball.velocity.z = 0
ball.trail.append(pos=(ball.x,ball.y,ball.z), retain=0)
#once the ball reaches the floor the simulation resets
ball.pos=ball.pos + ball.velocity*dt
if time<= 17:
Ucurve.plot(pos = (time, U))
Kcurve.plot(pos = (time, K))
Ecurve.plot(pos = (time, E))
#instructions for graphing two cycles

Inelastic Collision

Video: http://www.youtube.com/watch?v=SzpEBTUAImk

Description: This simulation recreates inelastic collisions between two carts. Users can change the mass and velocities of either carts in the beginning lines of code; each carts size is directly proportional to its mass. This simulation also displays a graph showing the momentum and kinetic energy of the entire system. The momentum graph is a horizontal line showing that momentum is conserved. The kinetic energy graph is not constant, showing that energy is lost through sound and other forms of energy in the collision.

Code:
from __future__ import division
from visual import*
from visual.graph import*

m_1 = 2 #red cart's mass
v_1 = 20 #red cart's velocity
m_2 = 4 #blue cart's mass
v_2 = -5 #blue cart's velocity
floor = box(pos=(0,0,0), length=60, width=6, height=.9, color=color.green)
cart1 = box(pos=(-24,1.4+(.5)*(.3)*(m_1),0), length=5, width=3, height=(.3)*(m_1), color=color.red)
ball1 = sphere(pos=(-25.75,.95,-.7), radius = .7, color=color.black)
ball2 = sphere(pos=(-25.75,.95,.7), radius = .7, color=ball1.color)
ball3 = sphere(pos=(-22.25,.95,-.7), radius = .7, color=ball1.color)
ball4 = sphere(pos=(-22.25,.95,.7), radius = .7, color=ball1.color)
cart2 = box(pos=(24,1.4+(.5)*(.3)*(m_2),0), length=5, width=3, height=(.3)*(m_2), color=color.blue)
ball5 = sphere(pos=(25.75,.95,-.7), radius = .7, color=ball1.color)
ball6 = sphere(pos=(25.75,.95,.7), radius = .7, color=ball1.color)
ball7 = sphere(pos=(22.25,.95,-.7), radius = .7, color=ball1.color)
ball8 = sphere(pos=(22.25,.95,.7), radius = .7, color=ball1.color)
wall1 = box(pos=(29.5,2.5,0), length=1, width=6, height=5, color=color.green)
wall2 = box(pos=(-29.5,2.5,0), length=1, width=6, height=5, color=color.green)
cart1.velocity = vector(v_1,0,0)
ball1.velocity = vector(cart1.velocity.x,0,0)
ball2.velocity = vector(cart1.velocity.x,0,0)
ball3.velocity = vector(cart1.velocity.x,0,0)
ball4.velocity = vector(cart1.velocity.x,0,0)
cart2.velocity = vector(v_2,0,0)
ball5.velocity = vector(cart2.velocity.x,0,0)
ball6.velocity = vector(cart2.velocity.x,0,0)
ball7.velocity = vector(cart2.velocity.x,0,0)
ball8.velocity = vector(cart2.velocity.x,0,0) #ensures wheels stay attached to carts
time =0 #time
dt = .001 #time step
p = ((m_2)*(cart2.velocity.x)+(cart1.velocity.x)*(m_1)) #total momentum
k = .5*(m_1)*(pow(ball1.velocity.x,2) + pow(ball1.velocity.y,2) + .5*(m_2)*(pow(ball2.velocity.x,2) + pow(ball2.velocity.y,2)))
#kinetic energy
graph1 = gdisplay(x=650, y=0, width=600, height=400, title='Momentum vs. Time',
xtitle='time (s)', ytitle='Momentum (kg*m/s)', xmax=20, xmin=0,
ymax=1.2*p, ymin=-1.2*p, foreground=color.black, background=color.white)
pcurve = gcurve(gdisplay = graph1, color=color.black)
#momentum graph
graph2 = gdisplay(x=650, y=400, width=600, height=400, title='Kinetic Energy vs. Time',
xtitle='time (s)', ytitle='Kinetic Energy (J)', xmax=20, xmin=0,
ymax=1.2*k, ymin=0, foreground=color.black, background=color.white)
kcurve = gcurve(gdisplay = graph2, color=color.black)
#kinetic energy graph
while true:
rate(1000)
time += dt
cart1.pos = cart1.pos + cart1.velocity*dt
cart2.pos = cart2.pos + cart2.velocity*dt
ball1.pos = ball1.pos + ball1.velocity*dt
ball2.pos = ball2.pos + ball2.velocity*dt
ball3.pos = ball3.pos + ball3.velocity*dt
ball4.pos = ball4.pos + ball4.velocity*dt
ball5.pos = ball5.pos + ball5.velocity*dt
ball6.pos = ball6.pos + ball6.velocity*dt
ball7.pos = ball7.pos + ball7.velocity*dt
ball8.pos = ball8.pos + ball8.velocity*dt
if cart1.pos.x >= cart2.pos.x - (.5)*cart2.length - (.5)*cart1.length:
cart1.velocity.x = ((m_2)*(cart2.velocity.x)+(cart1.velocity.x)*(m_1))/((m_1)+(m_2))
ball1.velocity.x = cart1.velocity.x
ball2.velocity.x = cart1.velocity.x
ball3.velocity.x = cart1.velocity.x
ball4.velocity.x = cart1.velocity.x
cart2.velocity.x = cart1.velocity.x
ball5.velocity.x = cart1.velocity.x
ball6.velocity.x = cart1.velocity.x
ball7.velocity.x = cart1.velocity.x
ball8.velocity.x = cart1.velocity.x
#after the two carts collide, they each have the same velocity and momentum is conserved (but not kinetic energy)
if cart2.pos.x >= wall1.pos.x - (.5)*cart2.length - (.5)*wall2.length:
cart1.velocity = -cart1.velocity
ball2.velocity = -ball2.velocity
ball3.velocity = -ball3.velocity
ball4.velocity = -ball4.velocity
cart2.velocity = -cart2.velocity
ball5.velocity = -ball5.velocity
ball6.velocity = -ball6.velocity
ball7.velocity = -ball7.velocity
ball8.velocity = -ball8.velocity
#this ensures the carts rebound off the right wall
if cart1.pos.x <= wall2.pos.x + (.5)*cart1.length + (.5)*wall1.length:
cart1.velocity = -cart1.velocity
ball2.velocity = -ball2.velocity
ball3.velocity = -ball3.velocity
ball4.velocity = -ball4.velocity
cart2.velocity = -cart2.velocity
ball5.velocity = -ball5.velocity
ball6.velocity = -ball6.velocity
ball7.velocity = -ball7.velocity
ball8.velocity = -ball8.velocity
#this ensures the carts rebound off the left wall
p = ((m_2)*(cart2.velocity.x)+(cart1.velocity.x)*(m_1))
k = .5*(m_1)*(pow(ball1.velocity.x,2) + pow(ball1.velocity.y,2) + .5*(m_2)*(pow(ball2.velocity.x,2) + pow(ball2.velocity.y,2)))
if time<= 20:
pcurve.plot(pos = (time,p))
kcurve.plot(pos = (time,k))

Race

Video: http://www.youtube.com/watch?v=UPs82IDOwn0

Description: This simulation shows a race of objects with different shapes and therefore rotational inertia. The shapes are from closest to farthest, a hollow sphere, a solid cylinder, a disk, a solid sphere, and a ring. All objects have the same mass and radius, who are you going to put your money on? (All objects roll without slipping in this simulation)

Code:
from __future__ import division
from visual import*

m_1 = 1 #mass of hollow sphere
r_1 = 1 #radius of hollow sphere
m_2 = 1 #mass of cylinder
r_2 = 1 #radius of cylinder
m_3 = 1 #mass of solid sphere
r_3 = 1 #radius of solid sphere
m_4 = 1 #mass of disk
r_4 = 1 #radius of disk
m_5 = 1 #mass of ring
r_5 = 1 #radius of ring
g = 9.8 #gravitational acceleration
u = .2 #coefficient of static friction
dt = .001 #time step
ramp = box(pos=(0,0,0), axis=(-2,1,0), length=70, width=32, height=.1)
stand1 = cylinder(pos=(-23,-15.7,8), length=26, axis=(0,1,0), radius=2)
stand2 = cylinder(pos=(-23,-15.7,-8), length=26, axis=(0,1,0), radius=2)
stand3 = cylinder(pos=(-23,-15.7,0), length=26, axis=(0,1,0), radius=2)
floor = box(pos=(0,-15.7,0), length=90, width=32, height=.2)
wall = box(pos=(45,-8.2,0), length=.2, width=32, height=15)
ball1 = sphere(pos=(-29,15.7,13), radius=(r_1), color=color.orange)
ball2 = sphere(pos=(ball1.pos.x,ball1.pos.y,-8), radius=(r_3), color=color.cyan)
cylinder1 = cylinder(pos=(ball1.pos.x,ball1.pos.y,1), axis=(0,0,5), radius=(r_2), color=color.green)
cylinder2 = cylinder(pos=(ball1.pos.x,ball1.pos.y,-3), axis=(0,0,.1), radius=(r_4), color=color.red)
ring = ring(pos=(ball1.pos.x, ball1.pos.y,-13), axis=(0,0,.1), radius=(r_5), color=color.blue)
ball1.velocity = vector(0,0,0)
ball2.velocity = vector(0,0,0)
cylinder1.velocity = vector(0,0,0)
cylinder2.velocity = vector(0,0,0)
ring.velocity = vector(0,0,0) #all racers start at the same height with the same velocity

while true:
rate(500)
if ball1.pos.y >= floor.pos.y + r_1 + .4:
ball1.velocity.x = ball1.velocity.x + ((r_1)*((u*(m_1)*g*(r_1))/(2/3*(m_1)*(r_1)*(r_1))))*cos(atan(-1/2))*dt
ball1.velocity.y = ball1.velocity.y + ((r_1)*((u*(m_1)*g*(r_1))/(2/3*(m_1)*(r_1)*(r_1))))*sin(atan(-1/2))*dt
#the object's acceleration is equal to its radius times its angular acceleration which equals torque over rotational interia
#the torque is equal to friction times radius (condition of rolling without slipping)
if ball1.pos.y <= floor.pos.y + r_1 + .4:
ball1.velocity.x = pow((pow(ball1.velocity.x,2) + pow(ball1.velocity.y,2)),.5)
ball1.velocity.y = 0
#when the object reaches the floor, the y velocity is zero, but kinetic energy is still conserved
if ball1.pos.x >= wall.pos.x - r_1 - .4:
ball1.velocity.x = 0
ball1.velocity.y = 0
#when the object hits the wall it comes to rest
if ball2.pos.y >= floor.pos.y + r_3 + .4:
ball2.velocity.x = ball2.velocity.x + ((r_3)*((u*(m_3)*g*(r_3))/(2/5*(m_3)*(r_3)*(r_3))))*cos(atan(-1/2))*dt
ball2.velocity.y = ball2.velocity.y + ((r_3)*((u*(m_3)*g*(r_3))/(2/5*(m_3)*(r_3)*(r_3))))*sin(atan(-1/2))*dt
if ball2.pos.y <= floor.pos.y + r_3 + .4:
ball2.velocity.x = pow((pow(ball2.velocity.x,2) + pow(ball2.velocity.y,2)),.5)
ball2.velocity.y = 0
if ball2.pos.x >= wall.pos.x - r_3 - .4:
ball2.velocity.x = 0
ball2.velocity.y = 0
if cylinder1.pos.y >= floor.pos.y + r_2 + .4:
cylinder1.velocity.x = cylinder1.velocity.x + ((r_2)*((u*(m_2)*g*(r_2))/(1/2*(m_2)*(r_2)*(r_2))))*cos(atan(-1/2))*dt
cylinder1.velocity.y = cylinder1.velocity.y + ((r_2)*((u*(m_2)*g*(r_2))/(1/2*(m_2)*(r_2)*(r_2))))*sin(atan(-1/2))*dt
if cylinder1.pos.y <= floor.pos.y + r_2 + .4:
cylinder1.velocity.x = pow((pow(cylinder1.velocity.x,2) + pow(cylinder1.velocity.y,2)),.5)
cylinder1.velocity.y = 0
if cylinder1.pos.x >= wall.pos.x - r_2 - .4:
cylinder1.velocity.x = 0
cylinder1.velocity.y = 0
if cylinder2.pos.y >= floor.pos.y + r_4 + .4:
cylinder2.velocity.x = cylinder2.velocity.x + ((r_4)*((u*(m_4)*g*(r_4))/(1/2*(m_4)*(r_4)*(r_4))))*cos(atan(-1/2))*dt
cylinder2.velocity.y = cylinder2.velocity.y + ((r_4)*((u*(m_4)*g*(r_4))/(1/2*(m_4)*(r_4)*(r_4))))*sin(atan(-1/2))*dt
if cylinder2.pos.y <= floor.pos.y + r_4 + .4:
cylinder2.velocity.x = pow((pow(cylinder2.velocity.x,2) + pow(cylinder2.velocity.y,2)),.5)
cylinder2.velocity.y = 0
if cylinder2.pos.x >= wall.pos.x - r_4 - .4:
cylinder2.velocity.x = 0
cylinder2.velocity.y = 0
if ring.pos.y >= floor.pos.y + r_5 + .4:
ring.velocity.x = ring.velocity.x + ((r_5)*((u*(m_5)*g*(r_5))/((m_5)*(r_5)*(r_5))))*cos(atan(-1/2))*dt
ring.velocity.y = ring.velocity.y + ((r_5)*((u*(m_5)*g*(r_5))/((m_5)*(r_5)*(r_5))))*sin(atan(-1/2))*dt
if ring.pos.y <= floor.pos.y + r_5 + .4:
ring.velocity.x = pow((pow(ring.velocity.x,2) + pow(ring.velocity.y,2)),.5)
ring.velocity.y = 0
if ring.pos.x >= wall.pos.x - r_5 - .4:
ring.velocity.x = 0
ring.velocity.y = 0
ball1.pos.x = ball1.pos.x + ball1.velocity.x*dt
ball1.pos.y = ball1.pos.y + ball1.velocity.y*dt
ball2.pos.x = ball2.pos.x + ball2.velocity.x*dt
ball2.pos.y = ball2.pos.y + ball2.velocity.y*dt
cylinder1.pos.x = cylinder1.pos.x + cylinder1.velocity.x*dt
cylinder1.pos.y = cylinder1.pos.y + cylinder1.velocity.y*dt
cylinder2.pos.x = cylinder2.pos.x + cylinder2.velocity.x*dt
cylinder2.pos.y = cylinder2.pos.y + cylinder2.velocity.y*dt
ring.pos.x = ring.pos.x + ring.velocity.x*dt
ring.pos.y = ring.pos.y + ring.velocity.y*dt

Saturday, February 27, 2010

FINALLLLLLY!

I guess we have to take a 3.5. :(




Monday, February 8, 2010

Power Lab Writeup

Lemon
A lemon battery works by exploiting the fact that some metals give up electrons more easily than others. In the lemon battery, a chemical reaction among the acidic lemon juice, copper, and zinc creates a current. Since copper gives up its electrons rather easily and zinc receives those electrons, there is a voltage difference between the copper coin and zinc nail. This voltage difference allows a current to run through the lemon battery.

Solar Panel
The solar panel works as a voltage source because it makes great use of silicon. Silicon has an outer shell with 4 electrons and it always looks to find 4 additional electrons to complete its shell. The silicon used in a solar panel has impurities which means there are other atoms mixed with silicon such as phosphorous. Since phosphorous has 5 outer electrons, there is a leftover electron when it bonds with silicon. When these leftover electrons are hit by the heat (energy) from sunlight, they begin to wander randomly while carrying an electrical current. These electrons "rush" to the holes created by the silicon atoms bonding with boron which only has 3 outer electrons. As a result, voltage is created when the electrons move in the solar panel.

Hand crank generator
The hand crank generator works through magnetic induction. A coil of wire rests inside several magnets. When a person turns the crank, the coil begins turning and the magnetic flux through the coil changes. Because of this changing magnetic field, a voltage will be induced that opposes the change in the magnetic field. This is what lights up the lightbulb. As soon as a person stops turning the crank, there is no change in magnetic flux and therefore no induced voltage so the lightbulb doesn't shine.

Mini Circuit Lab Pictures

Hand Crank Generator













Solar Panel without light


















Solar Panel with light


















Lemon

Wednesday, February 3, 2010

from visual import*
Container = cylinder(pos=(0,-11,0), axis=(0,22,0), radius=9, opacity=0.3, color=color.white)
Displacer = cylinder(pos=(0,10.999,0), axis=(0,.001,0), radius=Container.radius, opactiy=0.3, color=color.white)
Bottom = cylinder(pos=(0,-10.999,0,), axis=(0,.001,0), radius=Container.radius, opactiy=0.3, color=color.white)
ball1 = sphere(pos=( 0,0,0), radius=0.5, color=color.blue)
ball2 = sphere(pos=(0,0,0), radius=0.5, color=color.blue)
ball3 = sphere(pos=(0,0,0), radius=0.5, color=color.red)
ball4 = sphere(pos=(0,0,0), radius=0.5, color=color.red)
ball5 = sphere(pos=(0,0,0), radius=0.5, color=color.yellow)
ball6 = sphere(pos=(0,0,0), radius=0.5, color=color.yellow)
ball7 = sphere(pos=(0,0,0), radius=0.5, color=color.orange)
ball8 = sphere(pos=(0,0,0), radius=0.5, color=color.orange)
ball9 = sphere(pos=(0,0,0), radius=0.5, color=color.green)
ball10 = sphere(pos=(0,0,0), radius=0.5, color=color.green)
ball1.velocity = vector(50,60,70)
ball2.velocity = vector(-50,60,-70)
ball3.velocity = vector(60,70,50)
ball4.velocity = vector(-60,-70,50)
ball5.velocity = vector(50,60,70)
ball6.velocity = vector(-50,-60,70)
ball7.velocity = vector(50,-70,-60)
ball8.velocity = vector(60,-50,-70)
ball9.velocity = vector(70,50,60)
ball10.velocity = vector(70,-60,50)
deltat = .001
t = 0
scene.autoscale = False
while t < 1e5:
rate(10000)
if ball1.pos.x < ball1.radius - pow(abs((pow(Container.radius,2)-pow(ball1.pos.z,2))),.5):
ball1.velocity.x = - ball1.velocity.x
if ball1.pos.x > pow(abs((pow(Container.radius,2)-pow(ball1.pos.z,2))),.5) - ball1.radius:
ball1.velocity.x = - ball1.velocity.x
if ball1.pos.y < Bottom.pos.y + ball1.radius:
ball1.velocity.y = -ball1.velocity.y
if ball1.pos.y > Displacer.pos.y - ball1.radius:
ball1.velocity.y = -ball1.velocity.y
if ball1.pos.z < ball1.radius - pow(abs((pow(Container.radius,2)-pow(ball1.pos.x,2))),.5):
ball1.velocity.z = - ball1.velocity.z
if ball1.pos.z > pow(abs((pow(Container.radius,2)-pow(ball1.pos.x,2))),.5) - ball1.radius:
ball1.velocity.z = - ball1.velocity.z
if ball2.pos.x < ball2.radius - pow(abs((pow(Container.radius,2)-pow(ball2.pos.z,2))),.5):
ball2.velocity.x = - ball2.velocity.x
if ball2.pos.x > pow(abs((pow(Container.radius,2)-pow(ball2.pos.z,2))),.5) - ball2.radius:
ball2.velocity.x = - ball2.velocity.x
if ball2.pos.y < Bottom.pos.y + ball1.radius:
ball2.velocity.y = -ball2.velocity.y
if ball2.pos.y > Displacer.pos.y - ball2.radius:
ball2.velocity.y = -ball2.velocity.y
if ball2.pos.z < ball2.radius - pow(abs((pow(Container.radius,2)-pow(ball2.pos.x,2))),.5):
ball2.velocity.z = - ball2.velocity.z
if ball2.pos.z > pow(abs((pow(Container.radius,2)-pow(ball2.pos.x,2))),.5) - ball2.radius:
ball2.velocity.z = - ball2.velocity.z
if ball3.pos.x < ball3.radius - pow(abs((pow(Container.radius,2)-pow(ball3.pos.z,2))),.5):
ball3.velocity.x = - ball3.velocity.x
if ball3.pos.x > pow(abs((pow(Container.radius,2)-pow(ball3.pos.z,2))),.5) - ball3.radius:
ball3.velocity.x = - ball3.velocity.x
if ball3.pos.y < Bottom.pos.y + ball3.radius:
ball3.velocity.y = -ball3.velocity.y
if ball3.pos.y > Displacer.pos.y - ball3.radius:
ball3.velocity.y = -ball3.velocity.y
if ball3.pos.z < ball3.radius - pow(abs((pow(Container.radius,2)-pow(ball3.pos.x,2))),.5):
ball3.velocity.z = - ball3.velocity.z
if ball3.pos.z > pow(abs((pow(Container.radius,2)-pow(ball3.pos.x,2))),.5) - ball3.radius:
ball3.velocity.z = - ball3.velocity.z
if ball4.pos.x < ball4.radius - pow(abs((pow(Container.radius,2)-pow(ball4.pos.z,2))),.5):
ball4.velocity.x = - ball4.velocity.x
if ball4.pos.x > pow(abs((pow(Container.radius,2)-pow(ball4.pos.z,2))),.5) - ball4.radius:
ball4.velocity.x = - ball4.velocity.x
if ball4.pos.y < Bottom.pos.y + ball4.radius:
ball4.velocity.y = -ball4.velocity.y
if ball4.pos.y > Displacer.pos.y - ball4.radius:
ball4.velocity.y = -ball4.velocity.y
if ball4.pos.z < ball4.radius - pow(abs((pow(Container.radius,2)-pow(ball4.pos.x,2))),.5):
ball4.velocity.z = - ball4.velocity.z
if ball4.pos.z > pow(abs((pow(Container.radius,2)-pow(ball4.pos.x,2))),.5) - ball4.radius:
ball4.velocity.z = - ball4.velocity.z
if ball5.pos.x < ball5.radius - pow(abs((pow(Container.radius,2)-pow(ball5.pos.z,2))),.5):
ball5.velocity.x = - ball5.velocity.x
if ball5.pos.x > pow(abs((pow(Container.radius,2)-pow(ball5.pos.z,2))),.5) - ball5.radius:
ball5.velocity.x = - ball5.velocity.x
if ball5.pos.y < Bottom.pos.y + ball5.radius:
ball5.velocity.y = -ball5.velocity.y
if ball5.pos.y > Displacer.pos.y - ball5.radius:
ball5.velocity.y = -ball5.velocity.y
if ball5.pos.z < ball5.radius - pow(abs((pow(Container.radius,2)-pow(ball5.pos.x,2))),.5):
ball5.velocity.z = - ball5.velocity.z
if ball5.pos.z > pow(abs((pow(Container.radius,2)-pow(ball5.pos.x,2))),.5) - ball5.radius:
ball5.velocity.z = - ball5.velocity.z
if ball6.pos.x < ball6.radius - pow(abs((pow(Container.radius,2)-pow(ball6.pos.z,2))),.5):
ball6.velocity.x = - ball6.velocity.x
if ball6.pos.x > pow(abs((pow(Container.radius,2)-pow(ball6.pos.z,2))),.5) - ball6.radius:
ball6.velocity.x = - ball6.velocity.x
if ball6.pos.y < Bottom.pos.y + ball6.radius:
ball6.velocity.y = -ball6.velocity.y
if ball6.pos.y > Displacer.pos.y - ball6.radius:
ball6.velocity.y = -ball6.velocity.y
if ball6.pos.z < ball6.radius - pow(abs((pow(Container.radius,2)-pow(ball6.pos.x,2))),.5):
ball6.velocity.z = - ball6.velocity.z
if ball6.pos.z > pow(abs((pow(Container.radius,2)-pow(ball6.pos.x,2))),.5) - ball6.radius:
ball6.velocity.z = - ball6.velocity.z
if ball7.pos.x < ball7.radius - pow(abs((pow(Container.radius,2)-pow(ball7.pos.z,2))),.5):
ball7.velocity.x = - ball7.velocity.x
if ball7.pos.x > pow(abs((pow(Container.radius,2)-pow(ball7.pos.z,2))),.5) - ball7.radius:
ball7.velocity.x = - ball7.velocity.x
if ball7.pos.y < Bottom.pos.y + ball7.radius:
ball7.velocity.y = -ball7.velocity.y
if ball7.pos.y > Displacer.pos.y - ball7.radius:
ball7.velocity.y = -ball7.velocity.y
if ball7.pos.z < ball7.radius - pow(abs((pow(Container.radius,2)-pow(ball7.pos.x,2))),.5):
ball7.velocity.z = - ball7.velocity.z
if ball7.pos.z > pow(abs((pow(Container.radius,2)-pow(ball7.pos.x,2))),.5) - ball7.radius:
ball7.velocity.z = - ball7.velocity.z
if ball8.pos.x < ball8.radius - pow(abs((pow(Container.radius,2)-pow(ball8.pos.z,2))),.5):
ball8.velocity.x = - ball8.velocity.x
if ball8.pos.x > pow(abs((pow(Container.radius,2)-pow(ball8.pos.z,2))),.5) - ball8.radius:
ball8.velocity.x = - ball8.velocity.x
if ball8.pos.y < Bottom.pos.y + ball8.radius:
ball8.velocity.y = -ball8.velocity.y
if ball8.pos.y > Displacer.pos.y - ball8.radius:
ball8.velocity.y = -ball8.velocity.y
if ball8.pos.z < ball1.radius - pow(abs((pow(Container.radius,2)-pow(ball8.pos.x,2))),.5):
ball8.velocity.z = - ball8.velocity.z
if ball8.pos.z > pow(abs((pow(Container.radius,2)-pow(ball8.pos.x,2))),.5) - ball8.radius:
ball8.velocity.z = - ball8.velocity.z
if ball9.pos.x < ball9.radius - pow(abs((pow(Container.radius,2)-pow(ball9.pos.z,2))),.5):
ball9.velocity.x = - ball9.velocity.x
if ball9.pos.x > pow(abs((pow(Container.radius,2)-pow(ball9.pos.z,2))),.5) - ball9.radius:
ball9.velocity.x = - ball9.velocity.x
if ball9.pos.y < Bottom.pos.y + ball9.radius:
ball9.velocity.y = -ball9.velocity.y
if ball9.pos.y > Displacer.pos.y - ball9.radius:
ball9.velocity.y = -ball9.velocity.y
if ball9.pos.z < ball9.radius - pow(abs((pow(Container.radius,2)-pow(ball9.pos.x,2))),.5):
ball9.velocity.z = - ball9.velocity.z
if ball9.pos.z > pow(abs((pow(Container.radius,2)-pow(ball9.pos.x,2))),.5) - ball9.radius:
ball9.velocity.z = - ball9.velocity.z
if ball10.pos.x < ball10.radius - pow(abs((pow(Container.radius,2)-pow(ball10.pos.z,2))),.5):
ball10.velocity.x = - ball10.velocity.x
if ball10.pos.x > pow(abs((pow(Container.radius,2)-pow(ball10.pos.z,2))),.5) - ball10.radius:
ball10.velocity.x = - ball10.velocity.x
if ball10.pos.y < Bottom.pos.y + ball10.radius:
ball10.velocity.y = -ball10.velocity.y
if ball10.pos.y > Displacer.pos.y - ball10.radius:
ball10.velocity.y = -ball10.velocity.y
if ball10.pos.z < ball10.radius - pow(abs((pow(Container.radius,2)-pow(ball10.pos.x,2))),.5):
ball10.velocity.z = - ball10.velocity.z
if ball10.pos.z > pow(abs((pow(Container.radius,2)-pow(ball10.pos.x,2))),.5) - ball10.radius:
ball10.velocity.z = - ball10.velocity.z
ball1.pos = ball1.pos + ball1.velocity*deltat
ball2.pos = ball2.pos + ball2.velocity*deltat
ball3.pos = ball3.pos + ball3.velocity*deltat
ball4.pos = ball4.pos + ball4.velocity*deltat
ball5.pos = ball5.pos + ball5.velocity*deltat
ball6.pos = ball6.pos + ball6.velocity*deltat
ball7.pos = ball7.pos + ball7.velocity*deltat
ball8.pos = ball8.pos + ball8.velocity*deltat
ball9.pos = ball9.pos + ball9.velocity*deltat
ball10.pos = ball10.pos + ball10.velocity*deltat
t = t + deltat