I have a polygon P given as a set of points, and I need to compute the radius of the largest inscribed circle.
To do that, I am following the answer given by the user "Plow" here: https://stackoverflow.com/a/4284218/15297702
- Construct the Voronoi Diagram of the edges in P.
- For Voronoi nodes (points equidistant to three or more edges) inside P:
- Find the node with the maximum distance to edges in P. This node is the centre of the maximum inscribed circle
I am trying to do that in CGAL, but I am not able to find the Voronoi nodes.
The following code simply takes as polygon the square [0,1]x[0,1] and it is adapted from the CGAL documentation here: https://doc.cgal.org/latest/Segment_Delaunay_graph_2/index.html#title15. When I print the vertices defining the Voronoi edge, I keep seeing the vertices of the pentagon, so I guess I am not getting the Voronoi nodes that I need to compute those distances. What am I doing wrong?
#include <CGAL/Simple_cartesian.h>
#include <cassert>
#include <fstream>
#include <iostream>
typedef CGAL::Simple_cartesian<double> K;
#include <CGAL/Segment_Delaunay_graph_2.h>
#include <CGAL/Segment_Delaunay_graph_filtered_traits_2.h>
typedef CGAL::Segment_Delaunay_graph_filtered_traits_without_intersections_2<K>
Gt;
typedef CGAL::Segment_Delaunay_graph_2<Gt> SDG2;
int main() {
std::vector<std::pair<Gt::Point_2, Gt::Point_2>> segments;
std::pair<Gt::Point_2, Gt::Point_2> segm0({0, 0}, {1, 0});
std::pair<Gt::Point_2, Gt::Point_2> segm1({1, 0}, {1, 1});
std::pair<Gt::Point_2, Gt::Point_2> segm2({1, 1}, {0, 1});
std::pair<Gt::Point_2, Gt::Point_2> segm3({1, 1}, {0, 0});
segments.push_back(segm0);
segments.push_back(segm1);
segments.push_back(segm2);
segments.push_back(segm3);
SDG2 sdg;
std::size_t n_segments =
sdg.insert_segments(segments.begin(), segments.end());
assert(sdg.is_valid(true, 1));
std::cout << std::endl;
std::string inf_vertex("infinite vertex");
char vid[] = {'A', 'B', 'C', 'D'};
SDG2::Finite_edges_iterator eit = sdg.finite_edges_begin();
for (int k = 1; eit != sdg.finite_edges_end(); ++eit, ++k) {
SDG2::Edge e = *eit;
// get the vertices defining the Voronoi edge
SDG2::Vertex_handle v[] = {
e.first->vertex(sdg.ccw(e.second)), e.first->vertex(sdg.cw(e.second)),
e.first->vertex(e.second), sdg.tds().mirror_vertex(e.first, e.second)};
std::cout << "--- Edge " << k << " ---" << std::endl;
for (int i = 0; i < 4; i++) {
// check if the vertex is the vertex at infinity; if yes, print
// the corresponding string, otherwise print the site
if (sdg.is_infinite(v[i])) {
std::cout << vid[i] << ": " << inf_vertex << std::endl;
} else {
std::cout << vid[i] << ": " << v[i]->site() << std::endl;
}
}
std::cout << std::endl;
}
return 0;
}