Predict bounce

BlitzMax Forums/BlitzMax Programming/Predict bounce

As Czar Flavius says, you'll want to brush up on your mechanics for this.

If we ignore air friction it's fairly easy. Using the ball's vertical velocity, as well as acceleration due to gravity (9.81 metres per second per second, I'm sure you know), you can calculate the exact time it will take for the ball to hit the ground. I'm thinking the equation you want is s = ut + 0.5at^2 where s is the distance to the ground, u is the initial vertical velocity of the ball, a is the acceleration due to gravity and t is time in seconds. You'll need to rearrange that to get t, which I kinda forget how (it's a lot easier to do on paper than in code) but hopefully someone can point us in that direction. I'm eating me dinner :)

Because it's a quadratic equation you ought to get two values, one of which will more than likely be negative, which would also tell you how long ago the ball bounced, so take the positive one.

Come to think of it, I have this baby that I took from a site somewhere but heaven knows if it actually works, that was quite a while ago

Rem
	bbdoc: Solve a quadratic equation
	about: Solves a quadratic equation of the form ax^2 + bx + c = 0
	returns: A floating point array with two elements
End Rem
Function fry_Solve_Quadratic:Float[](a:Float, b:Float, c:Float)

	Local root:Float[2]

	'calculate D
	Local D:Double = (b*b) - (4.0 * a * c)
	
	If D = 0 Then
		'one root:
		root[0] = (b * -1.0) / (2.0 * a)
		root[1] = root[0]
	Else If D > 0 Then
		'two roots
		root[0] = ((b * -1.0) + Sqr(D)) / (2.0 * a)
		root[1] = ((b * -1.0) - Sqr(D)) / (2.0 * a)
	Else
		'complex roots. Oh man!
		DebugLog "Complex Roots. Oh man!"
		DebugLog "D: "+D
		DebugLog "Values given are A="+a+" B="+b+" C="+c
		root = [0.0, 0.0]
	End If
	
	Return root

End Function


Sorry about the rather unhelpful comments. Really sorry, actually, I'm not sure exactly how or if this works either. I do recall though that the calculation of "D" is some helpful mathematical function that tells you if there's one root, two roots, or if they're complex.

With t, you can easily calculate the x and y locations of the bounce using the starting coordinates and respective components of the velocity.

Friction poses problems. How complex are you planning it? The simplest method sees friction as a constant and you just ensure that's in all your calculations, making allowances for things like stationary balls (you don't want friction to make the ball shoot into the air). If it's more accurately modelled, you'll be looking at finding out the effective coefficient of friction of the air and the ball, and it makes the calculation more complex. Exactly how much more complex, I can't say right now. It's been seven years since my A-Level Maths, every time I go back to it I have to re-learn everything.