Published
Edited
Dec 9, 2021
8 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
T = {
let T = [
[
[
[0, 0],
[1, 0],
[1, 1],
[0, 1]
]
]
];
let n = 7;
for (let i = 0; i < n; i++) {
T = multi_polygon_step(T, i);
}
let An = math.pow(math.inv(A), n);
let S = [
[1, -1 / 2],
[0, Math.sqrt(3) / 2]
];
T = T.map((p) => p.map((pts) => pts.map((xy) => math.multiply(S, An, xy))));
return T;
}
Insert cell
D = [
[0, 0],
[1, 0],
[0, 1],
[-1, -1]
]
Insert cell
A = [
[2, 0],
[0, 2]
]
Insert cell
function multi_polygon_step(mp, n) {
return polygonClipping.union(...mp.map((p) => polygon_step(p, n)));
}
Insert cell
function polygon_step(p, n) {
let An = math.pow(A, n);
return D.map(function (d) {
return p.map((a) => a.map((aa) => math.add(math.multiply(An, d), aa)));
});
}
Insert cell
math = require("mathjs")
Insert cell
polygonClipping = require("polygon-clipping")
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