Published
Edited
Jan 28, 2019
Importers
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function closestPointOnCircleEdge(A, B, r) {
const a1 = B.x - A.x;
const b1 = (B.x - A.x) ** 2 + (B.y - A.y) ** 2;

let x = A.x + r * (a1 / Math.sqrt(b1));

const a2 = B.y - A.y;
const b2 = (B.x - A.x) ** 2 + (B.y - A.y) ** 2;

let y = A.y + r * (a2 / Math.sqrt(b2));

const C = { x, y };

return C;
}
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more