Bouncing of a ball from circular boundary

827 Views Asked by At

Lets say a ball with xspeed: 14, yspeed: 16 hits the circular edge at xposition:626 yposition:382 like on the below picture :

Vector reflection

It needs to bounce properly, to get the right bounce and new ball position, speed, what would be the calculation steps for this? I need this for a game I am writing. Thanks for your time!

1

There are 1 best solutions below

1
On

It seems the following.

$\def\ol{\overline}$

Suppose that the circle has radius $R$ and is centered at a point $(x_0,y_0)$. Suppose that the ball hits the circle at the point $(x,y)$ at the moment $t_0$ with speed $\ol{v_1}=(v_{11},v_{12})$. The normal $\ol{n}=(n_1,n_2)$ to the circle at the point $(x,y)$ has unit length and is collinear to the vector $(x-x_0,y-y_0)$. Hence

$$(n_1,n_2)=\frac{1}{\sqrt{(x-x_0)^2+(y-y_0)^2}}(x-x_0,y-y_0).$$

Then $\ol{m}=(-n_2,n_1)$ is a unit vector orthogonal to $\ol{n}$.

The equation of new ball position is $\overline{p(t)}=(x,y)+(t-t_0)\ol{v_2}$, where $\ol{v_2}=(v_{21},v_{22})$ is the speed of the ball after the collision with the circle. The collision conditions imply that $(\ol{v_1},\ol{n})=-(\ol{v_2},\ol{n})$ and $(\ol{v_1},\ol{m})=(\ol{v_2},\ol{m})$. Then

$$v_{21}=(n_2^2-n_1^2)v_{11}-(2n_1n_2)v_{12},$$ $$v_{22}=-(2n_1n_2)v_{11}+(n_1^2-n_2^2)v_{12}.$$