Public
Edited
Oct 16, 2022
4 stars
Also listed in…
Math
PlotX3D
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
function boxes(n, t) {
let boxes = [];
for (let x = -1; x < 0.999; x = x + 2 / n) {
for (let y = -1; y < 0.999; y = y + 2 / n) {
boxes.push(box(x, y, n, t));
}
}
return boxes.flat();
}
Insert cell
function box(x0, y0, n, t) {
let box = create_box([2 / n, 2 / n, f(x0, y0)], {
translation: `${x0 + 1 / n}, ${y0 + 1 / n}, ${f(x0, y0) / 2}`,
color: "#40bfbf",
transparency: t,
class: `box box${n}`
});
let edges = create_indexedLineSet(
[
[
[x0, y0, 0],
[x0, y0, f(x0, y0)]
],
[
[x0 + 2 / n, y0, 0],
[x0 + 2 / n, y0, f(x0, y0)]
],
[
[x0 + 2 / n, y0 + 2 / n, 0],
[x0 + 2 / n, y0 + 2 / n, f(x0, y0)]
],
[
[x0, y0 + 2 / n, 0],
[x0, y0 + 2 / n, f(x0, y0)]
],
[
[x0, y0, f(x0, y0)],
[x0 + 2 / n, y0, f(x0, y0)],
[x0 + 2 / n, y0 + 2 / n, f(x0, y0)],
[x0, y0 + 2 / n, f(x0, y0)],
[x0, y0, f(x0, y0)]
],
[
[x0, y0, 0],
[x0 + 2 / n, y0, 0],
[x0 + 2 / n, y0 + 2 / n, 0],
[x0, y0 + 2 / n, 0],
[x0, y0, 0]
]
],
{ transparency: t, class: `box box${n}` }
);
return [box, edges];
}
Insert cell
d3.color("#40bfbf").darker()
Insert cell
function slices(n) {
let slices = d3.range(-1, 1, 2 / n).map((x0) => slice(x0, n, n == 4 ? 0 : 1));
return slices;
}
Insert cell
function slice(x0, n, t) {
return [
create_surface((x, y) => [x, y, f(x0, y)], [x0, x0 + 2 / n], [-1, 1], {
nu: 4,
Nu: 4,
nv: 8,
Nv: 50,
transparency: t,
class: `slice slice${n}`
}),
create_surface((y, z) => [x0, y, z * f(x0, y)], [-1, 1], [0, 1], {
nu: 1,
Nu: 50,
nv: 1,
Nv: 1,
transparency: t,
class: `slice slice${n}`
}),
create_surface((y, z) => [x0 + 2 / n, y, z * f(x0, y)], [-1, 1], [0, 1], {
nu: 1,
Nu: 50,
nv: 1,
Nv: 1,
transparency: t,
class: `slice slice${n}`
}),
create_surface((x, z) => [x, 1, z * f(x0, 1)], [x0, x0 + 2 / n], [0, 1], {
nu: 1,
Nu: 1,
nv: 1,
Nv: 1,
transparency: t,
class: `slice slice${n}`
}),
create_surface((x, z) => [x, -1, z * f(x0, -1)], [x0, x0 + 2 / n], [0, 1], {
nu: 1,
Nu: 1,
nv: 1,
Nv: 1,
transparency: t,
class: `slice slice${n}`
})
];
}
Insert cell
f = (x, y) => (y ** 3 - y - x + 2) / 3
Insert cell
import {
show_x3d,
create_indexedFaceSet,
create_indexedLineSet,
create_surface,
create_box
} from "@mcmcclur/plotx3d"
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