[Math] Find radians reflection angle

linear algebratrigonometry

I'm coding a simple Flash game, just to learn flash and improve my maths, but I'm getting very confused with Radians as there are new to me.

What I've done so far is using your mouse you (click & release) you shoot a ball off in that direction using radians. Now what I'd like to happen is when the ball hits the wall it bounces off in it's reflection angle. Eg. if the ball hits the right-hand-side wall travelling at in a radians of -0.65 it should bounce back in the radians of about -2.5

Could some please explain to me how I go about doing this?
Thanks

Best Answer

The relevant quantity here is the velocity vector of the ball. When you hit a wall, you want to flip the component of that vector perpendicular to the wall and keep the other component equal.

So, if you fix a velocity vector by giving an initial speed $v_0$ and a direction given by an angle $\alpha$ with respect to the horizontal direction and assuming there are only horizontal end vertical walls, this is what will happen:

  1. The moment you hit a horizontal wall, you want to flip the vertical component of the vector and keep the horizontal component equal. This means $$ v_0(\cos(\alpha),\sin(\alpha)) \mapsto v_0 (\cos(\alpha),-\sin(\alpha)) = v_0 (\cos(-\alpha)),\sin(-\alpha))$$ which corresponds to reversing the angle $\alpha$.
  2. The moment you hit a vertical wall, you want to flip the horizontal component of the vector and keep the vertical component equal. This means $$ v_0(\cos(\alpha),\sin(\alpha)) \mapsto v_0(-\cos(\alpha),\sin(\alpha)) = v_0(\cos(\pi-\alpha)),\sin(\pi-\alpha))$$ which corresponds to adding $\pi$ to the reversed angle $-\alpha$.