Skip to Content.
Sympa Menu

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

Subject: CGAL users discussion list

List archive

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


Chronological Thread 
  • From: Efi Fogel <>
  • To:
  • Subject: Re: [cgal-discuss] difference for 2d polygons return incorrect polygon
  • Date: Sun, 26 Apr 2020 14:26:29 +0300
  • Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-phdr: 9a23:4e/OJBwONoktbWnXCy+O+j09IxM/srCxBDY+r6Qd2ugSIJqq85mqBkHD//Il1AaPAdyGra8bwLGH+4nbGkU4qa6bt34DdJEeHzQksu4x2zIaPcieFEfgJ+TrZSFpVO5LVVti4m3peRMNQJW2aFLduGC94iAPERvjKwV1Ov71GonPhMiryuy+4ZLebxhIiTanYb5/Lhq6oAvVu8ILnYZsN6E9xwfTrHBVYepW32RoJVySnxb4+Mi9+YNo/jpTtfw86cNOSL32cKskQ7NWCjQmKH0169bwtRbfVwuP52ATXXsQnxFVHgXK9hD6XpP2sivnqupw3TSRMMPqQbwoXzmp8qFmQwLqhigaLT406G7YisJyg6xbrhyvpAFxzZDIb4yOLvVyYrnQcMkGSWZdXMtcUTFKDIOmb4sICuoMJelWr4f8p1ATrRW+AgasC/3ryjRVgXL5w6M60+UvEQHB0wwvAdYOvW/brNXwLqgSUOS1wLPUwjXEavNbwDHw45XGfBAmpPGDR7NwcczJxEkpDQzKlU6fqYj7MD+PyusNtG2b4/JhVeKpkW4nqht+riKhxsc2jITCm4Ebykjc+Cln3Io4Ice0RU17bNK+DZddtiCXO5FrTs4hXW1lvjsxxKcctp6hZicKzYwqxx7BZPyDdIiF+hfjW/yQITd8nX5leba/iwur/Uiu1+HxVde43ExFripCldnMuXQN2ALJ5sebTft9+1+t2TeJ1w/N9uFJOV44mbbfJpI7wbM9loAfvVnCEyL3gkn6kaybels89uit8evnY7HmppGGN49zjwHzKrohmsK+AeQ2NQgOUHaU+eCn2b3s+E32WrRKjvksnqbFt5DaINwXprSlDA9NzoYj9xG/Ai+639QXh3YHKEtJdw+Gj4jyJ17OPev4DeykjlS3kDZrwujGMaf7DpXMKHjDirbhcqxn505S0gpghe1Z/I9eX7EdPOroCAi2r83dFhZ/Mgquwu+hBs86zZIbQWvIA6mXN+TZvlaMo+4uOOKRf5RGhTDmNvIF+/vq2H8lhUcGL+7uxooScHn+H/J8Ikzfb2CrmcYECW5NvwwwS6vhh1SGFDJSfH2vRLlv2zcgFYiaAJffE4CxnKSajmD8BYxTfmkAC1aWEH6ueZ/DQOYJcCvVI8lvlXsPWrGlDoMgzhqzrxSp970yJeXd/mgUtInoycNuz+zVjxA7szJuXOqH1GTYYm911k0PSDIylPRyr01zzViO1YB3hvVZEZpY4PYfAVRyDoLV0+EvU4O6YQnGZNrcEA/3EOXjOik4S5cK+/FLZk98H9u4iRWahnilBrYUk/qAA5lmq/uAjUi0HN50zjP97Idkl0MvG5IdOmivh6o5/A/WVdaQzhep0p2yfKFZ5xbjsWeOyW3U4hNdWQ90FKTBBDURPxuM69v+4UzGQvmlDrF1agY=

What do you think is wrong?
   ____  _        ____             _
  /_____/_) o    /__________  __  //
 (____ (   (    (    (_/ (_/-(-'_(/
                         _/




On Sun, 26 Apr 2020 at 13:53, Luoyu <> wrote:
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/

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss





Archive powered by MHonArc 2.6.18.

Top of Page