How do I derive a Voronoi diagram given its point set and its Delaunay triangulation?

26,751

Solution 1

The Voronoi diagram is just the dual graph of the Delaunay triangulation.

  • So, the edges of the Voronoi diagram are along the perpendicular bisectors of the edges of the Delaunay triangulation, so compute those lines.
  • Then, compute the vertices of the Voronoi diagram by finding the intersections of adjacent edges.
  • Finally, the edges are then the subsets of the lines you computed which lie between the corresponding vertices.

Note that the exact code depends on the internal representation you're using for the two diagrams.

Solution 2

If optimal speed is not a consideration, the following psuedo code will generate a Voronoi diagram the hard way:

for yloop = 0 to height-1
  for xloop = 0 to width-1

    // Generate maximal value
    closest_distance = width * height

    for point = 0 to number_of_points-1
      // calls function to calc distance
      point_distance = distance(point, xloop, yloop)

      if point_distance < closest_distance
        closest_point = point
      end if
    next

  // place result in array of point types
  points[xloop, yloop] = point

  next
next

Assuming you have a 'point' class or structure, if you assign them random colours, then you'll see the familiar voronoi pattern when you display the output.

Solution 3

After trying to use this thread as a source for answers to my own similar question, I found that Fortune's algorithm — likely because it is the most popular & therefore most documented — was the easiest to understand.

The Wikipedia article on Fortune's algorithm keeps fresh links to source code in C, C#, and Javascript. All of them were top-notch and came with beautiful examples.

Share:
26,751
Kalzem
Author by

Kalzem

Full Stack Dev in training, long time game developer.

Updated on February 08, 2020

Comments

  • Kalzem
    Kalzem over 4 years

    I'm working on a game where I create a random map of provinces (a la Risk or Diplomacy). To create that map, I'm first generating a series of semi-random points, then figuring the Delaunay triangulations of those points.

    With that done, I am now looking to create a Voronoi diagram of the points to serve as a starting point for the province borders. My data at this point (no pun intended) consists of the original series of points and a collection of the Delaunay triangles.

    I've seen a number of ways to do this on the web, but most of them are tied up with how the Delaunay was derived. I'd love to find something that doesn't need to be integrated to the Delaunay, but can work based off the data alone. Failing that, I'm looking for something comprehensible to a relative geometry newbie, as opposed to optimal speed. Thanks!

  • batty
    batty about 15 years
    You can also find the dual (ie. Voronoi diagram) just by computing the circumcentres of all the triangles, and connecting any two circumcentres whose triangles share an edge.
  • nit
    nit almost 15 years
    As suggested in the above comment, I would do it in two steps: 1. Compute the circumcenter of every Delaunay triangle -> these are the Voronoi vertices. See en.wikipedia.org/wiki/… 2. For every Delaunay edge, compute a Voronoi edge: the segment connecting the circumcenters of the two neighboring Delaunay triangles.
  • nit
    nit almost 15 years
    Note that although for every Delaunay triangle corresponds one Voronoi vertex, this vertex can be outside the triangle, as well. see an example here: mathopenref.com/trianglecircumcenter.html
  • Tara
    Tara over 9 years
    That's all nice and dandy, but I don't see any use for a Voronoi diagram generated as an image. Maybe there is one?
  • Tomilov Anatoliy
    Tomilov Anatoliy about 8 years
    @balint.miklos What to do with outer sites/triangles?
  • PixelArtDragon
    PixelArtDragon about 8 years
    Not as an image per se, but I've used it for procedural tile-based world generation (where each tile is determined by the cell to which it belongs).