Public
Edited
Sep 12, 2020
Importers
Insert cell
Insert cell
{
while (true) {
yield new Promise(resolve => {
setTimeout(() => resolve(createRandomizedFigure()), 1000);
});
}
}
Insert cell
{
const set1 = [
s(v(1, 0), v(0, 1)),
s(v(0, 1), v(0, 2)),
s(v(0, 2), v(1, 3)),
];
const set2 = [
s(v(1, 0), v(0, 1)),
s(v(0, 2), v(1, 3)),
];
const dSet1 = densifyAll(set1, 0.1);
const dSet2 = densifyAll(set2, 0.1);
const h = maxHausdorffDistance(dSet1, dSet2);

return createFigure(dSet1, dSet2, h);
}
Insert cell
{
const set1 = [
s(v(1, 0), v(0, 1)),
s(v(0, 1), v(0, 2)),
s(v(0, 2), v(1, 3)),
];
const set2 = set1.map(seg => {
return s(v(seg.p1.x + 0.1, seg.p1.y + 0.1), v(seg.p2.x + 0.1, seg.p2.y + 0.1))
});
const dSet1 = densifyAll(set1, 0.1);
const dSet2 = densifyAll(set2, 0.1);
const h = maxHausdorffDistance(dSet1, dSet2);

return createFigure(dSet1, dSet2, h);
}
Insert cell
function maxHausdorffDistance(segments1, segments2) {
return Math.max(
hausdorffDistance(segments1, segments2),
hausdorffDistance(segments2, segments1)
);
}
Insert cell
function hausdorffDistance(segments1, segments2) {
let max = 0;
for (const segment of segments1) {
const minDist = minimalDistance(segment, segments2);
if (minDist > max) {
max = minDist;
}
}
return max;
}
Insert cell
function minimalDistance(segment, segments) {
let min = Number.MAX_VALUE;
for (const otherSegment of segments) {
const dist = segment.distanceFromSegment(otherSegment);
if (dist < min) {
min = dist;
}
}
return min;
}
Insert cell
function densifyAll(segments, maxLength) {
return segments.flatMap(s => densify(s, maxLength));
}
Insert cell
Insert cell
Insert cell
Insert cell
import { densify } from '1644a2915de754ae'
Insert cell
import { Segment, Vector, Figure, s, v } from '98496f10eb8a3c09'
Insert cell
jsts = require('jsts')
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