5
\$\begingroup\$

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?

alt text

\$\endgroup\$

1 Answer 1

13
\$\begingroup\$

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

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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. \$\endgroup\$
    – James
    Jan 11, 2011 at 23:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .