Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] difference for 2d polygons return incorrect polygon

Subject: CGAL users discussion list

List archive

[cgal-discuss] difference for 2d polygons return incorrect polygon


Chronological Thread 
  • From: Luoyu <>
  • To:
  • Subject: [cgal-discuss] difference for 2d polygons return incorrect polygon
  • Date: Sun, 26 Apr 2020 05:53:24 -0500 (CDT)
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None ; spf=SoftFail ; spf=Pass
  • Ironport-phdr: 9a23:F+9Qex3RsxeErNHesmDT+DRfVm0co7zxezQtwd8Zse0UL/ad9pjvdHbS+e9qxAeQG9mCtrQZ1KGN6OjJYi8p2d65qncMcZhBBVcuqP49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx7xKRR6JvjvGo7Vks+7y/2+94fcbglVhDexe7N/IRe5oQjfuMQdnJdvJLs2xhbVuHVDZv5YxXlvJVKdnhb84tm/8Zt++ClOuPwv6tBNX7zic6s3UbJXAjImM3so5MLwrhnMURGP5noHXWoIlBdDHhXI4wv7Xpf1tSv6q/Z91SyHNsD4Ubw4RTKv5LptRRT1iikIKiQ5/XnZhMJwkqxVow+vqBNjzIDbe4yVKPhzcr/Bcd8GWWZNQMBcXDFBDIOmaIsPCvIMM+BFr4n6p1oOsAa1CA6sBOPr1zNEmHz70bM13ukhEAzL3AwtEtIVvXTTsdX1KKMSUeeyzKnL1znMc/RW2TLk5YXObxsvr/aMXbdqfsrQz0kiDwXFgU+LpoP+OzOayP4BvHSc7+plU++klm0pqxlprzSywsohjpPFi4wWx1ze9ih0wZw5KNy5RUN9fNWqCoFftzuAOItzWs4iQ39nuCI9yrAev562czIGyJI9yBHEcPOHd5aH7gj/W+aWJDd0nHNleLShiBau6UWs1+nxW82u3FtErSdJiNrBu3EX2xHS68WLUv598V2g2TaL2QDT8OZEIUUsmKrbL54t36A8m5kNvUnMHiL7mUX7ga+We0g//eio9vjnYrHhpp+bNI94kB3xMqMrmsCnG+Q3LhAOX3SH+eS7zLDs4UL5T69OjvEvj6bZsYvaKtgGpq6iGA9YyZ0j6ha6Dze+ytsUh3gHLFRfeBKGlYflIV/OIOqrRcu41l+jmTMuy/HdNaD6Gb3MKGLCmfHvZ+VT8UlZnS4uysFCr8ZUDuhbcKivBxGs6YHwCQIlNwuzwKDsD9ArhdBWYn6GHqLMaPCailSP/O96e7DdNr9Qgy70Lr0e39CriHY4nVEHeqzwhskQdWy8GfNlZU6eZCi324pTISIxpgM7CdfSphiCXDpUPivgWf564DgxAoarS4zEQ9L02eDT7GKABpRTI1t+JBWUC36xLNeDRusIbyWRZMRml25cWA==

Hi,
I want to compute difference of the given polygons. And I found the
CGAL::difference() to do it. But in some cases, the difference return
incorrect result polygon.

Here is my test code and data.

#include <iostream>
#include "print_utils.h"

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Boolean_set_operations_2.h>
#include <list>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef Kernel::Point_2 Point_2;
typedef CGAL::Polygon_2<Kernel> Polygon_2;
typedef CGAL::Polygon_with_holes_2<Kernel>
Polygon_with_holes_2;
typedef std::list<Polygon_with_holes_2> Pwh_list_2;

Polygon_2 MakePolygon(const std::list<Point_2>& Polygon)
{
Polygon_2 resultPolygon;
for (std::list<Point_2>::const_iterator it = Polygon.cbegin(); it !=
Polygon.cend(); it++)
{
resultPolygon.push_back(*it);
}

return resultPolygon;
}



int main()
{
Polygon_2 sourcePolygon;
sourcePolygon.push_back(Point_2(-369.040009, 481.649994));
sourcePolygon.push_back(Point_2(-369.040009, -439.420013));
sourcePolygon.push_back(Point_2(220.240005, -439.420013));
sourcePolygon.push_back(Point_2(220.240005, 481.649994));

if (sourcePolygon.is_clockwise_oriented()) {
sourcePolygon.reverse_orientation();
}

std::list<Point_2> hole_1{ Point_2(220.240005, -121.932671),

Point_2(220.240005, -439.420013),

Point_2(-369.040009, -439.420013)
};

std::list<Point_2> hole_2{ Point_2(-369.040009, 481.649994),

Point_2(220.240005, 481.649994),

Point_2(220.240005, 186.445908)
};

std::list<Point_2> hole_3{ Point_2(-369.040009, 481.649994),

Point_2(-369.040009, -439.420013),

Point_2(220.240005, -439.420013),

Point_2(220.240005, 481.649994)
};

std::list<Polygon_2> allHoles;
allHoles.push_back(MakePolygon(hole_1));
allHoles.push_back(MakePolygon(hole_2));
allHoles.push_back(MakePolygon(hole_3));

for (Polygon_2 currentHole : allHoles)
{
if (currentHole.is_clockwise_oriented()) {
currentHole.reverse_orientation();
}

Pwh_list_2 difference;

CGAL::difference(sourcePolygon, currentHole,
std::back_inserter(difference));
if (difference.size() != 1) {
return -1;
}

sourcePolygon = difference.front().outer_boundary();
if (sourcePolygon.is_clockwise_oriented()) {
sourcePolygon.reverse_orientation();
}
}

print_polygon(sourcePolygon);

return 0;
}



--
Sent from: http://cgal-discuss.949826.n4.nabble.com/



Archive powered by MHonArc 2.6.18.

Top of Page