Public
Edited
Sep 29, 2023
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
area = (d, r1, r2) => {
return (
r1**2 * Math.acos( (d**2+r1**2-r2**2) / (2*d*r1) ) + r2**2 * Math.acos( (d**2 -r1**2 + r2**2) / (2*d*r2) )
-.5 * Math.sqrt( (d+r1+r2) * (-d+r1+r2) * (d-r1+r2) * (d+r1-r2) )
)
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
distance = ( A, B, AB) => { // arguments are number of set elements
const iterations = 5
const r1 = Math.sqrt( A / Math.PI )
const r2 = Math.sqrt( B / Math.PI )

// set exclusion
if( AB <= 0 ){ return r1+r2+1 }
// set inclusion
else if ( A <= AB || B <= AB){ return 0 }
// set intersection
else{
let x1 = Math.abs( r1-r2 )
let x2 = r1+r2
let y1 = Math.PI * Math.min(r1**2, r2**2)
let y2 = 0
let guess, guessArea
for( let i=0; i<iterations; i++){
guess = (x2-x1) / (y2-y1) * ( AB - y1) + x1
guessArea = area( guess, r1, r2 )
if( guessArea > AB ){
x1 = guess
y1 = guessArea
}else{
x2 = guess
y2 = guessArea
}
}
return (x2-x1) / (y2-y1) * ( AB - y1) + x1
}
}
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