Published
Edited
Nov 9, 2020
3 stars
Insert cell
Insert cell
{
const context = DOM.context2d(width, height);
context.translate(width / 2, height / 2);

const random = d3.randomNormal(0, height / 8);

const points = Array.from({ length: 256 }, () => [random(), random()]);

context.strokeStyle = "steelblue";
for (const [i, j] of qhull(points)) {
const p = points[i],
q = points[j];
context.beginPath();
context.moveTo(p[0], p[1]);
context.lineTo(q[0], q[1]);
context.stroke();
}

for (const p of points) {
context.beginPath();
context.arc(p[0], p[1], 3, 0, 2 * Math.PI);
context.fill();
}

return context.canvas;
}
Insert cell
// "https://bundle.run/qhull-js"
qhull = FileAttachment("qhull-js-0.0.1")
.url()
.then(require)
Insert cell
points = Array.from({ length: 100 }, () => [random(), random(), random()])
Insert cell
// returns a simplicial mesh describing the convex hull of the point set
hull = qhull(points)
Insert cell
d3 = require("d3-random@2")
Insert cell
random = d3.randomNormal()
Insert cell
height = 500
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more