Spring2008:Bouncing Ball Report:Class

From GeoMod

Jump to: navigation, search


Contents

Abstract

This is a class report about creating model that is used to simulate a bouncing ball. The ball's initial position is (x=1,y=0,z=10); giving it an initial height of 10 along the z-axis. The ball has a radius of 1. The initial velocity of the ball in the z-direction is 0. The initial velocity of the ball in the x-direction is 1.


In order to make the model more realistic, a 75% decrease in velocity is assumed with each bounce of the ball. Meaning that each time the ball bounces it will lose 75% of its velocity. This velocity decrease is used to simulate the effect friction has on the ball when it comes in contact with the floor.


A simple experiment was done to see if the model actually simulates the real world. A tennis ball was dropped from a height of 1m and the height of each bounce of the ball was recorded.

Introduction

The goal of this assignment was to replicate a ball bouncing. The ball starts at a height of 10 on the z axis and bounces along the x axis. To make the model better replicate real life each student performed an experiment with a ball. The final model replicates a ball bouncing, but it has certain limitations that keep it from replicating real life. Image:Python_Model_initial.jpg

Methods

There are step by step procedures used within the program to set the boundaries for the coordinates x, y and z as a base in order to place a ball within the grid. All the characteristics of the ball was then written into the program, i.e. size, shape by means of standard formulas within Python. Then the formulas needed for calculations were then added into the program for resistance, gravity, time, etc. Next the program was manipulated in order to make the ball appear to bounce. Throughout the program steps were taken to run the program in order to determine if the program would run, what was missing within the program and how to enhance the assignment. Also, to calibrate the model an analytical position was determined for each time as the ball fell to the ground.

The following are the videos of the students experiments: Andy:Media:Bouncy_ball_002.avi Beth:Media:096.avi Terrance:Media:HPIM1674.avi

Results

When the model was run in Python, the ball fell from its initial height and also moved along the x-axis. The ball bounced off of the x-axis like it was supposed to, and the height of each bounce thereafter was reduced. Eventually, the force of friction slowed the ball so much that it appears to come to rest. While the program replicates a ball bouncing when compared to the experiments conducted by the students the results did not match up. When the analytical position was plotted with the modeled position, they seem to match almost exactly. This means that the model is calibrated correctly to the equation s = 0.5gt^2+10.

Conclusion

The program worked and within the program there was latitude for manipulating other features of the bouncing ball; speed, height, friction and length of run. These characteristics along with the actual experiment allowed the student the ability to compare the written program to the actual in order to make the necessary adjustments to achieve a good simulation.

Comments

To better improve this program it needs to be shortened and comments need to be added to inform people that read the program. The program does not realistically replicate a bouncy ball bouncing because the friction is constant and in the bouncy ball test the friction reduced in small increments each bounce. The effect of friction reducing each bounce of the bouncy ball can be seen in the graph in that the line does not have as severe of a curve as the program. Image:Bouncing_Ball_graph-1.jpg Image:assignmentbb.jpg Image:model vs analytical.jpg

Discussion

Andy: I had to add an extra step in my code to alter allow the ball to lose less vertical velocity on the first bounce than on the rest of the bounces. I noticed that the other two programs did not have to perform this step and I believe that it is because I used a bouncy ball and the other two test were performed with a tennis and a racquet ball.

Programs

Andy's program after calibration:

from visual import *

scene.forward = (0, -0.5,1) 
scene.up = (0,0,1)
scene.forward = (0, 1,0)
scene.lights = [vector(0, -10, 0)]

xaxis = curve(pos=[ (10, 0, 0), (0, 0,0)], color=(1,0,0))
yaxis = curve(pos=[ (0, 10, 0), (0, 0,0)], color=(0,1,0))
zaxis = curve(pos=[ (0, 0, 10), (0, 0,0)], color=(0,0,1))

ball = sphere(pos=(1,0,10), color=(1,0,0),radius=.125)

g = -9.8
dt = 0.01
vel = 0.0
t = 0
xvel = .005
s=0
while 1:
    t += dt
    vel += g * dt
    ball.pos.z += vel * dt

    if ball.pos.z < .125:
        ball.pos.z = .125
        xvel = xvel * .8

        if ball.pos.x > 3.2:
            vel = -vel * .83

        if ball.pos.x < 3.1:
            vel = -vel * .853

        
    

            
    s = 0.5*g*t*t+10
    
    print s,ball.pos.z,ball.pos.x,t,vel, xvel

    ball.pos.x += xvel

Beth's program:

Python Code

    from visual import *

    scene.forward = (0, -0.5,1) 
    scene.up = (0,0,1)
    scene.forward = (0, 1,0)
    scene.lights = [vector(0, -10, 0)]

    xaxis = curve(pos=[ (10, 0, 0), (0, 0,0)], color=(1,0,0))
    yaxis = curve(pos=[ (0, 10, 0), (0, 0,0)], color=(0,1,0))
    zaxis = curve(pos=[ (0, 0, 10), (0, 0,0)], color=(0,0,1))

    ball1 = sphere(pos=(1,0,10), radius=1, color=(1,0,0), vel1z=0.0)

    '''gravity constant'''
    g = -9.8
    '''change in time'''
    dt = 0.01
    '''initial velocity ball1'''
    vel1z = 0.0
    '''initial time'''
    t = 0.0
    '''x velocity'''
    vel1x = 1.0

    while 1:
        #rate(60)
        '''time'''
        t = t + dt
        print t
        vel1z = vel1z + g * dt
        ball1.pos.z = ball1.pos.z + vel1z * dt #+ 0.5 * g * dt * dt
        ball1.pos.x = ball1.pos.x + vel1x * dt
        ct = ct + 1
        if ball1.pos.z < 1:
            vel1z = -vel1z * 0.75
            vel1x = vel1x * 0.75
            ball1.pos.z = 1
            if vel1<0.05:
                vel1=0.0
            if vel1x<0.05:
                vel1x=0.0
        '''position of ball'''    
        s = 0.5*g*t*t + 10

        print t,ball1.pos.z,s

Terrance's Program:

The Final:

from visual import *
from random import uniform, seed 

scene.forward = (0, -0.5,1) 
scene.up = (0,0,1)
scene.forward = (0, 1,0)
scene.lights = [vector(0, -10, 0)]

xaxis = curve(pos=[ (10, 0, 0), (0, 0,0)], color=(1,0,0))
yaxis = curve(pos=[ (0, 10, 0), (0, 0,0)], color=(0,1,0))
zaxis = curve(pos=[ (0, 0, 10), (0, 0,0)], color=(0,0,1))

seed (2)

balls = []
for i in range(5):
    rad = uniform(.5, 2)
    vx = uniform(.005, .01)
    balls.append (sphere(radius = rad, velx = vx, pos = (1,0,10), velz = 0))

g = -9.8
dt = 0.01
vel = 0.0
t = 0


while 1:
    t +=dt
    for i in balls:
        i.velz = i.velz + g * dt
        i.pos.z = i.pos.z + i.velz * dt
  
    
    if i.pos.z < i.radius:
        i.pos.z = i.radius
        i.velz = -i.velz * 0.75
        i.velx = i.velx * 0.75

    i.pos.x =  i.pos.x + i.velx
Personal tools