Public
Edited
Aug 30, 2024
Paused
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
surfaces = ["SchwarzD", "SchwarzP", "Gyroid", "IWP", "F-K S", "F-K C(Y)", "Split P", "F-RD", "G Prime"]
Insert cell
Dvals = getValues(maxX, maxY, maxZ, divisions, surface)
Insert cell
function getValues(w, d, h, divisions, surface) {
const X = [],
Y = [],
Z = [],
val = [],
xStart = 0,
yStart = 0,
zStart = 0,
maxX = w * Math.PI,
maxY = d * Math.PI,
maxZ = h * Math.PI,
scope = {};
const TPMSfunction = TPMS(surface, scope);
const delta = Math.PI / divisions;
for (let x = xStart; x < maxX + delta / 2; x += delta) {
for (let y = yStart; y < maxY + delta / 2; y += delta) {
for (let z = zStart; z < maxZ + delta / 2; z += delta) {
const xTrim = Math.min(x, maxX);
const yTrim = Math.min(y, maxY);
const zTrim = Math.min(z, maxZ);
X.push(xTrim);
Y.push(yTrim);
Z.push(zTrim);
val.push(TPMSfunction(xTrim, yTrim, zTrim));
}
}
}
return { X, Y, Z, val, scope };
}
Insert cell
function TPMS(surface = "SchwarzD", scope) {
scope.sinTable = {};
scope.cosTable = {};
function cos(number) {
const foundResult = scope.cosTable[number];
if (foundResult === undefined) {
const result = Math.cos(number);
scope.cosTable[number] = result;
return result;
} else {
return foundResult;
}
}
function sin(number) {
const foundResult = scope.sinTable[number];
if (foundResult === undefined) {
const result = Math.sin(number);
scope.sinTable[number] = result;
return result;
} else {
return foundResult;
}
}
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)+0.32
}
}
Insert cell
data = [
{
type: "isosurface",
x: Dvals.X,
y: Dvals.Y,
z: Dvals.Z,
value: Dvals.val,
isomin: isomin <= isomax ? isomin : isomax - 1 / 16,
isomax: isomax >= isomin ? isomax : isomin + 1 / 16
//colorscale: "Reds"
}
]
Insert cell
layout = ({
margin: { t: 0, l: 0, b: 0 },
scene: {
camera: {
eye: {
x: 1.88,
y: -2.12,
z: 0.96
}
}
}
})
Insert cell
{
Plotly.react(graphDiv, data, layout, { showSendToCloud: true });
}
Insert cell
Plotly = require("https://cdn.plot.ly/plotly-2.29.1.min.js")
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