0

I have a ball and I'm moving it toward an angle like this:

ball.x += ball.speed * Math.sin(ball.angle)
ball.y += ball.speed * -Math.cos(ball.angle)

How can I calculate the reflection angle when the ball collides with a wall?(horizontal or vertical)

Something like this

Adrin
  • 585
  • 3
  • 11

1 Answers1

2

For any wall with normal vector e_n a ball with initial velocity vector v_i has the velocity vector v_f after reflection with

v_f = v_i - 2 dot( v_i, e_n) e_n,

where dot is the vector dot-product.

Explanation: The projection of v_i on e_n is dot( v_i, e_n ). This is the velocity towards the wall and this is the part that gets reversed upon reflection. The component p = dot( v_i, e_n ) results in a vector p e_n. The remaining component can be calculated via a cross product or simply v_s = v_i - p e_n. The final velocity is the non altered component plus the reversed projected component, i.e. v_s - p e_n = v_i - 2 p e_n = v_i - 2 dot( v_i, e_n) e_n

mikuszefski
  • 3,943
  • 1
  • 25
  • 38
  • 1
    This is assuming a non-rotating ball. In reality friction and refection at oblique angles would result in a change of rotation as well (This changes distribution of internal energies and effects velocity as well etc. etc.) Hence the edges on a pool table which are placed in a height such that spin is also reflected properly. – mikuszefski Apr 11 '19 at 07:32