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

前端 未结 4 2225
栀梦
栀梦 2020-12-13 09:26

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 fig

相关标签:
4条回答
  • 2020-12-13 09:54

    Each of your Delaunay triangles contains a single point of the Voronoi diagram.

    You can compute this point by finding the intersection of the three perpendicular bisectors for each triangle.

    Your Voronoi diagram will connect this set of points, each with it's nearest three neighbors. (each neighbor shares a side of the Delaunay triangle)

    How do you plan on approaching the edge cases?

    0 讨论(0)
  • 2020-12-13 10:02

    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.

    0 讨论(0)
  • 2020-12-13 10:11

    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.

    0 讨论(0)
  • 2020-12-13 10:14

    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.

    0 讨论(0)
提交回复
热议问题