1
두 볼록 다각형의 정점이 주어지면 cgal을 사용하여 교차 영역을 계산하는 가장 간단한 방법은 무엇입니까?두 개의 폴리곤과 cgal이있는 교차 영역 계산
두 볼록 다각형의 정점이 주어지면 cgal을 사용하여 교차 영역을 계산하는 가장 간단한 방법은 무엇입니까?두 개의 폴리곤과 cgal이있는 교차 영역 계산
볼록한 다각형으로 작업하기 때문에 구멍을 걱정할 필요가 없습니다. 따라서 생각할 수있는 가장 간단한 코드는 기본적으로 다각형을 구성하고, 교차로를 호출하고, 교차점을 순환하고 전체 면적을 합산하는 것입니다.
#include <iostream>
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Boolean_set_operations_2.h>
#include <CGAL/Polygon_2_algorithms.h>
typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_2 Point;
typedef CGAL::Polygon_2<K> Polygon_2;
typedef CGAL::Polygon_with_holes_2<K> Polygon_with_holes_2;
using std::cout; using std::endl;
int main(){
Point points[] = { Point(0,0), Point(1,0), Point(1,1), Point(0,1)};
Point points2[] = { Point(0.5,0.5), Point(1.5,0.5), Point(1.5,1.5), Point(0.5,1.5)};
Polygon_2 poly1(points, points+4);
Polygon_2 poly2(points2, points2+4);
//CGAL::General_polygon_with_holes_2<K> poly3;
std::list<Polygon_with_holes_2> polyI;
CGAL::intersection(poly1, poly2, std::back_inserter(polyI));
double totalArea = 0;
typedef std::list<Polygon_with_holes_2>::iterator LIT;
for(LIT lit = polyI.begin(); lit!=polyI.end(); lit++){
totalArea+=lit->outer_boundary().area();
}
cout << "TotalArea::" << totalArea;
}