Published
Edited
Aug 17, 2018
1 fork
6 stars
Insert cell
Insert cell
Insert cell
Insert cell
function common_tangent_line(x1, y1, r1, x2, y2, r2) {
// Compute the common tangent line of two circles: (x1, y1) - r1 and (x2, y2) - r2
// Return in the form of line equation: ax + by + c == 0
let delta1 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) - (r1 + r2) * (r1 + r2);
let delta2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) - (r1 - r2) * (r1 - r2);
let p1 = r1 * (x1 * x2 + y1 * y2 - x2 * x2 - y2 * y2);
let p2 = r2 * (x1 * x1 + y1 * y1 - x1 * x2 - y1 * y2);
let q = x1 * y2 - x2 * y1;
let results = [];
if(delta1 >= 0) {
let l11 = {
a: (x2 - x1) * (r1 + r2) + (y1 - y2) * Math.sqrt(delta1),
b: (y2 - y1) * (r1 + r2) + (x2 - x1) * Math.sqrt(delta1),
c: p1 + p2 + q * Math.sqrt(delta1)
};
let l12 = {
a: (x2 - x1) * (r1 + r2) - (y1 - y2) * Math.sqrt(delta1),
b: (y2 - y1) * (r1 + r2) - (x2 - x1) * Math.sqrt(delta1),
c: p1 + p2 - q * Math.sqrt(delta1)
};
results.push(l11);
results.push(l12);
}
if(delta2 >= 0) {
let l21 = {
a: (x2 - x1) * (r1 - r2) + (y1 - y2) * Math.sqrt(delta2),
b: (y2 - y1) * (r1 - r2) + (x2 - x1) * Math.sqrt(delta2),
c: p1 - p2 + q * Math.sqrt(delta2)
};
let l22 = {
a: (x2 - x1) * (r1 - r2) - (y1 - y2) * Math.sqrt(delta2),
b: (y2 - y1) * (r1 - r2) - (x2 - x1) * Math.sqrt(delta2),
c: p1 - p2 - q * Math.sqrt(delta2)
};
results.push(l21);
results.push(l22);
}
return results;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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