Sunday, October 23, 2011

Python: Bouncing the Ball

The purpose:
We are going to use Python and VPython to make the animation of the bouncing the ball in order to help understand more about the Python.

We start with the python program, and we import the visual from VPython.

We make an sphere with certain position, radius and color, and we name the sphere "ball".
We make an box with certain position, dimension and color, and we name the box "WallR".

We add the time dt into the program, and we create the vector for the velocity of ball. We set the position of ball equals the old position of ball plus the velocity of ball times the time, and we use while loop program to repeat the changing position of ball in order to move the ball.

To make the ball bounce at the surface of the wall, we set the velocity of the wall reverse when the position of the right end of the ball is equal to the position of left end of the box "WallR".

We add value in the y and z coordinate of the velocity vector so the ball can move in three dimension.

We add the arrow with the same position of ball and same axis of velocity of ball so the arrow can show the motion of ball.

To have a trajectory of the moving ball, we create a trail of the moving ball by using the curve in VPython, and we set the position of trail is sames as the position of ball.

We make four more walls with different position, dimension, color in order to form a box, and we set the velocity of the ball reverses when the position of the end of the ball is the same as the position of the inner end of the wall so the ball can collide with the surface of any wall.

We set the velocity of the z-direction of the ball is the old z-velocity plus -9.8 times the time dt to make the acceleration of gravity of -9.8ms^-2 pointing in the negative z direction as we use the equation v(1) = v(0) + gt.

Here is our final product that the ball is bouncing in 3 dimensional with a square box.

Here is our program code:

#-------------------------------------------------------------------------------
# Name: Bouncing Ball
# Purpose:Help me learn some basic features of VPython
#
# Author: Hiu Ching Tang, Kishan Karunaratne
#
# Created: 10/22/2011
#-------------------------------------------------------------------------------

from visual import *
ball=sphere (pos=(-5,0,0),radius=0.5,color=color.red)
wallR=box (pos=(6,0,0),size=(0.2,12,12), color=color.green)
wallL=box (pos=(-6,0,0),size=(0.2,12,12), color=color.blue)
wallT=box (pos=(0,6,0),size=(12,0.2,12), color=color.cyan)
wallB=box (pos=(0,-6,0),size=(12,0.2,12), color=color.orange)
wallBack=box (pos=(0,0,-6),size=(12,12,0.2), color=color.white)

dt=0.05
ball.velocity=vector(1,2,1.5)
bv=arrow(pos=ball.pos, axis=ball.velocity, color=color.yellow)
ball.trail = curve(color=ball.color)

while (1==1):
rate(100)
ball.velocity=ball.velocity
ball.pos = ball.pos + ball.velocity*dt
if ball.x+0.5>wallR.x-0.2:
ball.velocity.x=-ball.velocity.x
if ball.x-0.5wallT.y-0.2:
ball.velocity.y=-ball.velocity.y
if ball.y-0.55.8:
ball.velocity.z=-ball.velocity.z
if ball.z-0.5

We do not successfully make the partially elastic collision as we do not know how to decrease the magnitude of velocity when the ball bounce the wall. I do not make 10 balls in the large box. However, we make successfully demonstrate the collision of the balls in three dimensional in a large box.

Friday, October 21, 2011

Special Relativity


The purpose:
We are going to learn more about the special relativity by studying the time dilation and length contraction of different initial frame.

First, we study the time dilation of two different initial frame by doing the first exercise on the Web. We are asked to the distance traveled and the time measured with different initial frame. One is stationary and another is moving. We are going to use the theorem that speed of light is always constant. We successfully ask all the questions and find the time dilation of two different frame.

Secondary, we are going to do the second exercise and study the contraction of length in order to the special relativity. We cannot finish the exercise as we cannot figure out whether the length measure by the stationary observer or moving observer is correct length. Finally, we find the length measured by the stationary observer is correct length and there is contraction of length measured by the moving observer.

Friday, October 14, 2011

CD Diffraction



Purpose: We are going to distance between the grooves on the CD.

We point a laser beam on a CD, and we put white boards as screen between laser beam and CD without blocking the beam. We have the diffraction pattern on the white boards.



We measure the distance between center to first order maxima distance.

The left first order maxima distance x(left) = 13.1 ± 0.05 cm.
The right first order maxima distance x(right) = 13.3 ± 0.05 cm.

We also measure the distance between the CD and white boards L = 17.2 ± 0.05 cm.

We have the wavelength of laser λ is 670 ± 20 nm = 670 x 10^-9 ± 20 x 10^-9 m.

We use the equation d = mλ/sinθ. For the first maximum order at x, m = 1, d = λ/sinθ.

