📜  碰撞圈 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:27.360000             🧑  作者: Mango

代码示例1
var circle1 = {radius: 20, x: 5, y: 5};
var circle2 = {radius: 12, x: 10, y: 5};

var dx = circle1.x - circle2.x;
var dy = circle1.y - circle2.y;
var distance = Math.sqrt(dx * dx + dy * dy);

if (distance < circle1.radius + circle2.radius) {
    // collision detected
}