Circle Collision Detection HTML5 Canvas

If we want to check whether circles are colliding with each other or not, one way is by getting the distance between two centers of circles and subtracting the radius of each circle from that distance

We also check if the distance is greater than 1. If we want to check it for 20 circles, then we need to calculate exact differences in distances. x/y positions of centers vs the radii.

bs(x2 - x1) > (r2 + r1)
abs(y2 - y1) > (r2 + r1)

The circles cannot collide if the distance in X or Y between circle centers is greater than the sum of radii.

Updated on: 30-Jan-2020


Kickstart Your Career

Get certified by completing the course

Get Started