Der folgende Code sollte tun, was Sie wollen. Sie müssen den orthogonalen Vektor der Ebene kennen (Sie können das Paket PCA verwenden, um es automatisch zu erhalten).
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_2_projection_traits_3.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_2_projection_traits_3<K> CDT_traits;
typedef CGAL::Constrained_Delaunay_triangulation_2<CDT_traits> CDT;
typedef std::pair<K::Point_3, K::Point_3> Constraint;
int main()
{
K::Vector_3 plane_orthogonal_vector(1,1,0);
CDT_traits traits(plane_orthogonal_vector);
CDT cdt(traits);
std::vector<CDT::Vertex_handle> vertices;
vertices.push_back(cdt.insert(K::Point_3(0,0,0)));
vertices.push_back(cdt.insert(K::Point_3(1,1,0)));
vertices.push_back(cdt.insert(K::Point_3(1,1,1)));
vertices.push_back(cdt.insert(K::Point_3(0,0,1)));
cdt.insert_constraint(vertices[0],vertices[1]);
cdt.insert_constraint(vertices[1],vertices[2]);
cdt.insert_constraint(vertices[2],vertices[3]);
cdt.insert_constraint(vertices[3],vertices[0]);
}
Mit CGAL 4,9, wird der folgende Code schneller für größeren Polygone (Es ist mit 4.8 arbeiten, aber die folgenden patch erforderlich):
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Constrained_Delaunay_triangulation_2.h>
#include <CGAL/Triangulation_2_projection_traits_3.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_2_projection_traits_3<K> CDT_traits;
typedef CGAL::Constrained_Delaunay_triangulation_2<CDT_traits> CDT;
typedef std::pair<std::size_t, std::size_t> Index_pair;
int main()
{
K::Vector_3 plane_orthogonal_vector(1,1,0);
CDT_traits traits(plane_orthogonal_vector);
CDT cdt(traits);
std::vector<K::Point_3> points;
points.push_back(K::Point_3(0,0,0));
points.push_back(K::Point_3(1,1,0));
points.push_back(K::Point_3(1,1,1));
points.push_back(K::Point_3(0,0,1));
std::vector<Index_pair > constraint_indices;
constraint_indices.push_back(Index_pair(0,1));
constraint_indices.push_back(Index_pair(1,2));
constraint_indices.push_back(Index_pair(2,3));
constraint_indices.push_back(Index_pair(3,0));
cdt.insert_constraints(points.begin(), points.end(),
constraint_indices.begin(), constraint_indices.end());
}
Dank! Aber es gibt noch eine weitere Aufgabe: Die Projektion meines Polygons auf der 2D-Ebene ist möglicherweise nicht konvex. Wenn ich richtig verstehe, ist das äußere Polygon einer CGAL-Triangulation die konvexe Hülle. Nach der Triangulation muss ich alle Dreiecke entfernen, die "außerhalb" des Polygons stehen. – Brainless
Sieh dir das an [Beispiel] (http://doc.cgal.org/latest/Triangulation_2/index.html#title29) – sloriot
hmmm ... Ich sehe nicht, wie es mir hilft – Brainless