i have created convex hull 3d points using cgal library. want check whether point inside hull or not. couldn't find options so. can help?
my code 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 " << <<" contains " << poly[i].size_of_vertices() << " vertices" << std::endl; } its workng , can access poly see no of vertices present in it. not able find , function check whether point inside of or not.
this adaptation of 2d approach might doable...
can define 2d planes form surface of convex hull? if so, construct infinite line between point in question , through other point further enough away guaranteed outside hull. then, each plane on surface of hull, determine if line crosses plane.
edit. (thanks comment brunolevy)
general arbitrary closed 3-d hull, if crosses odd number of planes, point inside hull, if it's number outside.
in case simpler. convex hull, must cross either zero, 1 or 2 such planes. if crosses 1 inside, otherwise out.
Comments
Post a Comment