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 18:31:46 +0300
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-phdr: 9a23:UfG3kBPMfuYF4A3XX2ol6mtUPXoX/o7sNwtQ0KIMzox0I/7/rarrMEGX3/hxlliBBdydt6sZzbeJ+PCxEUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQpFiCe9bL9oLBi7rwrdu8oSjIB/Nqs/1xzFr2dSde9L321oP1WTnxj95se04pFu9jlbtuwi+cBdT6j0Zrw0QrNEAjsoNWA1/9DrugLYTQST/HscU34ZnQRODgPY8Rz1RJbxsi/9tupgxCmXOND9QL4oVTi+6apgVRnlgzoFOTEk6mHaksN/jKxZrxyhqRJxwJPabp+JO/dlZKzRYckXSHBdUspNVSFMBJ63YYsVD+oGOOZVt4bzp1UPrRCjBQesA+zvxSFMhnTr2qA1zeohEQDI3AwnENIBrnDUoc76NKcXS++1za3IwS/fYPNR3Dfw8Y7FeQ0vr/GLWLJ/a8vRyU83GgPDlFqfspfqPzeL2egXr2eb6O9gWfqui24hsQFxoyKgyt0iionTgI8e11PK9T1hzYorOdG1TFR3bN2kHZdKqi2XNop7Ttk/T2xqpio3zKANt4ShcygQ0psnwgbSa/yZfIiM5RLuTOORLi15hHJhYb6/hhKy/VW5xu3yS8W50khGojBKktnLsXAN2BjT5dadRvRh+Ueh3C6D1wHV6u5aPUA5jbTXJ4Ilz7IqlZcesV7PEjL3lUj3lqOaa0cp9vaw5+TieLrmp5ucN4FuigH5N6QjgtKwAeo5MggAWGib9vqz1Ln48E32RbVFlPw2kq3DvJ/GIsQbo7a1AxVJ3YY79xa/EzCm3cwEknkINl1FfAuLgJXoO1HVPP/4EOy/g0+3nTdwx/HGO6XhDY/XInjClrfhZ7d95FRGxAo919AMr69SEawLdfLvRlfq5pufFQ48KwXywuD9Cdw72JlZQnOKGqbeMaXcthiD6esrZuWNf4QIoy2uFv4++vTOkXo9zF8BYbGyj9xQc2G9Bv0gIkODYHOqjM1GCnYPpgN5TerkjxqJXjdXInqzRKkh/SpoNYS9EI3/S5Cx1bydwD+gTNoRfXFDElnKEHHydozCVe1LczOXOsYmkzoKUv+qRIYlkB2vrwTn0KE0Eu2B8SIRsdfv1cN++vbIvRA07z19ScqHgE+XSGQhs20JDxEx06176RhwxFaN1qd1h9RXENVS47VCVQJsZs2U9PBzF92nAlGJRdyOUlvzGoz3UwF0dco4xpo1W2g4Htyjih7Z2C/zWu0akrWKANo/9aeOhiGsdfY48G7P0ewat3djQsZLMjf41Kt29gyWBoqQ1kvAyPzseqMb0yrAsmyEyDjW5R0KYEtLSazAGEsnSA7Ot92gvxHNSravDfIsNQ4TkcM=

Yes it does.
You compute the difference 3 times.
The first 2 times you get some difference and the 3 time you cut the entire reminder out, so you get nothing.
   ____  _        ____             _
  /_____/_) o    /__________  __  //
 (____ (   (    (    (_/ (_/-(-'_(/
                         _/




On Sun, 26 Apr 2020 at 18:25, 落 域 <> wrote:
The data of the tested hole should be able to cut the source polygon well, but the difference function does not return a cut polygon.

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




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