# How to calculate the exit speed of ball bouncing off a solid surface

Hey all, I am working on a simple game to include some rigid body dynamics, involving placing (moving & rotating) some springs to bounce a falling ball into a target area.

My problem is correctly calculating the exit velocity of the ball after it hits the spring surface (Vexit, Ve for short)

Assume the following:
Initial ball velocity vector at point of impact is known (Vimpact, Vi for short)
Surface orientation vector is known (Vsurface, Vs for short)
Bounce coefficient (Bc for short) of ball after hitting surface is constant (for example |Ve| = 1.2 x |Vi|)

My algorithm is as follows:
-get surface normal vector, Vn
-get Vi inverse (reversing both x,y components to get reversed direction vector)
-get normalised Vi inverse, call this Vin
-get angle between Vin & Vn, by arccos(Vin . Vn). Let this be angle A
-rotate Vin by (2A) degrees to get normalised exit vector Ven
-Ve = Ven . Bc

Now as far as I can tell, this would work well. However, I am unable to know on whether to perform the rotation step in clock-wise, or anti-clock-wise motion; since the angle i get is always positive

What do you all think of this algorithm anyways?
Can anyone help me out on how to figure out the rotation direction?
Anyone have a better (faster,simpler,more accurate, etc) algorithm to use?

Thanks a lot!

## 2 Answers

I think you're over-thinking this, you can achieve reflection, as it can be calculated by doing:

Ve = Vi - 2 * (Vi dot Vn) * Vn

(Where dot refers to the dot product)

Then you can simply scale Ve by your Bc to get the final result.

• Thanks, this seems the most simple method and probably would be the fastest to calculate as well – codemonkey Aug 5 '10 at 10:50
• I would suggest looking at scaling the dot product (instead of the final result) by the restitution value so that you don't affect the velocity parallel to the surface. You may also consider a different coefficient for that value although it'd be a slightly more complicated insertion into that equation. – dash-tom-bang Aug 24 '10 at 2:19

You don't need the arccos or the angle. You just want to invert the normal velocity.

Start by taking the component of the ball's velocity in the normal direction (perpendicular)

Vp = Dot(Vn, Vi) * Vn


compute the tangential velocity

Vt = Vi - Vp


and then invert the normal velocity while keeping the tangential velocity

Ve = Vt - Vp


This can simplify to

Ve = Vi - 2*Vp


This assumes that your Vn is normalized (i.e. Dot(Vn, Vn) == 1).

It should be easy to change this to support restitution other than 1 (that is, different bounciness.)

• Excellent answer as well. I think also to support different restitution, all I would need to do would be to multiply Ve by the bounciness – codemonkey Aug 5 '10 at 10:53
• Close - the version with restitution is Ve = Vi - (1+R)*Dot(Vi, Vn)*Vn, where R, the coefficient of restitution, is between 0 and 1. Also, just so there's no confusion I should point out that my simplified computation is identical to Chris's - I'm just going into a bit more detail on the derivation. – Charlie Aug 5 '10 at 22:17
• yeah, i see that now. And thanks for the correction on the restitution integration – codemonkey Aug 9 '10 at 14:25