Spring2008:Bouncing Ball Report:Andy Smith

From GeoMod

Jump to: navigation, search

Contents

Abstract

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 an experiment was performed with a bouncy ball. The final model replicates a ball bouncing, but it has certain limitations that keep it from replicating real life.

Introduction

In writing a program for a bouncing ball I was introduced to programing with Python. I learned the basic syntax used in the Python language and how to incorporate components into a program that attempt to make it replicate reality. Image:assignment1bb.JPG

Methods

The first step in writing the program was calling the window from visual import. Next the scene was set so that the axis and ball would be visible. After setting the scene the x, y, and z axis were added to the program. The components of the x, y, and z axis are: position, length, and color. The ball was added next, its components are: position, color, and radius.

The next step in the program was to add movement to the ball. The variables need to do this were g(gravity), dt, vel(velocity), t(time), and xvel(x velocity). Next a while loop was created. Inside the while loop the equations were created to add movement to the ball. The following equations: t += dt, vel += g *dt, and ball.pos.z += vel * dt were added to produce vertical movement to the ball. The above equations produced a falling ball but did bounce the ball off the x axis or add horizontal movement. To bounce the ball and move the ball horizontal an if statement was added to the while statement. Since the radius of the ball is 1 the if statement stated that if the balls z position reached less than 1 then the velocity became negative and lost 75% of its power. X velocity was also reduced by 75%. Horizontal movement was created by the equation ball.pos.x += xvel. We also included a print statement to give a report on how the program was running.

To compare this to reality test were performed with a ball. The ball used was a bouncy ball out of a 25 cent machine and it was bounced in front of a tape measure. The ball was released at 100 cm and had an exponential reduction in height on each bounce. Media:Bouncy_ball_002.avi

Results

The first time the program was executed the ball did not move. After a few adjustments to the program the ball dropped but did not bounce. An if statement was added to the program and the ball bounced. To make the program more realistic we added horizontal movement and then added reductions due to friction at a constant rate of 75%.


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 remains constant after the first two bounces and in the bouncy ball test the friction reduced in small increments each bounce.

Image:assignmentbb.jpg

Calibration

To calibrate the program so that it replicated life better the it was altered with the following code:

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

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

The alteration in the code allowed me to alter the friction on the balls after the first two bounces.

To analytically calibrate the program the formula s = 0.5*g*t*t+10 was added to the program. This formula compares the modeled position and the analytical position of the ball. This comparison could only be compared to the time of 1.42 which is the time when the ball first hits the ground. The graph of the the two positions show a very close match.

Image:analyticalvsmodel.JPG

Conclusion

The program worked and has the ability for the user to go into the program and easily manipulate it to show different results. Things in the program that the user can alter are the features of the ball, all axis, bounce height, distance, friction, and length of runtime. With the ability to alter these features the results of actual ball test the user has the ability to manipulate the program to realistically replicate a ball bouncing.

The Program

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=1)

g = -9.8
dt = 0.01
vel = 0.0
t = 0
xvel = .005

while 1:
    t += dt
    vel += g * dt
    ball.pos.z += vel * dt
    if ball.pos.z < 1:
        ball.pos.z = 1
        vel = -vel * 0.75
        xvel = xvel * .75
        
    print t,vel,ball.pos.z, ball.pos.x, xvel

    ball.pos.x += xvel

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

Personal tools