Skip to main content

Voronoi patterns

Scatter a few points over a sheet and give every spot on the sheet to the point nearest to it. The sheet falls apart into regions, one around each point, and those regions are Voronoi cells. The points are their seeds: each seed owns the part of the plane, or of space, that is nearer to it than to any other seed.

The rule is simple enough to see the whole shape of a cell in it. Two seeds share the ground exactly halfway between them, so the border between their cells is the line (in space, the plane) that cuts the gap between them in half at a right angle. Every cell is what is left of the plane once each neighbour has taken its half, so every cell is a convex polygon, or in space a convex polyhedron, and its edges are straight.

bitbybit.occt.patterns.voronoi builds those cells as exact OCCT shapes, in a planar face or in a solid that you give it, and builds what can be made from them: perforated faces, frames and hollow walls, beam lattices, closed-cell and open-cell foam. It also places the seeds and grades them with fields. The Voronoi functions are new and marked beta: their names and the shape of their reports may still change.

Why nature draws them​

Start many things growing at once, each from its own point and at the same speed, and let each stop where it meets a neighbour. Every meeting line lies halfway between two starting points, and what you get is a Voronoi diagram. Much of what grows, dries or packs works roughly that way, so patterns close to Voronoi cells turn up everywhere:

  • Giraffe skin. The reticulated giraffe's patches are polygons separated by narrow pale lines, much like cells with their edges drawn wide.
  • Dragonfly wings. A thin membrane is held by a network of veins; between the long veins, cross veins divide it into small polygonal cells, finest along the leading edge.
  • Leaf veins. The smallest veins of a leaf enclose little islands of tissue, each fed from the veins around it.
  • Bone. The spongy bone inside the ends of long bones is a three-dimensional lattice of thin struts and plates.
  • Foam. Soap foam and closed-cell foams are packed cells sharing thin walls, each cell sealed from its neighbours.
  • Cracked mud. Drying mud shrinks toward many centres at once and cracks along the lines between them.
  • Honeycomb. Seeds spaced evenly on a triangular grid give regular hexagons: the hexagon is the Voronoi cell of that arrangement, the one bees build.

Real cells are rarely all alike. Some start earlier or grow faster, and a cell then takes more than half of the gap to its neighbour. Bitbybit models that with weights, below, and every operation here can be graded so that cells, holes, beams or voids change size across a part.

A first diagram​

The face below has curved edges, a concave stretch along one side and a round hole. bitbybit.occt.patterns.voronoi.seeds2d scatters sixty seeds over it at random and evens them out with two rounds of relaxation, and bitbybit.occt.patterns.voronoi.cells2d splits the face into one cell a seed. The seeds are drawn as points, the cells as faces.

Voronoi cells in a face with a holeVoronoi cells in a face with a hole, front view
Bitbybit Platform

Voronoi cells in a face with a hole in Rete

Rete

Every point of a cell is nearer its own seed than any other. Look along the hole and the concave edge: a cell there is cut by the face's boundary, and a cell that the boundary splits in two, around the hole, keeps both pieces. Nothing about the face is special: its edges may be curved, it may have holes, and seeds that do not lie on its plane are taken onto it along its normal.

What Bitbybit builds​

Exact geometry. Each cell is computed from its seed and its neighbours, and then built as an exact face or solid from straight edges and planar faces, so a cell is as precise as the kernel and measures, exports and takes booleans like any other shape. In a convex face of straight edges, or a box, or any convex solid of planar faces, every cell is cut to the boundary exactly by the boundary's own lines and planes. In any other face or solid, the cells are computed in the box around it, and each cell that crosses the boundary is cut to it by a boolean, one boolean a crossing cell. The cells wholly inside need none, so a curved or holed domain costs about as many booleans as there are cells along its edge.

Faces or edges. cells2d builds one face a cell, as above, or, with output set to edges, the cells' edges with each edge that two cells share made once, which is what a drawing, a beam or a cut along the borders needs. walls says whether the pieces of the face's own boundary that close the cells come too.

Weighted cells. Give each seed a weight and the borders move: a heavier seed's border is pushed away from it, so its cell grows at its neighbours' cost, and a seed far outweighed by those around it may be left with no cell at all. These are power cells, also called Laguerre cells. They stay convex with straight borders, so everything on these pages works for them unchanged. Weights are in squared model units: the border between two seeds moves toward the lighter one by the difference of their weights divided by twice the distance between them, so seeds 20 apart whose weights differ by 100 have their border 2.5 off the middle. Seeds and fields grades them with a field.

Delaunay joins. Join every two seeds whose cells share an edge and you get the Delaunay triangulation, the Voronoi diagram's twin: each join is square to the border it stands for, and each corner where three cells meet is the centre of a circle through their three seeds. bitbybit.occt.patterns.voronoi.delaunay2d builds the joins as straight edges, or, with output set to triangles, as flat triangles between every three seeds whose cells meet at a point, as below. It reads the cells inside the face, so in a face that is not convex, two seeds whose cells would meet only outside it stay apart.

Voronoi cells over their Delaunay trianglesVoronoi cells over their Delaunay triangles, front view
Bitbybit Platform

Voronoi cells over their Delaunay triangles in Rete

Rete

The white faces are the Delaunay triangles, a seed at each corner. The orange lines over them are the cells' edges, drawn as thin round beams with beams2d from Lattices, frames and foam so they stand out against the white. Each triangle's edge and the cell edge it stands for cross at a right angle, or would if both were long enough.

