# separate two circles by moving both circles Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of separate two circles by moving both circles without wasting too much if your time.

The question is published on by Tutorial Guruji team.

how do I separate two distinct circles by moving both of them, not just one? here’s my code I use for separating the circles by moving one of the circle. I don’t know much about vectors. ‘_’

```if (i == j)
return;
var ref1 = a; // a and b are circles
var ref2 = b;
var x = ref1.x - ref2.x;
var y = ref1.y - ref2.y;
var d = Math.hypot(x, y);
if (d < r) {
x /= d;
y /= d;
ref2.x += (ref1.x - x * r - ref2.x) * 0.2;
ref2.y += (ref1.y - y * r - ref2.y) * 0.2;
}
```

i found a working solution to this:

```if (i == j)
return;
var ref1 = a; // a and b are circles
var ref2 = b;
var x = ref1.x - ref2.x;
var y = ref1.y - ref2.y;
var d = Math.hypot(x, y);
if (d < r) {
x /= d;
y /= d;
ref2.x += (ref1.x - x * r - ref2.x) * 0.2;
ref2.y += (ref1.y - y * r - ref2.y) * 0.2;
ref1.x += (ref2.x + x * r - ref1.x) * 0.2;
ref1.y += (ref2.y + y * r - ref1.y) * 0.2;
}
```