1
$\begingroup$

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

  • 0
    OK, have you already tried my suggestion? I.e. for the top and bottom wall, just reverse angle.2011-04-29

2 Answers 2

3

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$.
  • 0
    Ok, I get it now. Thanks a lot Raskolnikov and everyone else who helpped.2011-04-29
0

The reflection changes the sign of the angle giving 0.65, but since you also go in the opposite direction you change this angle by $\pi \sim 3.14$. So you get $0.65 - 3.14 \sim -2.5$.

Note that it does not make a difference if you add or substract $\pi$ as angles are only determined up to multiples of $2\pi$.

  • 0
    http://past$e$bin.com/rrtC30ri2011-04-29