Skip to main content

Cells in space

In space the rule is the same as on a face: each seed owns the region nearer to it than to any other seed. The border between two seeds is now a plane, halfway between them and square to the line that joins them, and each cell is a convex polyhedron with flat faces. bitbybit.occt.patterns.voronoi.cells3d splits a solid into those cells, and bitbybit.occt.patterns.voronoi.seeds3d places seeds inside a solid the way seeds2d does in a face.

Solids, faces or edges​

output says what cells3d builds:

  • solids, the default: one closed solid a cell, each built from its own faces, so every cell is a part you can measure, move, colour or export on its own.
  • faces: the faces of the cells, with each face that two cells share made once, as thin walls between the cells.
  • edges: the cells' edges, each made once, the wireframe of the whole diagram.

With faces or edges, walls says whether the pieces lying on the solid's own boundary come too. The solids come out the same either way.

In a box or a convex solid​

A box, or any convex solid of planar faces such as a prism or a lofted frustum, is the cheapest and most exact domain there is: every cell starts as the solid itself and is cut down by the planes it shares with its neighbours, so a cell on the boundary is cut by the boundary's own planes and nothing is approximated. No boolean runs at all.

The cells of a box, pulled apartThe cells of a box, pulled apart, back view
Bitbybit Platform

The cells of a box, pulled apart in Rete

Rete

Drawn in place, the cells fill the box with nothing to see but its outside, so the example pulls them apart. Each cell moves away from the middle by four tenths of its centre's distance from it: bitbybit.occt.shapes.solid.getSolids lists the cells, bitbybit.occt.shapes.solid.getSolidsCentersOfMass gives their centres, bitbybit.point.scalePointsCenterXYZ turns each centre into a move of four tenths of it, and bitbybit.occt.transforms.translateShapes moves each cell by its own. Every step works on the whole list at once, so the same few nodes and blocks do it in Rete and Blockly.

In any solid​

A solid that is not convex, or has curved faces, cannot be cut by its own planes. Its cells are computed in the box around it and then sorted: a cell wholly inside is built as it is, a cell wholly outside is left out, and a cell that crosses the boundary is cut to the solid by a boolean, one cell at a time. So a sphere's inner cells cost nothing extra and only the ring of cells along its surface takes booleans, and the outer cells keep a piece of the round surface.

Cells cut to a sphere, pulled apartCells cut to a sphere, pulled apart, back view
Bitbybit Platform

Cells cut to a sphere, pulled apart in Rete

Rete

bitbybit.occt.patterns.voronoi.cells3dWithReport builds the same cells and reports them: each seed's cell with its volume, its centroid and its placement, inside for a cell built as it was and crossing for one cut by a boolean, and booleans, the number of cuts it took, which the TypeScript tab prints.

A solid with a hole or a thin wall passing through a cell between its corners is still found to cross it: the test measures the distance from each cell to the solid's faces, not only where its corners lie.

The booleans are what a curved domain costs, so count them before reaching for thousands of cells. The cells wholly inside are cheap whatever their number; the ones along the boundary are not.

Faces and edges are made once where two cells share them, which needs every cell cut the same way as its neighbours, so faces and edges need a box or a convex solid, and so do the beams, frames and the compsolid that build on them. A solid that is not one is refused, and the refusal names what was asked for: "patterns.voronoi.cells3d: faces of cells need a box or a convex solid of planar faces", with "edges of cells", "frames" or "beams in space" in place of "faces of cells". The solids, and the foam, take any solid.

Seeds in a solid​

seeds3d places seeds as seeds2d does, at random, on a jittered grid or by Poisson sampling graded by affectors, then relaxes them. In a box or a convex solid it tests each candidate against the solid's planes; in any other solid, against the solid itself, a point on the boundary counting as inside. The seeds come back as a list of points, every one inside the solid, ready for any function on these pages. A seed you add yourself outside the solid is refused by its place in the list, "patterns.voronoi.cells3d: seed 3 lies outside the solid" (or "the shape", for a shape of several solids), unless outsideSeeds drops it.

One compsolid​

The solids from cells3d are independent: two neighbours each have their own copy of the face between them. bitbybit.occt.patterns.voronoi.compSolid builds the cells of a box or a convex solid as one compsolid instead, in which the cells share every vertex, edge and face they meet along: the face between two cells is one face, used by both. Nothing is fused and no boolean runs; the cells are built from the shared pieces directly. That is the shape analysis and meshing across cells need, where a mesh must match on both sides of every wall.

const box = await bitbybit.occt.shapes.solid.createBox({ width: 60, length: 40, height: 40, center: [0, 0, 0] });
const seeds = await bitbybit.occt.patterns.voronoi.seeds3d({ shape: box, count: 24, relax: 2, seed: 5 });
const cells = await bitbybit.occt.patterns.voronoi.compSolid({ shape: box, seeds });
const solids = await bitbybit.occt.shapes.solid.getSolids({ shape: cells });

Like the faces and edges, it needs a box or a convex solid, and refuses any other: "a compsolid of cells needs a box or a convex solid of planar faces".