Physics of bouncing
Author 
Message 
Insectoid

Posted: Wed Dec 09, 2009 1:31 pm Post subject: Physics of bouncing 


So, I've been playing around with trajectories and bouncing and stuff, and I've come across a problem;
I don't have a clue how things bounce (in number land) on an elastic surface. For example, dropping a basketball onto a (very taut) trampoline. In the exact center, it should bounce with rigidsurface rules (ie at the opposite angle). However, when it bounces near an edge it creates depressions and extra angles and it will 'roll' until it leaves the trampoline. The ball will bounce toward to center of the trampoline at an angle different from the original angle. It won't just bounce at an angle relative to the angle of the trampoline depression, because the ball is at the trough of 2 angles. So many variables but there MUST be an equation to find out what angle it will bounce at and how fast it will roll while on the trampoline.
My current bounce model causes the ball to rapidly accelerate in the positive direction, so it slows down and then is 'flung' in the opposite direction. The X velocity is not modified at all in my equations. So really, hitting something is just reversing gravity and applying it in greater force until it leaves the object.
So, my real question is, how do I model the rolling/change of angle and how do I apply it to my code? 





Sponsor Sponsor



DemonWasp

Posted: Wed Dec 09, 2009 2:02 pm Post subject: RE:Physics of bouncing 


