[Math] Collision between a circle and a rectangle

circlesclassical-mechanics

I am trying to create a simple model for collisions between a circle and a rectangle to be used in a computer game. The reason I am asking this question here rather than stack overflow is that the problem is not one of programming but rather of mechanics. The problem I am experiencing can be reduced to the following:

A circle with centre (cx,cy) collides with the top-left corner of a rectangle (rx,ry) The rectangle is stationary and cannot move. Given the circle collided with the rectangle at velocity (cvx,cvy), what velocity does the circle bounce off with, assuming the collision is perfectly elastic?

Next, consider that the rectangle is also moving with velocity (rvx,rvy), but its velocity is unaffected by a collision. What velocity does the circle bounce off with with, again assuming the collision is perfectly elastic?

This is similar to Angle of reflection off of a circle?, but the solution there does not seem applicable as a tangent cannot be drawn off the corner of a rectangle. Please note that I have not studied mechanics for over 2 years and then it was at a fairly low level.

Best Answer

Physically, the force exerted on the circle during collision acts radially on the line through the vertex of the rectangle and the center (of gravity) of the circle. This is true at least as far as the momentum is concerned; some kinetic energy may be converted (via tangential force) to rotational energy, with the details depending on the "surface structure" and friction. By your assumption that the rectangle is not affected, we should assume that the rectangle has infinite mass and no energy is transferred between the two objects (whereas momentum is, but that doesn't matter for the rectangle).

If at the moment of collision the circle center is at $(c_x,c_y)$ and the corner at $(r_x,r_y)$ and the velocity before is $(v_x,v_y)$, then the velocity after the collision is determined by $(v_x',v_y')=(v_x+q(c_x-r_x), v_y+q(c_y-r_y))$ and - assuming for simplicity that no rotation is produced - same kinetic energy: $v'^2=v^2$. You can use this to find the nonzero solution for $q$ and hence the new velocity: $$\begin{align}v_x^2+v_y^2&=(v_x+q(c_x-r_x))^2+(v_y+q(c_y-r_y))^2\\ \implies\quad0&=2q(v_x(c_x-r_x)+v_y(c_y-r_y))+q^2((c_x-r_x)^2+(c_y-r_y))^2\\ \implies \quad q&=-\frac{2(v_x(c_x-r_x)+v_y(c_y-r_y))}{R^2} \end{align}$$ where $R$ is the radius of your circle.

If the rectangle (still of infinite mass) is moving, it is best to assume the rectangle at rest (or rather the common center of gravity - but that is the center of gravity of the rectangle), i.e. you first subtract the rectangle velocity from the circle velocity, then compute the new circle velocity and add back the rectangle velocity.

More realistically, however, you really do have to consider rotational energy (pre and post collision) as well.

Related Question