相关疑难解决方法(0)

检测立方体和圆锥体是否相互交叉?

考虑3D中的两个几何对象:

  • 与轴对齐并由其中心位置及其范围(边长)定义的立方体
  • 一个不与轴对齐并由其顶点位置定义的圆锥,其底边中心的位置,以及顶点的半角

这是一个用C++定义这些对象的小代码:

// Preprocessor
#include <iostream>
#include <cmath>
#include <array>

// 3D cube from the position of its center and the side extent
class cube
{ 
    public:
        cube(const std::array<double, 3>& pos, const double ext)
        : _position(pos), _extent(ext) 
        {;}
        double center(const unsigned int idim) 
            {return _position[idim];}
        double min(const unsigned int idim)
            {return _position[idim]-_extent/2;}
        double max(const unsigned int idim)
            {return _position[idim]+_extent/2;}
        double extent()
            {return _extent;}
        double volume()
            {return std::pow(_extent, 3);}
    protected:
        std::array<double, 3> _position;
        double _extent;
};

// 3d cone …
Run Code Online (Sandbox Code Playgroud)

c++ python math 3d collision-detection

18
推荐指数
2
解决办法
3198
查看次数

标签 统计

3d ×1

c++ ×1

collision-detection ×1

math ×1

python ×1