CGAL:找到一个点所属的面/三角形?

fml*_*fml 5 c++ delaunay triangulation cgal computational-geometry

阅读完相关内容后,我想到了这一点:

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

  typedef std::vector<Delaunay::Face_handle> Faces;
  Faces faces;
  std::back_insert_iterator<Faces> result( faces );
  result = dt.get_conflicts ( Delaunay::Point(1.5, 1.5),
                                std::back_inserter(faces) );

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

这应该找到外接圆包含该点的面。之后,我必须采用这些三角形并使用一种方法来测试该点是否在它们内部(CGAL 会这样做吗?我知道这很容易实现)。

不管怎样,我怎样才能把三角形从脸上去掉呢?

答案是

CGAL::Triangle_2<K> f = dt.triangle(faces[0]);
std::cout << dt.triangle(faces[0]) << std::endl;
std::cout << dt.triangle(faces[1]) << std::endl;
Run Code Online (Sandbox Code Playgroud)

ETC

我不知道如何很好地使用 Triangle 类,但它至少是一个开始。

我本来想做出一个实际的答案,但 stackoverflow 不允许我这么做。

slo*_*iot 4

您应该使用locate 成员函数,可以在此处找到文档。