Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] Potential polygon intersection bug

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] Potential polygon intersection bug


Chronological Thread 
  • From: Maxime Gimeno <>
  • To:
  • Subject: Re: [cgal-discuss] Potential polygon intersection bug
  • Date: Wed, 10 Jun 2020 10:15:11 +0200
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-phdr: 9a23:ier3SBMhxFfHIISVu1Il6mtUPXoX/o7sNwtQ0KIMzox0K/z/ocbcNUDSrc9gkEXOFd2Cra4d1qyP7v6rATVIyK3CmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TW94jEIBxrwKxd+KPjrFY7OlcS30P2594HObwlSizexfLN/IA+roQjRt8QajpduJrsswRbVv3VEfPhby3l1LlyJhRb84cmw/J9n8ytOvv8q6tBNX6bncakmVLJUFDspPXw7683trhnDUBCA5mAAXWUMkxpHGBbK4RfnVZrsqCT6t+592C6HPc3qSL0/RDqv47t3RBLulSwKMSMy/mPKhcxqlK9UrxyhqB5/zYDaY4+bKeRwcb/GcNwAWWZMRNxcWzBdDo6+aYYEEuoPPfxfr4n4v1YAqgGxBAatBOPq1DBDm3743aw/0+s/FwHG2xErEtULsHvOo9T1NaISXv6vwKnHzDXDau1Z2TH66IXTfRAhpOuDXbN0ccbL1UYvEAbFg0yWpIf4MDybyv4DvHKH7+p8S+2vkWgnphlxrDSyyMohiJTFip8Lxlza8Sh03Zs5KN64RkN/f9KqHppduiGeOoZrQs0sQ2Vltik1x7AFvZO2fCgExZomyhPcbfGMboaG4hXmVOmLIDd4gmpoeLSliBmp6kegzvPzWtOo31ZNqypJitjMtnYX1xzS8MeLUPV9/l2n1D2S1A7T8vlJLV4omaffMZIswb49moANvUjeAiP6gkX7gaCQe0454Oan8f7nba/jppKEN497lAX+MqM2l8y6G+s4MwwOU3Gc+eSgybHv5EP5TbVFg/EsnanZt5faJcsfpqGnGQNazoEj6xOnAzen1tQXg2UHIUpbdB6bi4XlIVLDLfDiAfuhnligjC1nyvDJM7H5B5XCNHnDkLPvfbZn7E5czRI+zdVF6JNbC7EBJez8VlX+tNzZCx82LQq0w+H8BdVy04MRQ2OPAquDPKzOtl+I4/ojI/OQa48NpDb9N/8l6ubygn82g1AdebCl0oYWaHCjAvtmPl6ZYWH3j9caEWYKuxI+Q/bwhF2DVz5TfXeyULgm6jE1EoL1RbrFXZ2n1bydwD+gTNoRfXFDElnKEHHydozCVe1LczOXOsYmkzoKUv+qRIYlkB2vrwTn0KE0E+zP5yc4qZfngdhp+/XIx1Z17i1xF83b0meXTmgykHlPXC4zxKk4oEpzzRCI3qF8xvBZDtdO/OgabwEhKJTgwvxmXtDuRhraLJDOU0ejWtzgADcrT9t3zcVJeFd4A9zljxbN2G2hDLYR0rCKH5cp6bmP43+kLMl0zzPK1bIqkkI9aspJL2yvwKBlpCbJAIuctkyJlqOnPYsd2SPL8y/XyGOevURVFgFxVKjDWlgQY0LXqZLy4UaUHOzmMqguLgYUkZ3KEaBNcNC81QwXFsemA8zXZieKo0n1AB+Jwr2Wa4+zIjcS2SzcDA4PlAVBpC/aZzh7PT+opiflNBIrDUjmOhq+/ux3qXf9RUgxnVnTMh9RkoGt8xtQvsSyDvMe2rVe5XUkojRwWVGhhpfYVobGqA1mc6FRJ9g65QUf2A==

Hi,

Your problem lies in the orientation of your polygons. One is clockwise and the other is not, when they should both be. If you compile tour code in Debug mode, you should get an assertion about that. 
If you reverse the orientation of P, you'll get the right result.

Le mer. 10 juin 2020 à 04:33, Nicolau Andres Thio <> a écrit :
Hello,

I am new to CGAL and have been trying to add polygon intersection to my
code. I have been baffled as to why my code is giving me the results it is;
after doing some extensive search online I have found no mention of a bug
but I am not sure what else it could be (barring a simple mistake I am just
not seeing). I have come up with a very simple example to check the polygon
intersection code is doing what I think it should. Here is my code:

#include <CGAL/Cartesian.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/General_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       Rat_Kernel;
typedef Rat_Kernel::Point_2                                             Rat_Point;
typedef Rat_Kernel::Segment_2                                           Rat_Segment;
typedef CGAL::Polygon_2<Rat_Kernel>                                     Rat_Polygon;
typedef CGAL::Polygon_with_holes_2<Rat_Kernel>                          Rat_Polygon_Holes;

int main(int argc, char** argv){


    Rat_Polygon p, q, result;
    std::list<Rat_Polygon_Holes> polyIterator;

    p.push_back(Rat_Point(1, 1));
    p.push_back(Rat_Point(1, 0));
    p.push_back(Rat_Point(0, 0));
    p.push_back(Rat_Point(0, 1));
    q.push_back(Rat_Point(-1, 0.5));
    q.push_back(Rat_Point(2, 0.5));
    q.push_back(Rat_Point(0, 2));

    CGAL::intersection(q, p, std::back_inserter(polyIterator));
    result = polyIterator.begin()->outer_boundary();
    printf("Intersection polygon vertices: ");
        for (auto vi = result.vertices_begin(); vi != result.vertices_end(); ++vi){
                printf("(%.2f,%.2f) ", CGAL::to_double((*vi).x()),
CGAL::to_double((*vi).y()));
    }
    printf("\nIntersection polygon edges ");
        for (auto ei = result.edges_begin(); ei != result.edges_end(); ++ei){
                        printf("(%.2f,%.2f) - (%.2f,%.2f) :: ",
                                CGAL::to_double((*ei).source().x()),
                                CGAL::to_double((*ei).source().y()),
                                CGAL::to_double((*ei).target().x()),
                                CGAL::to_double((*ei).target().y()));
        }
    printf("\n\n");
}


The output is not the correct intersection however:

Intersection polygon vertices: (0.00,1.00) (1.00,0.50) (1.00,0.50)
(1.00,1.00)
Intersection polygon edges (0.00,1.00) - (1.00,0.50) :: (1.00,0.50) -
(1.00,0.50) :: (1.00,0.50) - (1.00,1.00) :: (1.00,1.00) - (0.00,1.00) ::



 The correct intersection polygon should have vertices (0,0.5), (1,0.5),
(1,1) and (0,1). Am I missing something or is this an actual bug?

Thank you very much in advance for your help.

Regards,

Nico



--
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.19+.

Top of Page