The report. Most functions have a twin that also tells you what was built, such as bitbybit.occt.patterns.voronoi.cells2dWithReport and bitbybit.occt.patterns.voronoi.delaunay2dWithReport. A report gives one entry a seed, in the order of the seeds, with its cell's state (built; empty when its cell holds no part of the face, as a seed far outweighed has none; merged; dropped), its area or volume, its centroid and where it lies against the face or solid (inside, cut exactly; crossing, cut by a boolean). It gives one entry a piece of the result too, the seeds whose cells the piece belongs to or lies between and the walls of the face or solid it lies on, numbered as bitbybit.occt.shapes.edge.getEdges and bitbybit.occt.shapes.face.getFaces number them. booleans says how many cells needed a boolean.

Seeds outside, and seeds too close​

A seed outside the face or solid is refused by its place in the list, "patterns.voronoi.cells2d: seed 3 lies outside the face" (in a solid, "the solid"), unless outsideSeeds is set to drop, which leaves it out and reports its cell as dropped.

Two seeds in one place are refused too, unless coincidentSeeds is set to merge, which merges each into the first of them. The functions that put one piece where two cells meet, the shared edges and the Delaunay joins in a face, and the shared faces, edges, beams, frames and the compsolid in a solid, need their seeds a little further apart than that: at least a millionth of the face's diagonal, or a hundred-thousandth of the solid's box diagonal. Seeds closer than that would let a third cell mislabel the stretch between them, so they are refused by name, with the setting that merges them: seeds 0 and 3 are closer than 0.000116619, too close to build what their cells share; coincidentSeeds: "merge" merges them. They are merged when you ask for it. Random seeds land that close only rarely, and Poisson seeds never do.

Separate pieces, ready to print​

The cells, their edges and joins, the beams and the frames come as a compound of independent pieces: one face or solid a cell, one beam a strut and one sphere a node, one frame a face. Nothing is fused, so each piece is built on its own, and can be picked, measured or coloured on its own. Where pieces overlap, as beams do at their nodes, they stay overlapping. That is what a 3D printer needs: export the compound and print it, since slicers merge overlapping bodies into one. A step that needs a single solid inside Bitbybit can fuse the pieces with a boolean, at a boolean's cost.

A perforated face is one face with its holes. Two more results are single shapes by construction, built from faces made once and shared, never from booleans: the foam, one solid with a void in each cell, sealed or joined to its neighbours through windows, and the compsolid, all the cells of a box or convex solid sharing every face they meet along.

The pages of this section​

  • Seeds and fields: random, grid and Poisson seeds, Lloyd relaxation, and affector fields that grade seeds, weights, sizes and openings.
  • Perforated faces: one hole a cell, scaled or inset, rounded, kept off the edges and graded, and a sheet metal vent panel.
  • Cells in space: cells in a box, a convex solid and any solid, pulled apart, and the compsolid.
  • Lattices, frames and foam: beams on the cells' edges, frames and hollow walls on their faces, and closed-cell and open-cell foam.
  • Made for 3D printing: a dragonfly-wing pendant, a lattice mount, an arm with a graded foam core and a tea-light lantern, each built step by step.

Every function​

FunctionWhat it does
affectorMakes a shape an affector: points, curves, faces, shells or solids whose nearness grades cells, through field and the seed methods.
beams2dPuts a beam on every edge of the Voronoi cells of seeds in a planar face, each shared edge once, with a sphere at each node.
beams2dWithReportPuts beams on the cells' edges in a planar face as beams2d does, and reports each cell, each beam and sphere, and the beams as a graph.
beams3dPuts a beam on every edge of the Voronoi cells of seeds in a convex solid, each shared edge once, with a sphere at each node: a strut lattice.
beams3dWithReportPuts beams on the cells' edges in a convex solid as beams3d does, and reports each cell, each beam and sphere, and the beams as a graph.
cells2dSplits a planar face into the Voronoi cells of seeds, each the part nearer its seed than any other.
cells2dWithReportSplits a planar face into Voronoi cells as cells2d does, and reports each seed's cell and each piece of the compound.
cells3dSplits a solid into the Voronoi cells of seeds, each the part nearer its seed than any other.
cells3dWithReportSplits a solid into Voronoi cells as cells3d does, and reports each seed's cell and each piece of the compound.
compSolidBuilds the Voronoi cells of seeds in a convex solid as one compsolid, whose cells share every vertex, edge and face they meet along.
delaunay2dJoins the seeds whose Voronoi cells meet inside a planar face, by the edges or triangles of their Delaunay triangulation.
delaunay2dWithReportJoins seeds as delaunay2d does, and reports each seed's cell and the seeds each edge or triangle joins.
fieldGives the affectors' combined influence at each point, mapped linearly from 0 and 1 onto from and to.
foamMakes a solid into foam: one solid holding a void in each seed's Voronoi cell, the cell scaled by scale or inset by inset.
foamWithReportMakes a solid into foam as foam does, and reports what became of each seed's cell and void.
frames3dBuilds every face between the Voronoi cells of seeds in a convex solid once, each with a window scaled by scale or inset by inset, its corners rounded by radius.
frames3dWithReportFrames the faces between Voronoi cells as frames3d does, and reports each seed's cell and each frame or hollow cell.
perforatePerforates a planar face with one hole a seed's Voronoi cell, each cell shrunk by scale about its centroid or by inset along its edges, its corners rounded by radius.
perforateWithReportPerforates a planar face as perforate does, and reports what became of each seed's cell and hole.
seeds2dPlaces seeds in a planar face: at random, on a jittered grid, or evenly spaced by Poisson sampling, whose spacing affectors can grade; then evens them out by relax rounds.
seeds3dPlaces seeds in a solid: at random, on a jittered grid, or evenly spaced by Poisson sampling, whose spacing affectors can grade; then evens them out by relax rounds.