(中广)获取AABB树生成的边界立方体进行碰撞检测
(CGAL) Obtain the bounding cube generated by AABB tree to make collision detection
我想知道两个多面体是否相交,为此我用 CGAL::AABB_tree 制作了它们两个的 AABB 树,它生成边界立方体,用这个 AABB 树我想检查与以下方面的交集:
CGAL::box_intersection_d (RandomAccessIterator1 begin1, RandomAccessIterator1 end1, RandomAccessIterator2begin2, RandomAccessIterator2 end2, Callback callback, ...)
但是我不知道如何从树上获取 RandomAccessIterator1 begin1、RandomAccessIterator1 end1、RandomAccessIterator2begin2、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 的主分支,您甚至可以使用新引入的函数进行碰撞检测:请参阅当前文档页面。
相关文章:
- 如何使用 std::累积在 C++ 中计算总和立方体
- std::当在256字节边界上写入整数时,流的奇怪行为
- 使用不变量来确定二分搜索中的边界条件
- 跨 DLL 边界访问虚拟方法是否安全/可能?
- 在 64 位边界上对齐C++结构数组?
- 如何有效地计算将单位立方体映射到自身的反射和旋转?
- std::数组边界检查如何工作?
- CGAL:如何创建填充边界曲线的曲面网格?
- 如何使用采样器立方体作为数组
- 在 c++ 中是否允许创建具有运行时边界的数组?
- OpenGL,为什么这不是一个立方体?
- 在具有 MPI 的超立方体中广播
- 是否可以跨 dll 边界返回常量引用/指向 std::vectors?
- C++11:16 字节原子<>变量是否在 16 字节边界上自动对齐,从而允许CMPXCHG16B指令?
- Opengl 和 c++ 绘制多个立方体
- 转换引用对象的边界框?
- 将迭代器作为 3 个元素的滑动窗口,可以超调边界(可能使用 Boost)
- 算法设计:用边界数字表示 2D 网格的最佳方式,以C++?
- (中广)获取AABB树生成的边界立方体进行碰撞检测
- OpenGL -当我在立方体上绘制边界时,会出现额外的线