@@ -12,9 +12,9 @@ The library is available as `SharpVoronoiLib` [NuGet package](https://www.nuget.
1212
1313Alternatively, you can download the solution and either copy the ` SharpVoronoiLib ` project code or build the project and use the ` SharpVoronoiLib.dll ` .
1414
15- # Use
15+ # Usage
1616
17- Quick-start:
17+ ### Quick-start
1818
1919```
2020List<VoronoiSite> sites = new List<VoronoiSite>
@@ -31,6 +31,22 @@ List<VoronoiEdge> edges = VoronoiPlane.TessellateOnce(
3131);
3232```
3333
34+ (Note that the algorithm will ignore duplicate sites, so check ` VoronoiSite.Tesselated ` for skipped sites if duplicates are possible in your data.)
35+
36+ ### Full syntax
37+
38+ Full syntax (leaving a reusable ` VoronoiPlane ` instance):
39+
40+ ```
41+ VoronoiPlane plane = new VoronoiPlane(0, 0, 600, 600);
42+
43+ plane.SetSites(sites);
44+
45+ List<VoronoiEdge> edges = plane.Tessellate();
46+ ```
47+
48+ ### Result structure
49+
3450The tesselation result for the given ` VoronoiSite ` s contains ` VoronoiEdge ` s and ` VoronoiPoint ` s. The returned collection contains the generated edges.
3551
3652![ voronoi terms] ( https://user-images.githubusercontent.com/3857299/213494489-4a6030a2-64d8-4e7e-b556-6f5674d89911.png )
@@ -44,14 +60,16 @@ The tesselation result for the given `VoronoiSite`s contains `VoronoiEdge`s and
4460* ` VoronoiSite.ClockwiseEdges ` (on-demand) contains these edges sorted clockwise (starting from the bottom-right "corner" end point).
4561* ` VoronoiSite.ClockwiseEdgesWound ` (on-demand) contains these edges also "wound" in the clockwise order so their start/end points form a loop.
4662* ` VoronoiSite.Neighbours ` contains the site's neighbours (in the Delaunay Triangulation), that is, other sites across its edges.
47- * ` VoronoiSite.Points ` (on-demand) contains points of the site's cell, that is, edge end points / edge nodes.
63+ * ` VoronoiSite.Points ` (on-demand) contains points/vertices of the site's cell, that is, edge end points / edge nodes.
4864* ` VoronoiSite.ClockwisePoints ` (on-demand) contains these points sorted clockwise (starting from the bottom-right "corner").
4965* ` VoronoiPoint.Edges ` are edges emerging from this point.
5066* ` VoronoiPoint.Sites ` (on-demand) are sites touching this point.
5167
5268![ voronoi terms - site] ( https://user-images.githubusercontent.com/3857299/213494492-18b23ddb-9ca2-41f7-a4ef-73dc28c54e17.png )
5369![ voronoi terms - edge] ( https://user-images.githubusercontent.com/3857299/213494501-3a5510dd-072d-422b-bb28-18016857ac53.png )
5470
71+ ### Border closing
72+
5573If closing borders around the boundary is not desired (leaving sites with unclosed edges/polygons):
5674
5775```
@@ -63,19 +81,14 @@ List<VoronoiEdge> edges = VoronoiPlane.TessellateOnce(
6381);
6482```
6583
66- Full syntax (leaving a reusable ` VoronoiPlane ` instance) :
84+ Closed versus unclosed :
6785
68- ```
69- VoronoiPlane plane = new VoronoiPlane(0, 0, 600, 600);
70-
71- plane.SetSites(sites);
72-
73- List<VoronoiEdge> edges = plane.Tessellate();
74- ```
86+ <img width =" 484 " height =" 343 " alt =" closed borders " src =" https://github.com/user-attachments/assets/b9d59c77-18f8-4478-9809-9646d59af5be " />
87+ <img width =" 484 " height =" 343 " alt =" unclosed borders " src =" https://github.com/user-attachments/assets/c2e28f2a-4cf4-4132-bc0f-b5003ddcb27d " />
7588
76- (Note that the algorithm will ignore duplicate sites, so check ` VoronoiSite.Tesselated ` for skipped sites if duplicates are possible in your data.)
89+ ### Site generation
7790
78- Sites can be quickly randomly-generated (this will guarantee no duplicates):
91+ Sites can be quickly randomly-generated (this will guarantee no duplicates and no sites on edges ):
7992
8093```
8194VoronoiPlane plane = new VoronoiPlane(0, 0, 600, 600);
@@ -85,7 +98,14 @@ plane.GenerateRandomSites(1000, PointGenerationMethod.Uniform); // also supports
8598plane.Tessellate();
8699```
87100
88- Lloyds relaxation algorithm can be applied to "smooth" cells:
101+ Uniform and Gaussian:
102+
103+ <img width =" 475 " height =" 328 " alt =" random uniform " src =" https://github.com/user-attachments/assets/cae69f77-c5cb-4005-ae40-e68f8bcfa868 " />
104+ <img width =" 475 " height =" 328 " alt =" random gaussian " src =" https://github.com/user-attachments/assets/b1a1fea1-d804-4ea5-afd1-adb719894e1a " />
105+
106+ ### Site relaxation
107+
108+ Lloyds relaxation algorithm can be applied to "smooth" cells by spacing them out over several tessalation passes:
89109
90110```
91111VoronoiPlane plane = new VoronoiPlane(0, 0, 600, 600);
@@ -98,11 +118,22 @@ List<VoronoiEdge> edges = plane.Relax();
98118// List<VoronoiEdge> edges = plane.Relax(3, 0.7f); // relax 3 times with 70% strength each time
99119```
100120
121+ <img width =" 475 " height =" 328 " alt =" no relaxing " src =" https://github.com/user-attachments/assets/5294cbb2-2a07-4d3a-98c2-0bfe399013a9 " /> → <img width =" 475 " height =" 328 " alt =" twice relaxing " src =" https://github.com/user-attachments/assets/2ba08672-1c28-4217-b745-2cddf7fc700d " />
122+
123+ ### Delaunay triangulation
124+
125+ A Voronoi diagram has a corresponding Delaunay triangulation, i.e. site neighbour links:
126+
127+ <img width =" 475 " height =" 328 " alt =" site neighbours subtle " src =" https://github.com/user-attachments/assets/d4e81817-8650-4761-bacd-63ac83652365 " />
128+ <img width =" 475 " height =" 328 " alt =" site neighbours distinct " src =" https://github.com/user-attachments/assets/c6793e3b-2102-43a3-88b4-0e8e9921ca3e " />
129+
130+ While these normally form triangles, be aware that four or more points in a circle will make this mathematically ambiguous; sites will have neighbours across a vertex crossing other neighbour links. This is extremely rare with random points, but must be checked if using the results for something like a triangle mesh. The library does not currently provide a direct way to gather a list of these triangles.
131+
101132# MonoGame example
102133
103- A very simple [ MonoGame] ( https://github.com/MonoGame/MonoGame ) example is included in ` MonoGameExample ` project:
134+ A simple interactive [ MonoGame] ( https://github.com/MonoGame/MonoGame ) example is included in ` MonoGameExample ` project:
104135
105- ![ SVL MG ] ( https://github.com/user-attachments/assets/28dfb592-f6b1-4044-96a9-e32110c237a0 )
136+ < img width = " 994 " height = " 498 " alt = " monogame demo enhanced " src = " https://github.com/user-attachments/assets/40be8056-a54f-44c9-85f9-3b1c5f00a03d " />
106137
107138# Dependencies
108139
@@ -116,9 +147,6 @@ The key differences from the [original VoronoiLib repo](https://github.com/Zalgo
116147* Multiple critical and annoyingly-rare bugs and edge cases fixes
117148* LOTS more unit testing
118149
119- Known issues:
120- * The algorithm uses a lot of allocations, forcing garbage collection
121-
122150# Credits
123151
124152- [ Originally written by Logan Lembke as VoronoiLib] ( https://github.com/Zalgo2462/VoronoiLib )
0 commit comments