Voronoi diagram: Difference between revisions
Content added Content deleted
m (minor rewording) |
m (whitespace/formatting) |
||
Line 1: | Line 1: | ||
{{Draft task}} |
{{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''. |
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: | Line 7: | ||
[[File:voronoi-C.png|center|300px]] |
[[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>. |
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 |
<lang c>#include <stdio.h> |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
#include <string.h> |
#include <string.h> |
||
Line 75: | Line 74: | ||
return 0; |
return 0; |
||
}</lang> |
}</lang> |
||
=={{header|Python}}== |
=={{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. |
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> |
|||
⚫ | |||
minx, miny = points[0] |
minx, miny = points[0] |
||
maxx, maxy = points[0] |
maxx, maxy = points[0] |
||
Line 115: | Line 112: | ||
return voronoi </lang> |
return voronoi </lang> |
||
=== Sample Output: === |
=== Sample Output: === |
||
voronoi = generate_voronoi([(0, 0), (5, 5)]) |
<lang python>voronoi = generate_voronoi([(0, 0), (5, 5)]) |
||
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) |
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) |
||
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) < |
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) </lang> |