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

发布于 2024-11-25 10:06:03 字数 1495 浏览 3 评论 0原文

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

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

应该找到其外接圆包含该点的面。之后,我必须采用这些三角形并使用一种方法来测试该点是否在它们内部(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;

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

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

After reading about it I've come to this:

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

That should find the faces whose circumcircle contains the point. After that, I'd have to take these triangles and use a method to test if the point is inside them I think (does CGAL do this? I know it's easy to implement though).

Anyway, how can I get the triangles out of faces?

Answer is

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;

etc

I don't know how to use the Triangle class well but it's a start at least.

I was gonna make an actual answer but stackoverflow didn't allow me to so.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房的律动 2024-12-02 10:06:03

您应该使用locate成员函数,可以找到文档这里

You should use the locate member function which documentation can be found here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文