轻量级 Delaunay 三角函数库(用于 c++)

2022-01-14 00:00:00 geometry c++ triangulation cgal

我想玩一些(2D)Delaunay 三角剖分,并且正在寻找一个相当小的库来使用.我知道 CGAL,但我想知道那里是否有一些相当简单明了的东西.

I'd like to play around with some (2D) Delaunay triangulations, and am looking for a reasonably small library to work with. I'm aware of CGAL, but I was wondering if there was something fairly simple and straightforward out there.

我想做的事:

  • 创建任意一组点的三角剖分
  • 找到任意点所在的三角形,并获取顶点
  • 创建三角测量图像(可选)

建议?

推荐答案

你可能应该详细说明你的目标,以便提供更相关的答案,但我先提一下 Triangle,2D Delaunay 生成工具,用 C 语言编写,既可以作为独立程序使用,也可以调用来自您自己的代码.

You should probably detail your goals a bit, so that more relevant answers can be provided, but let me first mention Triangle, a 2D Delaunay generation tool, which is written in C, and can be used both as a standalone program, or called from your own code.

那么,关于CGAL,这里是一个典型的小例子,以防你还在考虑:

Then, about CGAL, here is a typical small example, in case you still consider it:

#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;
}

相关文章