需求说明:有立方体的八个顶点坐标,需要判断两个或多个立方体是否有交集。
根据百度搜索结果,CGAL可以提供立方体的布尔运算功能,但是需要根据已知的坐标构建该库的多面体对象。
以下内容参考博客 CGAL多面体布尔运算 - 码农岛
CGAL中的Polyhedron并不能直接进行多面体的布尔运算,真正实现布尔运算的结构是CGAL::Nef_polyhedron_3<Kernel>(包含用于二元布尔运算所需要的结构信息),按照CGAL的官方教程,用Polyhedron来构造Nef_Polyhedron;Nef_Polyhedron重载了+,*,-运算符,分别表示并,交,差。
布尔运算的结果仍为Nef_Polyhedron类型,调用Nef_Polyhedron的convert_to_polyhedron(Polyhedron)函数可以将Nef_Polyhedron转化回为Polyhedron。
然后通过接口函数 polyhedron2mesh将CGAL::Polyhedron_3<Kernel>转换为mesh。得到布尔运算的mesh结果:
void polyhedron2mesh(VFMesh &mesh, Polyhedron &P);
以下代码实现了根据八个顶点坐标构建多面体并进行布尔运算,将结果输出至磁盘的功能。
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Nef_polyhedron_3.h>
#incl

最低0.47元/天 解锁文章
1395