On a trampoline, you have the elastic members of the trampoline interacting with the force of the basketball. Let's work with a 2D trampoline, because it'll be very much simpler. Let's also make the further assumption that instead of the complicated weave a real trampoline has, you merely have elastics going straight across some space. Further, we'll assume you want an iterative simulation (which is what your code in the other thread uses).
As the ball strikes the trampoline, it will deflect the members of the trampoline such that they are no longer straight. This will increase their length, which will create a tension by F = kx, where k is the spring constant of the member and x is the difference in length induced by the deflection (note: realistically, the trampoline is under tension when at rest).
At each iteration, you will then have two forces acting on the trampoline at the point the ball contacts it (I'm going to assume that modeling the ball as a point is adequate for your purposes): one force for each side of the ball. You can assume that the magnitude of the tension in both sides will be identical, but the angles will be different, because you're closer to one side than the other and the vertical deflection is the same. You have something like:
code: 
\ __
 \O_ 2 
1 
 

The third force here is gravity. Remember that F = ma. You have F and you have m, so you can determine a (remember, F, a and v are all vectors, so you should probably make a Vector type).
For a more realistic simulation, you could model the ball as a sphere and (with some coefficient of friction between the trampoline and the ball) determine the spin on the ball. This would also let you have different tension magnitudes, because you couldn't assume that the lengthchange value x in F=kx would be equal. 





Insectoid

Posted: Wed Dec 09, 2009 3:43 pm Post subject: RE:Physics of bouncing 


Hmm. I think I'll completely rewrite the program to utilize actual formulas and vectors with earthnumbers, just modified to fit the whole trajectory on the screen. That should make it easier to add more physics to it........ 





Insectoid

Posted: Thu Feb 11, 2010 1:08 pm Post subject: RE:Physics of bouncing 


I'm going to necro my own thread here to get some more help on this. Anyway, the problem I have with my program right now is that whenever the projectile remains in contact with the elastic for a very short time (13 frames) and with a high elasticity value (1 or greater) far too much energy is put into the projectile and it gains altitude over it's previous bounce ie the second bounce is higher than the first. I assume that this is because, in reality, a bouncing object remains in contact with the surface for a fraction of a 'frame', though my code gives it as much bounce as if it had actually been in contact for the full frame. At a bounce value of 1, it will give 1 unit of energy to the projectile when really (and I'm pulling this number out of the air) it should have only given .4 units, which leads to higherthanexpected bounce. Any idea how I could calculate the 'actual time of bounce' and calculate the velocity change more accurately?
My code:
Turing: 
var bulletX := 0. 00
var bulletY := 0. 00
var degrees := 0. 00
var bulletVel : real := 0
const elasticity := . 3
const gravity := . 1
var frames_under: int := 0
var font := Font.New ("Times New Roman:10")
var keys : array char of boolean
View.Set ("offscreenonly")
var line1Angle : real
var line2Angle : real
var degreeMod : real
loop
degrees := 90
bulletVel := 0
bulletX := 25
bulletY := 25
delay (10)
loop
Draw.ThickLine (25, 60, 25, round (bulletVel * 20 + 60), 20, blue)
Draw.FillArc (25, 25, 20, 20, round (degrees + 5), round (degrees  5), black)
Font.Draw ("Angle: " + realstr (degrees, 1), 60, 25, font, black)
Font.Draw ("Power: " + realstr (bulletVel * 100, 1), 5, round (bulletVel * 20 + 75), font, black)
View.Update
Input.KeyDown (keys )
if keys (KEY_UP_ARROW) then
degrees + = 1
elsif keys (KEY_DOWN_ARROW) then
degrees  = 1
end if
exit when keys (' ')
delay (10)
cls
end loop
loop
Input.KeyDown (keys )
bulletVel + = . 25
Draw.ThickLine (25, 60, 25, round (bulletVel * 20 + 60), 20, blue)
Draw.FillArc (25, 25, 20, 20, round (degrees + 5), round (degrees  5), black)
Font.Draw ("Power: " + realstr (bulletVel * 100, 1), 5, round (bulletVel * 20 + 75), font, black)
Font.Draw ("Angle: " + realstr (degrees, 1), 60, 25, font, black)
View.Update
exit when bulletVel >= 100 or not keys (' ')
delay (15)
cls
end loop
loop
Input.KeyDown (keys )
exit when keys (' ')
end loop
var velX : real
var velY : real
loop
Input.KeyDown (keys )
put frames_under
Draw.FillArc (round (bulletX ), round (bulletY ), 20, 20, round (degrees  185), round (degrees + 185), black)
Draw.ThickLine (25, 60, 25, round (bulletVel * 20 + 60), 20, blue)
Draw.FillArc (25, 25, 20, 20, round (degrees + 185), round (degrees  185), black)
Font.Draw ("Power: " + realstr (bulletVel * 100, 1), 5, round (bulletVel * 20 + 75), font, black)
Font.Draw ("Angle: " + realstr (degrees, 1), 60, 25, font, black)
velX := bulletVel * cosd (round (degrees ))
velY := bulletVel * sind (round (degrees ))
put velX
if bulletY >= 20 then
Draw.Line (0, 20, maxx, 20, black)
velY  = gravity
%frames_under := 0
else
Draw.Line (0, 20, round (bulletX ), round (bulletY ), red)
Draw.Line (round (bulletX ), round (bulletY ), maxx, 20, red)
velY  = gravity
velY + = elasticity %*(bulletY25))*1
frames_under + = 1
line1Angle := arctand (bulletX / (bulletY  20))
line2Angle := arctand ((maxx  bulletX ) / (bulletY  20))
degreeMod := (line1Angle + line2Angle )/ 2
/*velXMod := gravity * cosd ((line1Angle + line2Angle) / 2)
if line1Angle > line2Angle then
velX = velXMod
elsif line1Angle < line2Angle then
velX += velXMod
end if
*/
end if
View.Update
bulletX + = velX
bulletY + = velY
degrees := arctand (velY / velX )
bulletVel := sqrt (velX ** 2 + velY ** 2)
delay (10)
cls
exit when bulletX > maxx or bulletX < 0 or keys (KEY_ENTER ) %or bulletY < 0
end loop
end loop
%x += gravity * cosd (arctand (bulletX/(bulletY20)) + arctand ((maxx  bulletX)/(bulletY20)))







DemonWasp

Posted: Thu Feb 11, 2010 4:53 pm Post subject: RE:Physics of bouncing 


I think your synopsis of why this isn't working is probably correct, and this is then a symptom of coding something that disagrees with physics  you get nonphysical behaviour.
I'm tempted to make a tutorial on 2D physics programming (I don't have enough physics or math yet to handle the 3D case sufficiently well)...maybe that'll be my project over reading week. 





SNIPERDUDE

Posted: Thu Feb 11, 2010 5:10 pm Post subject: RE:Physics of bouncing 


I'd be quite interested in a physics tutorial DemonWasp, it's one of those things that's great to learn. 





USEC_OFFICER

Posted: Tue Feb 16, 2010 1:02 pm Post subject: RE:Physics of bouncing 


Yes, it would be a great idea. I agree. 






