(中广)获取AABB树生成的边界立方体进行碰撞检测

(CGAL) Obtain the bounding cube generated by AABB tree to make collision detection

本文关键字:边界 立方体 碰撞检测 中广 获取 AABB      更新时间:2023-10-16

我想知道两个多面体是否相交,为此我用 CGAL::AABB_tree 制作了它们两个的 AABB 树,它生成边界立方体,用这个 AABB 树我想检查与以下方面的交集:

CGAL::box_intersection_d (RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2

begin2, RandomAccessIterator2 end2, Callback callback, ...)

但是我不知道如何从树上获取 RandomAccessIterator1 begin1、RandomAccessIterator1 end1、RandomAccessIterator2

begin2、RandomAccessIterator2 end2,谁能帮我?

#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/IO/Polyhedron_iostream.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <CGAL/AABB_tree.h>
#include <CGAL/AABB_traits.h>
#include <CGAL/AABB_face_graph_triangle_primitive.h>
#include <CGAL/box_intersection_d.h>
#include <CGAL/Bbox_2.h>    
typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_3 Point;
typedef CGAL::Polyhedron_3<K> Polyhedron;
typedef CGAL::AABB_face_graph_triangle_primitive<Polyhedron> Primitive;
typedef CGAL::AABB_traits<K, Primitive> Traits;
typedef CGAL::AABB_tree<Traits> Tree;
typedef Tree::Primitive_id Primitive_id;
typedef CGAL::Box_intersection_d::Box_d<double,2> Box;
typedef CGAL::Bbox_3                              Bbox;

int main(int argc, char* argv[]) {
Point p(1.0, 0.0, 0.0);
Point q(0.0, 1.0, 0.0);
Point r(0.0, 0.0, 1.0);
Point s(0.0, 0.0, 0.0);
Polyhedron polyhedron;
polyhedron.make_tetrahedron(p, q, r, s);
Polyhedron P;
std::ifstream in1((argc>1)? 
argv[1]:"/home/domus/Programming_Projects/Cpp_projects/cube_1.off");
in1 >> P;
Tree P_tree(faces(P).first, faces(P).second, P);
std::cout << P_tree.size() << std::endl;
Tree tree(faces(polyhedron).first, faces(polyhedron).second, polyhedron);
std::cout << tree.size() << std::endl;
return 0;
}
您可以使用

以下 CGAL::P olygon_mesh_processing::d o_intersect() 函数。

如果您可以使用 CGAL 的主分支,您甚至可以使用新引入的函数进行碰撞检测:请参阅当前文档页面。