Public
Edited
Dec 4, 2024
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
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
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
usedPolygon = usePolygonInterpolation
? interpolatePolygon(polygon, gridSize)
: polygon
Insert cell
gridPointsInPolygon = grid.filter((point) => {
if (robustPointInPolygon.default(polygon, point) == -1) {
return true;
}
})
Insert cell
usedPolygonAndGrid = useGrid
? [...usedPolygon, ...gridPointsInPolygon]
: usedPolygon
Insert cell
delaunatorTriangles = {
const delaunator = Delaunator.from(usedPolygonAndGrid)
const coordinates = [];
for (let i = 0; i < delaunator.triangles.length; i += 3) {
coordinates.push([
usedPolygonAndGrid[delaunator.triangles[i]],
usedPolygonAndGrid[delaunator.triangles[i + 1]],
usedPolygonAndGrid[delaunator.triangles[i + 2]]
]);
}
return coordinates;
}
Insert cell
edgeIndices = {
const indices = [];
for (let i = 0; i < usedPolygon.length - 1; i++) {
indices.push([i, i + 1]);
}
indices.push([usedPolygon.length - 1, 0]);
return indices;
}
Insert cell
constrainautorTriangles = {
if (polygon.length < 3) {
return [];
}
const del = Delaunator.from(usedPolygonAndGrid);
const con = new Constrainautor(del, edgeIndices);

const coordinates = [];
for (let i = 0; i < con.del.triangles.length; i += 3) {
coordinates.push([
usedPolygonAndGrid[con.del.triangles[i]],
usedPolygonAndGrid[con.del.triangles[i + 1]],
usedPolygonAndGrid[con.del.triangles[i + 2]]
]);
}
return coordinates;
}
Insert cell
insideTriangles = {
const coordinates = [];
for (let i = 0; i < constrainautorTriangles.length; i++) {
const triangleMidPoint = [
(1 / 3) * constrainautorTriangles[i][0][0] +
(1 / 3) * constrainautorTriangles[i][1][0] +
(1 / 3) * constrainautorTriangles[i][2][0],
(1 / 3) * constrainautorTriangles[i][0][1] +
(1 / 3) * constrainautorTriangles[i][1][1] +
(1 / 3) * constrainautorTriangles[i][2][1]
];

if (robustPointInPolygon.default(polygon, triangleMidPoint) == -1) {
coordinates.push(constrainautorTriangles[i]);
}
}
return coordinates;
}
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