Public
Edited
Nov 29
1 fork
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
polygon
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
TRIANG = {
function TRIANG(polygon, points, distance) {
// initialise Constrained Delaunay Triangulation with polygon
let polygonUsed = usePolygonInterpolation
? interpolatePolygon(polygon, distance)
: polygon;
var swctx = new poly2tri.SweepContext(
polygonUsed.map((p) => new poly2tri.Point(p[0], p[1]))
);
if (useGrid) {
// add grid points as Steiner points if they are inside the polygon
for (var i = 0; i < points.length; i++) {
if (useRobustPointInPolygon) {
if (robustPointInPolygon.default(polygon, points[i]) == -1) {
swctx.addPoint(new poly2tri.Point(points[i][0], points[i][1]));
}
} else {
if (pointInPolygon(points[i], polygon)) {
swctx.addPoint(new poly2tri.Point(points[i][0], points[i][1]));
}
}
}
}
// triangulate
swctx.triangulate();
let triangles = swctx.getTriangles();
return triangles;
}
return TRIANG;
}
Insert cell
Insert cell
Insert cell
triangles.map((t) => t.getPoints().map((p) => [p.x, p.y]))
Insert cell
Insert cell
test = function () {
const pixelTriangleIndex = [];
for (let index = 0; index < triangles.length; index++) {
pixelTriangleIndex[3 * index] = index;
pixelTriangleIndex[3 * index + 1] = index;
pixelTriangleIndex[3 * index + 2] = index;
}
return pixelTriangleIndex;
}
Insert cell
test()
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