<script>
function
radius(a, b, c) {
let g = a / 2;
let f = b / 2;
if
(g * g + f * f - c < 0)
return
(-1);
return
(Math.sqrt(g * g + f * f - c));
}
function
centerDistanceFromLine(a, b, i, j, k) {
let g = a / 2;
let f = b / 2;
let distance = Math.abs(i * g + j * f + k) /
(Math.sqrt(i * i + j * j));
if
(distance < 0)
return
(-1);
return
distance;
}
function
interceptLength(a, b, c, i, j, k) {
let rad = radius(a, b, c);
let dist = centerDistanceFromLine(
a, b, i, j, k);
if
(rad < 0 || dist < 0) {
document.write(
"circle not possible"
);
return
;
}
if
(dist > rad) {
document.write(
"Line not cutting circle"
);
}
else
document.write(2 * Math.sqrt(
rad * rad - dist * dist));
}
let a = 0, b = 0, c = -4;
let i = 2, j = -1, k = 1;
interceptLength(a, b, c, i, j, k);
</script>