[PPL-devel] newbie question - point containment within polyhedron

Enea Zaffanella zaffanella at cs.unipr.it
Sun Jan 28 19:19:45 CET 2007


Manoj Rajagopalan wrote:
> Hi all
> 
>    How do I check if a point is contained within a polyhedron? Firstly, 
> how do i represent the point? in terms of X, Y, Z where these are 
> declared to be of type Variable?

Hi.

// Supposing that you are working in a 3 dimensional space.

   using namespace Parma_Polyhedra_Library;

   Variable x(0);
   Variable y(1);
   Variable z(2);

// Now, create your polyhedron:

   C_Polyhedron ph(3, UNIVERSE);
   ph.add_constraint(x + 3*y >= z)
   ph.add_constraint(x >= 0)
   ph.add_constraint(2*y +2*z <= 5)

// Then, create a point, which is a Generator,
// e.g., having coordinates (1, 1, 1).

   Generator g = point(x + y + z);

// Finally, compute the relation between
// the polyhedron and the generator.

   Poly_Gen_Relation rel = ph.relation_with(g);

// If the point is contained in the polyhedron, then
// the polyhedron "subsumes" the point (i.e., adding
// the point to the polyhedron won't change the polyhedron).

   if (rel == Poly_Gen_Relation:subsumes())
     std::cout << "The point is contained in ph" << std::endl;

>    Would someone have any example code snippets to illustrate related 
> points?
> 
> thanks
> Manoj Rajagopalan

Have a look in ppl/tests/Polyhedron/relations1.cc, as well as the 
documentation for methods Polyhedron::relation_with(...).

Cheers,
Enea.



More information about the PPL-devel mailing list