gpt4 book ai didi

c++ - (CGAL) 获取AABB树生成的bounding cube做碰撞检测

转载 作者:太空宇宙 更新时间:2023-11-04 12:40:42 24 4
gpt4 key购买 nike

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

CGAL::box_intersection_d(RandomAccessIterator1 begin1,RandomAccessIterator1 end1,RandomAccessIterator2 begin2,RandomAccessIterator2 end2,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::Polygon_mesh_processing::do_intersect()功能。

如果您可以使用 CGAL 的 master 分支,您甚至可以使用新引入的碰撞检测功能:查看当前doc page .

关于c++ - (CGAL) 获取AABB树生成的bounding cube做碰撞检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54324009/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com