近似共面3d点的三角测量/多边形化
我有一个3d中的点列表(由std::vector表示)和一个给定的平面p,这样:近似共面3d点的三角测量/多边形化,3d,geometry,polygon,cgal,triangulation,3d,Geometry,Polygon,Cgal,Triangulation,我有一个3d中的点列表(由std::vector表示)和一个给定的平面p,这样: 每个点与P之间的距离小于阈值 点列表中没有重复项 点在平面上的投影是一个二维多边形,可以是复杂退化的和无孔的 我想要这些点的三角剖分(或者,如果可能的话,多边形化),这样平面上的三角剖分投影对应于平面上点投影的二维三角剖分。换句话说,我需要操作之间的交换性:“三角化”和“平面投影” 因此,凸包并不令人满意 CGAL可以这样做吗?下面的代码应该是您想要的。您需要知道平面的正交向量(可以使用包自动获取) #包括 #包括
CGAL可以这样做吗?下面的代码应该是您想要的。您需要知道平面的正交向量(可以使用包自动获取)
#包括
#包括
#包括
#包括
typedef CGAL::精确谓词不精确结构内核K;
typedef CGAL::三角测量_2 _投影_特征_3cdt特征;
typedef CGAL::约束的Delaunay三角剖分CDT;
typedef-std::对约束;
int main()
{
向量3平面正交向量(1,1,0);
CDT_性状(平面正交向量);
CDT-CDT(性状);
向量顶点;
顶点。向后推(cdt.insert(K::Point_3(0,0,0));
顶点向后推(cdt.insert(K::Point_3(1,1,0));
顶点向后推(cdt.insert(K::Point_3(1,1,1));
顶点向后推(cdt.insert(K::Point_3(0,0,1));
插入_约束(顶点[0],顶点[1]);
插入_约束(顶点[1],顶点[2]);
插入_约束(顶点[2],顶点[3]);
插入_约束(顶点[3],顶点[0]);
}
使用CGAL 4.9,对于较大的多边形,以下代码将更快(它正在使用4.8,但需要以下代码):
#包括
#包括
#包括
#包括
typedef CGAL::精确谓词不精确结构内核K;
typedef CGAL::三角测量_2 _投影_特征_3cdt特征;
typedef CGAL::约束的Delaunay三角剖分CDT;
typedef std::pair Index_pair;
int main()
{
向量3平面正交向量(1,1,0);
CDT_性状(平面正交向量);
CDT-CDT(性状);
std::向量点;
点。向后推(K::点3(0,0,0));
点。向后推(K::点3(1,1,0));
点。向后推(K::点3(1,1,1));
点。向后推(K::点3(0,0,1));
向量约束指数;
约束索引。向后推(索引对(0,1));
约束索引。向后推(索引对(1,2));
约束索引。向后推(索引对(2,3));
约束索引。向后推(索引对(3,0));
cdt.insert_约束(points.begin()、points.end(),
约束索引.begin(),约束索引.end();
}
谢谢!但是还有一个任务要完成:我的多边形在2D平面上的投影可能不是凸的。如果我理解正确,CGAL三角剖分的外多边形是凸包。所以在三角剖分之后,我必须移除所有位于多边形“外部”的三角形。。。我看不出这有什么帮助。解决这个问题的一种方法可能是遍历多边形的顶点,然后对于每个凹形顶点,依次删除“在”多边形外部的所有三角形。此示例显示了如何标记多边形域内的所有三角形。
#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]);
}
#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() );
}