The distance between the groove in CD due according to the left first order maxima = 1.106 x 10^-6 + 4.7294 x 10^-9 - 3.7551 x 10^-8 m.
The distance between the groove in CD due according to the right first order maxima = 1.096 x 10^-6 + 3.7425 x 10^-8 - 3.7106 x 10^-8 m.

We have the minimum and maximum range of distance d = 1.059 x 10^-6 and 1.111 x 10^-6.

The expected value of distance between of grooves in CD = 1600 nm = 1.6 x 10^-6 m.

We find the expected value of distance between of grooves in CD is out of the range of the calculated distance.

We successfully find distance between the grooves on the CD. However, we find the expected value of distance between of grooves in CD is out of the range of the calculated distance. There are some errors for the data we collected in the experiment. We hold the screen between the laser and CD by hand, and we do not hold the screen to be perpendicular to the laser and CD, which makes the measured distance between the CD and screen L and calculated distance x not accurate. We also do not hold the screen stably by hand so sometimes we shock, which changes the measured distance between the CD and screen L while moving the position of screen and makes the calculated distance x not accurate.

Saturday, October 8, 2011

Measuring a human hair


Purpose: We are going to measure the thickness of human hair by using a laser and micrometer, and we compare the accuracy of measuring the hair.

The expected range of thickness of human hair is (1.7 x 10^-5, 1.8 x 10^-4) m

Measure with a laser:


We obtain a human hair of one of the group mate and tape the hair across the hole in a 3x5 card.

We point the laser that is perpendicularly to the hole to the whiteboard. The interference pattern is shown on the whiteboard. We measure the distance between the card and whiteboard, and we mark the first three orders maximum measure the distance between orders.

Distance between card and whiteboard L= 604.9 cm= 6.049 m.

m

y (Left) (m)

y (Right) (m)

λ (m)

L (m)

d (Left) (m)

d (Right) (m)

0

0 ± 0.0005

0 ± 0.0005

6.2*10^-7 ± 2*10^-8

6.049± 0.0005



1

0.066 ± 0.0005

0.062 ± 0.0005

6.2*10^-7 ± 2*10^-8

6.049± 0.0005

5.68E-05 + 2.310E-06 - 2.227E-06

6.049E-05 + 2.464E-06 - 2.424E-06

2

0.109 ± 0.0005

0.105 ± 0.0005

6.2*10^-7 ± 2*10^-8

6.049± 0.0005

6.88E-05 + 2.567E-06 - 2.515E-06

7.144E-05 + 2.659E-06 - 1.984E-06

3

0.152 ± 0.0005

0.153 ± 0.0005

6.2*10^-7 ± 2*10^-8

6.049± 0.0005

7.40E-05 + 2.667E-06 - 2.137E-06

7.354E-05 + 2.624E-06 – 2.148E-06


Then we take the average value of d for each order m.

m

d (Left) (m)

d (Right) (m)

D (avg) (m)

0




1

5.68E-05 + 2.310E-06 - 2.227E-06

6.049E-05 + 2.464E-06 - 2.424E-06

5.865E-05 + 4.304E-06 – 4.077E-06

2

6.88E-05 + 2.567E-06 - 2.515E-06

7.144E-05 + 2.659E-06 - 1.984E-06

7.012E-05 + 3.979E-06 - 3.835E-06

3

7.40E-05 + 2.667E-06 - 2.137E-06

7.354E-05 + 2.624E-06 – 2.148E-06

7.377E-05 + 2.897E-06 – 2.378E-06



Finally, we take the average of the order 1, 2 and 3 to find the final average thickness d. We have the final average thickness d = 6.75 x 10^-5 + 9.154 x 10^-6 - 1.294 x10^-5 m, which is in the range of expected value.



Measure with a micrometer:

Our group mate Chris use micrometer to measure the thickness of hair. He finds the thickness of the hair using microscope is 0.1mm, which is 1 x 10^-4 m, which is in the range of the expected range of thickness of a human hair.

The advantage of using laser is easier to look at and mark the reading by eyes for the value of measurement. The disadvantage of using laser is it has lower accuracy of measurement as there are such more measuring errors such as measuring the distances between board and card, and measuring the distance between maximum points of board.
The advantage of using microscope is it has higher accuracy of measurement. The disadvantage of using microscope is harder to look at the reading by eyes for very smaller value of measurement.

We successfully find the thickness of hair by using laser, and we successfully find the thickness of hair by using a microscope as the thicknesses of measure in both method are in the expected range. We find the method of the thickness of hair by using microscope is more closed to the expected value as the uncertain range is smaller.