A human can tell if two figures overlap or not at a glance. But it is difficult to solve this generally with a computer, and different problems often require different tricks.


Various methods of checking whether figures overlap is used to detect collision between objects in physics simulations and games. You may rely on the functions of existing tools and libraries in actual projects. But knowing the basics will not only help you understand these tools, but will also enable you to quickly implement only the functions you need yourself.



One of the simplest is the circle-point collision detection. Since all points on the edge of a circle are at the distance of the radius from its center, checking if a certain point is inside a circle is just to check the distance between the point and the center of the circle.

Two circles are overlapping if the distance between their centers is equal to or less than the sum of their radii.



$distance(A_{center},B_{center}) \leq A_{radius}+B_{radius}$

$\Rightarrow distance(A_{center},B_{center})-A_{radius}-B_{radius}\leq 0$

The distance between two points can be obtained by the following equation.


${d={\sqrt {(x_{1}-x_{2})^{2}+(y_{1}-y_{2})^{2}}}}$