我想尝试一下(2D)德劳内三角剖分,并寻找一个相对较小的库来使用。我知道CGAL,但我想知道是否有其他比较简单和直接的选择。
我想要做的事情:
- 创建任意点集的三角剖分
- 找到任意点所在的三角形并获取其顶点
- 创建三角剖分的图像(可选)
有什么建议吗?
我想尝试一下(2D)德劳内三角剖分,并寻找一个相对较小的库来使用。我知道CGAL,但我想知道是否有其他比较简单和直接的选择。
我想要做的事情:
有什么建议吗?
你可能需要更详细地说明你的目标,以便提供更相关的答案,但让我先提一下Triangle,这是一个用C语言编写的二维Delaunay生成工具,既可以作为独立程序使用,也可以从你自己的代码中调用。
接下来关于CGAL,以下是一个典型的小例子,如果你仍然考虑使用它:
#include <vector>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K> Delaunay;
typedef K::Point_2 Point;
void load_points(std::vector< Point >& points)
{
points.push_back(Point(1., 1.));
points.push_back(Point(2., 1.));
points.push_back(Point(2., 2.));
points.push_back(Point(1., 2.));
}
int main()
{
std::vector< Point > points;
load_points(points);
Delaunay dt;
dt.insert(points.begin(), points.end());
std::cout << dt.number_of_vertices() << std::endl;
return 0;
}
另外还有一个名为poly2tri的工具,看起来很不错:https://github.com/greenm01/poly2tri
我曾经使用Gnu Triangulated Surface library进行2D Delaunay三角剖分,效果很不错。虽然它使用了OOP-in-C GLib风格,但它可以很容易地被包装起来。