Reputation: 13
I m a bit confused about how the the CGAL::do_intersect
works.
I thought the function returns true
if there is a point in both polygons. As far as I m not mistaken in
lies within out
and I should see true
printed out or what am I missing?
#include <CGAL/Point_2.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2 Point_2;
typedef CGAL::Polygon_2<Kernel> Polygon_2;
int main(int argc, char **argv)
{
Polygon_2 in, out;
in.push_back(Point_2(1,1));
in.push_back(Point_2(1,2));
in.push_back(Point_2(2,2));
in.push_back(Point_2(2,1));
out.push_back(Point_2(0,0));
out.push_back(Point_2(3,0));
out.push_back(Point_2(3,3));
out.push_back(Point_2(0,3));
std::cout << "IN intersect with OUT is " << (CGAL::do_intersect(in, out) ? "true":"false") << std::endl;
std::cout << "OUT intersect with IN is " << (CGAL::do_intersect(out, in) ? "true":"false") << std::endl;
std::cout.flush();
}
Upvotes: 1
Views: 151
Reputation: 16324
The vertices in the polygon need to be counter-clockwise. The following code produces the desired output:
IN intersect with OUT is true
OUT intersect with IN is true
#include <CGAL/Point_2.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Boolean_set_operations_2.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2 Point_2;
typedef CGAL::Polygon_2<Kernel> Polygon_2;
int main(int argc, char **argv)
{
Polygon_2 in, out;
in.push_back(Point_2(1,1));
in.push_back(Point_2(2,1));
in.push_back(Point_2(2,2));
in.push_back(Point_2(1,2));
out.push_back(Point_2(0,0));
out.push_back(Point_2(3,0));
out.push_back(Point_2(3,3));
out.push_back(Point_2(0,3));
std::cout << "IN intersect with OUT is " << (CGAL::do_intersect(in, out) ? "true":"false") << std::endl;
std::cout << "OUT intersect with IN is " << (CGAL::do_intersect(out, in) ? "true":"false") << std::endl;
std::cout.flush();
}
Upvotes: 1