Published
Edited
Jan 8, 2022
7 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function place(a, b, c) {
const x_ba = b.x - a.x;
const y_ba = b.y - a.y;
const l_ab2 = x_ba ** 2 + y_ba ** 2;
const r_ac2 = (a.r + c.r) ** 2;
const r_bc2 = (b.r + c.r) ** 2;
const t_ap = (l_ab2 + r_ac2 - r_bc2) / (2 * l_ab2);
const t_pc = Math.sqrt(r_ac2 / l_ab2 - t_ap ** 2);
c.x = a.x + t_ap * x_ba + t_pc * y_ba;
c.y = a.y + t_ap * y_ba - t_pc * x_ba;
return c;
}
Insert cell
Insert cell
Insert cell
A = ({x: 120, y: 150, r: 50})
Insert cell
B = ({x: 300, y: 205, r: 90})
Insert cell
C = place(A, B, {r: 50 - Math.cos(now / 5000) * 14})
Insert cell
C2 = place(B, A, {r: C.r})
Insert cell
p = {
const x_ba = B.x - A.x;
const y_ba = B.y - A.y;
const l_ab2 = x_ba ** 2 + y_ba ** 2;
const r_ac2 = (A.r + C.r) ** 2;
const r_bc2 = (B.r + C.r) ** 2;
const t_ap = (l_ab2 + r_ac2 - r_bc2) / (2 * l_ab2);
const t_pc = Math.sqrt(r_ac2 / l_ab2 - t_ap ** 2);
return {x: A.x + t_ap * x_ba, y: A.y + t_ap * y_ba};
}
Insert cell
color_a = "#1f77b4"
Insert cell
color_b = "#2ca02c"
Insert cell
color_c = "#000000"
Insert cell
color_p = "#d62728" // d3.schemeCategory10[3]
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more