I need to estimate the projected area of a boost::polygon of several circles that are created in a loop.
The idea is for a given x and y centroid, a polygon is created drawing a circle of a given radius using n number of vertices. This circle is stored in a ‘polygon_90_set_data’. These circles may or not overlap between them. This is repeated several times in a loop with the idea to create all the circles of interest (> 2 mill). I need to estimate the area projected by all circles similar to the enclosed figure.
However, when I try to get the projected area in my code I just get the area of a circle and not all of them. This could be a problem of dissolve or merge, but not sure how do it. Could you help me? This is my code so far.
#include <vector>
#include <boost/polygon/polygon.hpp>
#include "draw_circle_rcpp.h"
namespace bpl = boost::polygon;
typedef bpl::polygon_90_data<double> Polygon;
typedef bpl::polygon_traits<Polygon>::point_type Point;
typedef bpl::polygon_90_set_data<double> PolygonSet;
using namespace boost::polygon::operators;
double displayed_area_rcpp(arma::mat spheres, int nvertices = 10L) {
const std::size_t n_shperes = spheres.n_rows;
// Create a polygon
PolygonSet da;
for (int i = 0; i < n_shperes; i++) {
// Create a polygon
Polygon polygon;
double X = spheres(i, 0);
double Y = spheres(i, 1);
double radius = spheres(i, 2);
//Create the circle vertices
arma::mat circle_sphere = draw_circle_rcpp(X, Y, radius, nvertices);
// Create points
std::vector<Point> points;
for (int j = 0; j < nvertices; ++j) {
double xx = circle_sphere(j, 0);
double yy = circle_sphere(j, 1);
points.push_back(Point(xx, yy));
}
// Points to polygon
polygon.set(points.begin(),points.end());
assign(da, polygon);
}
return bpl::area(da);
}
I think that the potential issue is where I do the 'assign' but not sure.