Public
Edited
May 17, 2024
Insert cell
Insert cell
Insert cell
Insert cell
domains = ({SchwarzD:1,SchwarzP:3, Gyroid:1.5, IWP:5, "F-K S":1.5, "F-K C(Y)":4, "Split P":2, "F-RD":7, "G Prime":1.4})
Insert cell
surfaces = ["SchwarzD", "SchwarzP", "Gyroid", "IWP", "F-K S", "F-K C(Y)", "Split P", "F-RD", "G Prime"]
Insert cell
offset = Math.round((now / 1600) % (2*Math.PI) * 1000) / 1000
Insert cell
function tpms(x,y,z){return 1/domains[surface] * TPMS(surface)(x,y,z)}
Insert cell
function TPMS(surface = "SchwarzD") {
const sin = Math.sin;
const cos = Math.cos;
switch (surface) {
case "SchwarzD":
return (x, y, z) => cos(x) * cos(y) * cos(z) - sin(x) * sin(y) * sin(z);
case "SchwarzP":
return (x, y, z) => cos(x) + cos(y) + cos(z);
case "Gyroid":
return (x, y, z) => sin(x) * cos(y) + sin(y) * cos(z) + sin(z) * cos(x);
case "IWP": {
return (x, y, z) =>
2 * (cos(x) * cos(y) + cos(y) * cos(z) + cos(x) * cos(z)) -
(cos(2 * x) + cos(2 * y) + cos(2 * z));
}
case "F-K S":
return (x, y, z) =>
cos(2 * x) * sin(y) * cos(z) +
cos(2 * y) * sin(z) * cos(x) +
cos(2 * z) * sin(x) * cos(y);
case "F-K C(Y)":
return (x, y, z) =>
sin(2 * x) * sin(y) +
sin(2 * y) * sin(z) +
sin(x) * sin(2 * z) -
cos(x) * cos(y) * cos(z) +
sin(2 * x) * cos(z) +
cos(x) * sin(2 * y) +
cos(y) * sin(2 * z) -
sin(x) * sin(y) * sin(z);
case "Split P":
return (x, y, z) =>
1.1 *
(sin(2 * x) * sin(z) * cos(y) +
sin(2 * y) * sin(x) * cos(z) +
sin(2 * z) * sin(y) * cos(x)) -
0.2 *
(cos(2 * x) * cos(2 * y) +
cos(2 * y) * cos(2 * z) +
cos(2 * z) * cos(2 * x)) -
0.4 * (cos(2 * x) + cos(2 * y) + cos(2 * z));
case "F-RD":
return (x, y, z) =>
4 * cos(x) * cos(y) * cos(z) -
cos(2 * x) * cos(2 * y) -
cos(2 * y) * cos(2 * z) -
cos(2 * x) * cos(2 * z);
case "G Prime":
return (x, y, z) =>
sin(2 * x) * cos(y) * sin(z) +
sin(2 * y) * cos(z) * sin(x) +
sin(2 * z) * cos(x) * sin(y);
}
}
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