# How to calculate new direction after sprite collision

The scenario as you can see in the picture. A ball will be hitting a surface and I want to fairly correctly get the new angle after the collision..

I expect to know the X,Y coordinates of the lines breaking points (The picture below would has 6 lines)

Secondly, if the ball would have a rotation - Is there a standard way of compensate for a "screewed" ball?

-

What you need to calculate is the reflection vector;

if v is the velocity of your ball and n is the normal vector of the surface the ball is bouncing from then the the velocty of the ball after the bounce (assuming perfectly elastic collision etc) will be;

v-2(v•n)n

in 2d this will be;

newvelocity_x=v_x-2(v_x.n_x+v_y.n_y)n_x

newvelocity_y=v_y-2(v_x.n_x+v_y.n_y)n_y

-
Good general purpose answer. Just a little note for those making more simplistic rebound game like breakout or pong or the like, if you have a axis aligned bounding box and are not doing real physics (you want the velocity to remain the same) then you can just swap the components of the velocity vector. ie: If you reach the left or right edge of the box, negate the X value of the velocity vector. If you reach the top or bottom, negate the Y value of the velocity. – James Jan 11 '11 at 23:24