Voronoi diagram: Difference between revisions

m
whitespace/formatting
m (minor rewording)
m (whitespace/formatting)
Line 1:
{{Draft task}}
 
A [[wp:Voronoi Diagram|Voronoi Diagram]] is a diagram consisting of a number of sites. Each Voronoi ''s'' also has a Voronoi cell consisting of all points closest to ''s''.
 
Line 8 ⟶ 7:
[[File:voronoi-C.png|center|300px]]
C code drawing a color map of a set of Voronoi sites. Image is in PNM P6, written to stdout. Run as <code>a.out > stuff.pnm</code>.
<lang Cc>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Line 75 ⟶ 74:
return 0;
}</lang>
 
=={{header|Python}}==
 
This implementation takes in a list of points, each point being a tuple and returns a dictionary consisting of all the points at a given site.
<lang python>def generate_voronoi(points):
 
<lang python>
def generate_voronoi(points):
minx, miny = points[0]
maxx, maxy = points[0]
Line 115 ⟶ 112:
return voronoi </lang>
=== Sample Output: ===
<lang python>voronoi = generate_voronoi([(0, 0), (5, 5)]) <br>
voronoi[0] : (0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (0, 1), (1, 1), (2, 1), (3, 1), (4, 1), (0, 2), (1, 2), (2, 2), (3, 2), (0, 3), (1, 3), (2, 3), (0, 4), (1, 4), (0, 5) // Points closest to (0, 0) <br>
voronoi[1] : (5, 1), (4, 2), (5, 2), (3, 3), (4, 3), (5, 3), (2, 4), (3, 4), (4, 4), (5, 4), (1, 5), (2, 5), (3, 5), (4, 5), (5, 5) // Points closest to (5, 5) <br/lang>
Anonymous user