Skip to content
/ VoroBox Public

Constrained Voronoi Diagrams in 2D - not clipped so each cell is a true Voronoi cell.

License

Notifications You must be signed in to change notification settings

oycar/VoroBox

Repository files navigation

Australia

VoroBox

Quick Summary

VoroBox produces Conforming Voronoi Diagrams in 2D. These diagrams fill either a polygon or the convex hull of a set of points specified in an YAML or JSON formatted input file. It outputs two or more VTK files suitable for drawing the resulting diagram and (optionally) YAML files in the same format as the input which can be used to iterate the diagram. The Voronoi cells produced are not clipped, they are accurate representations of the nearest neighbour domains produced from the initial data. VoroBox is written in Swift, and is in a Swift Package Manager format which can be run on any system with swift installed.

Install

Prerequisites are Swift - you can run VoroBox using the swift package manager on either an Apple machine or Linux. I haven't tried to use it under Windows. The example input files are in YAML; but VoroBox expects a JSON file so you'll need a convertor. I use a simple ruby script. For convenience VoroBox use the Files package. To see the output plots you'll need a plotting package that can read VTK files; pyvista is one such.

Input and Output is Text Data

Once you have a YAML input file prepared you need to generate a file Zones/zoneData.json which VoroBox will read. To create complex geometries you can combine several zones where each zone is a "weakly simple polygon" with no internal holes; by combining them arbitrarily complex shapes can be triangulated. The Zones folder has some examples. By default each zone is listed in an anticlockwise direction; if you need to you can specify order: clockwise to reverse this. By default VoroBox produces a Voronoi diagram; here some of the constituent zones have been allowed to blend into each other, whilst one zone is left distinct. Maltese Cross Voronoi Diagram

To achieve this the underlying triangulation is adjusted to make the input points become part of the Voronoi diagram, as a consequence the triangulation can become distorted and overlapping. The red lines show the Voronoi cells, the grey lines the underlying Delaunay triangulation Maltese Cross Edges

but if conformingTo: Delaunay is set a Delaunay triangulation is produced instead. Maltese Cross Triangulation

End Result

Some more images of coastlines; first Tasmania and here is the coast of South Australia shown as edges South Australia

Note

I couldn't find a good example of conforming Voronoi diagrams in the public domain so I wrote this as a way to learn Swift. The triangulation code is a port of the Delaunator javascript library of mapbox to the Swift programming language, although several modification have been made. VoroBox still uses a flat array data structure of halfEdges and vertices to organize the meshes.