collision circle

Solutions on MaxInterview for collision circle by the best coders in the world

showing results for - "collision circle"
Rafael
09 Oct 2020
1var circle1 = {radius: 20, x: 5, y: 5};
2var circle2 = {radius: 12, x: 10, y: 5};
3
4var dx = circle1.x - circle2.x;
5var dy = circle1.y - circle2.y;
6var distance = Math.sqrt(dx * dx + dy * dy);
7
8if (distance < circle1.radius + circle2.radius) {
9    // collision detected
10}