 Komm - 1 year ago 87
C# Question

# Generate Voronoi diagram without using Fortune's algorithm

I'm hoping to create a Voronoi landscape in Unity in C#. I looked at a number of Unity Project files, but they all implement Fortune's algorithm, which is completely over my head. Are there any other methods of generating Voronoi diagram (that is easier to understand)?
Slow performance is completely fine with me.
Much appreciated!

Sidenote: Since I'm working in Unity and need to generate 2D/3D mesh from Voronoi diagram, per-pixel distance check won't work :,(
On second thought, maybe I could use a 2D array of Vector2s instead of pixels, that are 1.0 unit spaced apart in x and z axis. gue

There is a very simple way to create an approximated Voronoi diagram VD. For every Site `s` that should define a cell in the VD (2D-plane) you center a cone at `s` with constant slope and a certain height. Then you look from above onto that landscape of cones (where all the spikes are visible). The boundary where the different cones meet (projected to the 2D-plane) is the (approximated) Voronoi diagram. As you requested in the comments, to get the actual edge data seems not so easy. But there could be some graphical routines to generate them by intersecting the cones.

An alternative is to compute a Delaunay triangulation of the given point set. There are some implementation referenced in this related post (also simple approximations are mentioned). Then you compute the dual graph of your triangulation and you have the Voronoi diagram. (Dual graph means that for every for every edge `AB` in the triangulation there exists an edge in the VD bisecting the space between the two vertices `A` and `B`, and for every triangle there exists a vertex in the VD where the dual edges meet.) Othwerwise there are also many `C#` Voronoi implementations around: Unity-delaunay, but as you mentioned using the Fortune approach.

If you want to code everything yourself you may compute a triangulation of the points with brute force for `n` points in `O(n^2)` time. Then apply in-circle tests and edge flips. That is, for every triangle `t(abc)` create a circle `C` defined by the three vertices of `t`. Then check if there lies another point `d` of your point set inside `C`. If so, then flip the edge that is in `t` as well as forms an edge in the triangle with `d`. This flipping is done until all triangles fulfil the empty circle property (Delaunay condition). Again with brute force will take `O(n^2)` time. Then you can compute the dual graph as mentioned above. Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download