안녕하세요. 비슷한 문제가 발생한 사람이 있습니까?부스트가있는 포인트에서 보로 노이 셀까지의 거리 계산
보로 노이 다이어그램을 구성해도 문제가 발생하지 않았습니다. Voronoi 셀은 적어도 나를위한 다각형입니다. 또한 라이브러리는 한 지점에서 다각형까지의 거리를 찾을 수있게합니다. 그러나 라이브러리 함수는 셀을 사용하기를 원하지 않습니다. 컴파일러는 Elvish에서 무언가를 산출합니다. 농담. 즉, 컴파일러 출력은 나를 도울 수 없습니다. 셀에서 다각형을 만드는 방법이 있습니까?
voronoi 다이어그램은 vpoints에 생성됩니다. 프로그램은 qpoints 요소에서 해당 셀까지의 거리를 계산해야합니다.
이#include <iostream>
#include <vector>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/polygon/voronoi.hpp>
namespace bg = boost::geometry;
using boost::polygon::voronoi_diagram;
typedef voronoi_diagram<double>::cell_type cell_type;
typedef voronoi_diagram<double>::edge_type edge_type;
typedef voronoi_diagram<double>::vertex_type vertex_type;
typedef boost::polygon::point_data<double> point_type;
using namespace std;
int main() {
vector<point_type> vpoints;
vpoints.push_back(point_type(0.0, 0.0));
vpoints.push_back(point_type(0.0, 4.0));
vpoints.push_back(point_type(4.0, 4.0));
vpoints.push_back(point_type(4.0, 0.0));
vpoints.push_back(point_type(2.0, 2.0));
vector<point_type> qpoints;
qpoints.push_back(point_type(0.0, 0.0));
qpoints.push_back(point_type(0.0, 2.0));
qpoints.push_back(point_type(3.0, 3.0));
qpoints.push_back(point_type(5.0, 5.0));
qpoints.push_back(point_type(5.0, 5.0));
voronoi_diagram<double> vd;
construct_voronoi(vpoints.begin(), vpoints.end(), &vd);
for (int i = 0; i < qpoints.size(); i++) {
for (voronoi_diagram<double>::const_cell_iterator it = vd.cells().begin();
it != vd.cells().end(); ++it) {
if (i == it->source_index()) {
cout << "v[i]=(" << vpoints[i].x() << "," << vpoints[i].y() << ")\t";
cout << "q[i]=(" << qpoints[i].x() << "," << qpoints[i].y() << ")\t";
cout << "Distance=";
cout << bg::distance(qpoints[i], *it) << endl;
cout << endl;
break;
}
}
}
return 0;
}