Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGAL: Find face/triangle a point belongs to?

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.

like image 217
fml Avatar asked Oct 11 '22 11:10

fml


1 Answers

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

like image 145
sloriot Avatar answered Oct 13 '22 10:10

sloriot