Spring2008:Bouncing Ball Report: Bronson

From GeoMod

Jump to: navigation, search

Type your abstract here.

Contents

Introduction

In this assignement the student was introduced to a general form of writing a program within the Python. In oder to beeter understand the syntax used for the program, the student was led to write a program for a bouncing ball.

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.

Results

In the initial program the ball did not move. But after readjusting formulas and the written program structure, the bouncing ball program worked. However, there were moments of lag within the program because of the additonal added into the program.

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

The next step with this program would be to expand the parameters the were set in making this program. Another would be to shorten the program in order to eliminate redundancy to allow for further expansion within the program.

The Programs

Initial:

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, vel=0) ball2 = sphere(pos=(1,5,10), color=(4,1,0),radius=1.5, vel=0)

g = -9.8 dt = 0.01 t = 0.0 s = .5 *(ball.vel * (t*t)) + 10 ct = 0

while 1:

    #rate(50)
   t = t + dt
   ball.vel = ball.vel + g * dt
   ball2.vel = ball2.vel + g * dt
   ball.pos.z = ball.pos.z + ball.vel * dt
   ball2.pos.z = ball2.pos.z + ball2.vel * dt
   if ball.pos.z < 1:
       ball.pos.z = 1
   if ball2.pos.z < 1.5:
       ball2.pos.z = 1.5
       ball.vel = -ball.vel - 2.25
       ball2.vel = -ball2.vel - .5
       s = .5 *(ball.vel * (t*t)) + 10
       ball.pos.x = ball.pos.x + .09 + ball.pos.z
       ball2.pos.x = ball2.pos.x + .0009 + ball2.pos.z
   if ball.pos.x >= 9:
       break
   if ball2.pos.x >= 9:
       break 
   
   ct = ct + 1
   print t,ball.vel,ball.pos.z,s,ball.pos.x,ball2.vel,ball2.pos.z,s,ball2.pos.x,ct

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


break


Image:Experiment 1.xls

Personal tools