Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 67 additions & 0 deletions user-guide/modules/ROOT/pages/faq/graphics-games.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,73 @@ Yes, general purpose Boost functionality can set well underneath Lua and AngelSc
Graph Serialization
----

. *Are there any Boost libraries that implement, or assist with, Voronoi diagrams?*
+
Yes. boost:polygon[] provides Voronoi diagram construction, graph traversal, and some supporting polygon operations, such as polygon intersection, union, difference, resizing and related operations useful for clipping or processing geometric regions.
+
The following example code constructs a Voronoi diagram from five points and reports how many cells, edges and vertices were created.
+
[source,cpp]
----

#include <boost/polygon/voronoi.hpp>
#include <iostream>


namespace bp = boost::polygon;

int main()
{
using Point = bp::point_data<int>;

// Five input sites, using integer coordinates.
std::vector<Point> points{
{0, 0},
{10, 0},
{5, 8},
{2, 5},
{8, 5}
};

// Construct the Voronoi diagram.
bp::voronoi_diagram<double> diagram;

bp::construct_voronoi(
points.begin(), points.end(), &diagram);

std::cout << "Input points: " << points.size() << '\n';
std::cout << "Voronoi cells: " << diagram.num_cells() << '\n';
std::cout << "Voronoi edges: " << diagram.num_edges() << '\n';
std::cout << "Voronoi vertices: "
<< diagram.num_vertices() << '\n';
}

----
+
Run this code and you should get:
+
[source,txt]
----
Input points: 5
Voronoi cells: 5
Voronoi edges: 12
Voronoi vertices: 2
----

Note:: boost:polygon[]'s Voronoi implementation is two-dimensional. Its default interface expects integer input coordinates, which helps the algorithm maintain robust geometric predicates. If your original coordinates are floating-point values, you may need to scale and map them onto an integer grid, considering the precision trade-offs.

. *Can I see an image of a Voronoi diagram?*
+
image::voronoi-diagram.png[Voronoi diagram]

. *How easy is it to extend a 2-D Voronoi implementation to 3-D?*
+
In 2D, Voronoi boundaries are edges, and vertices are points where three or more cells meet. In 3D, boundaries are polygonal faces, edges are where faces meet, and vertices are where multiple faces meet. The construction algorithm must handle this richer topology, including degeneracies such as five or more sites lying on a common sphere.
+
Best to start with boost:polygon[]'s 2D implementation and study the relationship between Voronoi diagrams and _Delaunay triangulations_ (a way of connecting a set of points into triangles so that no point lies inside the circumcircle of any triangle). If you need production-quality 3D geometry, investigate https://www.cgal.org/[CGAL - The Computational Geometry Algorithms Library] first and use Boost for the supporting infrastructure.



== See Also

* xref:faq.adoc[]
2 changes: 1 addition & 1 deletion user-guide/modules/ROOT/pages/library-table.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ The libraries marked as *Optional* for Header-only add some functionality if the

[#footnote1]
link:#footnote1-location[(1)]
A Voronoi diagram is a geometric structure that partitions a space into regions based on the proximity of a set of defined points, called _sites_ or _generators_. Each region contains all locations that are closer to its associated site than to any other site. The boundaries between regions consist of points that are equidistant from two or more sites. Voronoi diagrams have applications in computational geometry, geographic information systems (GIS), robotics, biology, and telecommunications, where they are used for tasks such as determining nearest service locations, analyzing spatial distributions, and partitioning areas for efficient resource allocation.
A Voronoi diagram is a geometric structure that partitions a space into regions based on the proximity of a set of defined points, called _sites_ or _generators_. Each region contains all locations that are closer to its associated site than to any other site. The boundaries between regions consist of points that are equidistant from two or more sites. Voronoi diagrams have applications in computational geometry, geographic information systems (GIS), robotics, biology, and telecommunications, where they are used for tasks such as determining nearest service locations, analyzing spatial distributions, and partitioning areas for efficient resource allocation. boost:polygon[] has a dedicated Voronoi diagram implementation.

[#footnote2]
link:#footnote2-location[(2)]
Expand Down
Loading