Help! Circles of given radius through two points

Help! Circles of given radius through two points
0

#1

Tell us what’s happening:
I dont know why my code cannot fulfill last objective: `getCircles([0.1234, 0.9876], [0.8765, 0.2345], 2.0)` should return `[[1.8631, 1.9742], [-0.8632, -0.7521]]` .

``````
function getCircles (...args) {
var p1x = args[0][0];
var p1y = args[0][1];
var p2x = args[1][0];
var p2y = args[1][1];
var r = args[2];

if(p1x == p2x && p1y == p2y && r > 0){
return 'Coincident point. Infinite solutions';
}

if(p1x == p2x && p1y == p2y && r == 0){
}

var distance = 0;
distance = Math.pow(Math.pow(p1x-p2x,2)+Math.pow(p1y-p2y,2),0.5);

if(2*r < distance){
return 'No intersection. Points further apart than circle diameter';
}

if(2*r == distance){
return [(p1x+p2x)/2,(p1y+p2y)/2];
}

var output = [[], []];

var x3 = (p1x+p2x)/2;
var y3 = (p1y+p2y)/2;
var q = distance;
var x = x3 + Math.sqrt(Math.pow(r,2)-Math.pow(q/2,2))*(p1y-p2y)/q;
var y = y3 + Math.sqrt(Math.pow(r,2)-Math.pow(q/2,2))*(p2x-p1x)/q;

output[0].push(x.toFixed(4));
output[0].push(y.toFixed(4));

x = x3 - Math.sqrt(Math.pow(r,2)-Math.pow(q/2,2))*(p1y-p2y)/q;
y = y3 - Math.sqrt(Math.pow(r,2)-Math.pow(q/2,2))*(p2x-p1x)/q;

output[1].push(x.toFixed(4));
output[1].push(y.toFixed(4));

return output;
}

getCircles([0.1234, 0.9876], [0.8765, 0.2345], 2.0)
``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36`.