Published
Edited
Jul 8, 2020
3 stars
Also listed in…
Hello
Insert cell
Insert cell
{
const context = DOM.context2d(width, 500);
context.beginPath();
d3.Delaunay.from(points).render(context);
context.stroke();

context.save();
context.beginPath();
context.setLineDash([3, 3]);
context.strokeStyle = "brown";
context.lineWidth = 1.5;
context.moveTo(...points[0]);
context.lineTo(...points[2]);
context.stroke();

context.restore();

context.fillText("Delaunay triangulation", 20, 20);

context.translate(width / 2, 0);
context.beginPath();
constrained.render(context);
context.stroke();

context.save();
context.beginPath();
context.strokeStyle = "brown";
context.lineWidth = 1.5;
for (const [a, b] of constrains) {
context.moveTo(...points[a]);
context.lineTo(...points[b]);
}
context.stroke();

context.fillText("Constrained triangulation", 20, 20);
return context.canvas;
}
Insert cell
points = [[150, 50], [50, 200], [150, 350], [250, 200]]
Insert cell
constrains = [[0, 2]]
Insert cell
constrained = {
const del = d3.Delaunay.from(points);
const con = new Constrainautor(del._delaunator);
for (const c of constrains) con.constrainOne(...c);
con.delaunify();
return del;
}
Insert cell
d3 = require("d3-delaunay@5")
Insert cell
Constrainautor = require("@kninnug/constrainautor")
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