0

I have created a convex hull with some 3D points using the CGAL library. Now I want to check whether a point is inside the hull or not. But couldn't find any options to do so. Can anyone help?

My code is bellow.

    #include <CGAL/Simple_cartesian.h>
    #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
    #include <CGAL/point_generators_3.h>
    #include <CGAL/algorithm.h>
    #include <CGAL/Polyhedron_3.h>
    #include <CGAL/convex_hull_3.h>
    #include <vector>
    typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
    typedef CGAL::Polyhedron_3<K> Polyhedron;
    typedef K::Point_3 Point;
    std::vector<Point> hullPoints[16];
    int numPoints[16];
    Polyhedron poly[16];
    //Reading hull points
    for(int i=0;i<a->vertI;i++)
    {
        for(int j=0;j<16;j++)
        {
            if(a->vertices[i][1] <= (a->maxY-(j*(a->maxY-a->minY)/16.0)) && a->vertices[i][1] >= (a->maxY-((j+1)*(a->maxY-a->minY)/16.0)) )
            {
                hullPoints[j].push_back(Point(a->vertices[i][0],a->vertices[i][1],a->vertices[i][2]));
            }


        }


    }
//Create hull
    for(int i=0;i<16;i++)
    {
        CGAL::convex_hull_3(hullPoints[i].begin(), hullPoints[i].end(), poly[i]);
        std::cout << "The convex hull " << i <<" contains " << poly[i].size_of_vertices() << " vertices" << std::endl;

    }

Its workng perfectly and I can access the Poly to see no of vertices present in it. But not able to find and function to check whether a point is inside of it or not.

sabby
  • 99
  • 7

1 Answers1

0

This is an adaptation of a 2D approach but it might be doable...

Can you define the 2D planes that form the surface of the convex hull? If so, then construct an infinite line between the point in question and through any other point further enough away to be guaranteed to be outside the hull. Then, for each plane on the surface of the hull, determine if the line crosses that plane.

EDIT. (thanks to comment from BrunoLevy)
For a general arbitrary closed 3-D hull, if it crosses an odd number of the planes, the point is inside the hull, if it's an even number it is outside.

In your case it is simpler. For a convex hull, it must cross either zero, one or two such planes. If it crosses only one it is inside, otherwise it is out.

Charles Bretana
  • 143,358
  • 22
  • 150
  • 216
  • what you say is correct, but it is for an arbitrary polyhedron. For the convex hull (that is *convex*), it is simpler: there is one intersection if the point is inside, and 0 or two if it is outside. More simply, one can compute orient3d(q, p1, p2, p3) for each facet (p1,p2,p3) of the convex hull and q the query point, if all the signs are the same, then the point is inside the convex hull. – BrunoLevy Jul 23 '15 at 09:28
  • Ahhh, yes, sorry, I missed that. I will edit the answer to address the distinction. – Charles Bretana Jul 23 '15 at 11:56