Public
Edited
Nov 29, 2024
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

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