qhull 求取数据凸包络 C++ 代码
时间: 2023-12-05 09:04:38 浏览: 68
以下是使用qhull库求取数据凸包络的C++代码示例:
```c++
#include <iostream>
#include <vector>
#include "libqhullcpp/Qhull.h"
using namespace std;
using namespace orgQhull;
int main()
{
// 构造数据点
vector<Point3> points;
points.push_back(Point3(0, 0, 0));
points.push_back(Point3(1, 0, 0));
points.push_back(Point3(1, 1, 0));
points.push_back(Point3(0, 1, 0));
points.push_back(Point3(0.5, 0.5, 1));
// 构造Qhull对象
Qhull qhull;
qhull.runQhull("", 3, points.data(), points.size(), "i Qt");
// 获取凸包顶点
vector<Point3> vertices;
for (QhullVertexSet::iterator it = qhull.vertexSet().begin(); it != qhull.vertexSet().end(); ++it)
{
vertices.push_back((*it).point());
}
// 输出结果
cout << "凸包顶点:" << endl;
for (vector<Point3>::iterator it = vertices.begin(); it != vertices.end(); ++it)
{
cout << (*it) << endl;
}
return 0;
}
```
这里同样使用libqhullcpp库来进行qhull计算,首先构造数据点,然后构造Qhull对象并运行qhull计算,最后从计算结果中提取凸包顶点并输出。
阅读全文