difference for 2d polygons return incorrect polygon

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

difference for 2d polygons return incorrect polygon

Luoyu
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


Reply | Threaded
Open this post in threaded view
|

Re: difference for 2d polygons return incorrect polygon

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




On Sun, 26 Apr 2020 at 13:53, Luoyu <[hidden email]> 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


Reply | Threaded
Open this post in threaded view
|

回复: difference for 2d polygons return incorrect polygon

Luoyu
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.

发件人: [hidden email] <[hidden email]> 代表 Efi Fogel <[hidden email]>
发送时间: 2020年4月26日 11:26
收件人: [hidden email] <[hidden email]>
主题: Re: [cgal-discuss] difference for 2d polygons return incorrect polygon
 
What do you think is wrong?
   ____  _        ____             _
  /_____/_) o    /__________  __  //
 (____ (   (    (    (_/ (_/-(-'_(/
                         _/




On Sun, 26 Apr 2020 at 13:53, Luoyu <[hidden email]> 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


Reply | Threaded
Open this post in threaded view
|

Re: 回复: difference for 2d polygons return incorrect polygon

Efi Fogel
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, 落 域 <[hidden email]> 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.

发件人: [hidden email] <[hidden email]> 代表 Efi Fogel <[hidden email]>
发送时间: 2020年4月26日 11:26
收件人: [hidden email] <[hidden email]>
主题: Re: [cgal-discuss] difference for 2d polygons return incorrect polygon
 
What do you think is wrong?
   ____  _        ____             _
  /_____/_) o    /__________  __  //
 (____ (   (    (    (_/ (_/-(-'_(/
                         _/




On Sun, 26 Apr 2020 at 13:53, Luoyu <[hidden email]> 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


Reply | Threaded
Open this post in threaded view
|

回复: 回复: difference for 2d polygons return incorrect polygon

Luoyu
oh sorry, the third hole data is wrong, this is the source polygon points, I'll send the right data tomorrow.

发件人: [hidden email] <[hidden email]> 代表 Efi Fogel <[hidden email]>
发送时间: 2020年4月26日 15:31
收件人: [hidden email] <[hidden email]>
主题: Re: [cgal-discuss] 回复: difference for 2d polygons return incorrect polygon
 
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, 落 域 <[hidden email]> 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.

发件人: [hidden email] <[hidden email]> 代表 Efi Fogel <[hidden email]>
发送时间: 2020年4月26日 11:26
收件人: [hidden email] <[hidden email]>
主题: Re: [cgal-discuss] difference for 2d polygons return incorrect polygon
 
What do you think is wrong?
   ____  _        ____             _
  /_____/_) o    /__________  __  //
 (____ (   (    (    (_/ (_/-(-'_(/
                         _/




On Sun, 26 Apr 2020 at 13:53, Luoyu <[hidden email]> 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


Reply | Threaded
Open this post in threaded view
|

回复: 回复: difference for 2d polygons return incorrect polygon

Luoyu
In reply to this post by Efi Fogel
Here is the right hole data,

        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(45.1425400 , 274.162262 ),
                                    Point_2(220.240005 , 186.445908 ),
                                    Point_2(220.240005 , -121.932671),
                                    Point_2(-49.0955925, -267.043030)
        };

发件人: [hidden email] <[hidden email]> 代表 Efi Fogel <[hidden email]>
发送时间: 2020年4月26日 15:31
收件人: [hidden email] <[hidden email]>
主题: Re: [cgal-discuss] 回复: difference for 2d polygons return incorrect polygon
 
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, 落 域 <[hidden email]> 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.

发件人: [hidden email] <[hidden email]> 代表 Efi Fogel <[hidden email]>
发送时间: 2020年4月26日 11:26
收件人: [hidden email] <[hidden email]>
主题: Re: [cgal-discuss] difference for 2d polygons return incorrect polygon
 
What do you think is wrong?
   ____  _        ____             _
  /_____/_) o    /__________  __  //
 (____ (   (    (    (_/ (_/-(-'_(/
                         _/




On Sun, 26 Apr 2020 at 13:53, Luoyu <[hidden email]> 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


Reply | Threaded
Open this post in threaded view
|

Re: difference for 2d polygons return incorrect polygon

axnmol
In reply to this post by Luoyu
Hey Luoyu,
As Efi said, i don't think there is anything wrong with the code in
particular. I have run  the code and considered only first two holes as
third hole is the polygon itself. It executed successfully with the right
output polygon output as : [ 4 vertices: (-369.04 -439.42) (220.24 -121.933)
(220.24 186.446) (-369.04 481.65) ]. And with the third hole included it
gives the expected output of no polygon as defined.

If you are able to find a combination of points for which it fails, i would
be glad to help.

Regards,
Anmolpreet



--
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


Reply | Threaded
Open this post in threaded view
|

Re: 回复: 回复: difference for 2d polygons return incorrect polygon

axnmol
In reply to this post by Luoyu
Hey Luoyu,
With these values the resultant polygon i am getting is - [ 5 vertices:
(-369.04 -439.42) (220.24 -121.933) (-49.0956 -267.043) (45.1425 274.162)
(-369.04 481.65) ].

See if it is the polygon you were expecting.
Regards,
Anmolpreet



--
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


Reply | Threaded
Open this post in threaded view
|

回复: 回复: 回复: difference for 2d polygons return incorrect polygon

Luoyu
Look like the resultant polygon is not what I wish. The point (220.24   -121.933) should be reductant.
In my mind, I think I'll get four points of the red part, and does not contain the blue point.



发件人: [hidden email] <[hidden email]> 代表 axnmol <[hidden email]>
发送时间: 2020年4月27日 1:46
收件人: [hidden email] <[hidden email]>
主题: Re: [cgal-discuss] 回复: 回复: difference for 2d polygons return incorrect polygon
 
Hey Luoyu,
With these values the resultant polygon i am getting is - [ 5 vertices:
(-369.04 -439.42) (220.24 -121.933) (-49.0956 -267.043) (45.1425 274.162)
(-369.04 481.65) ].

See if it is the polygon you were expecting.
Regards,
Anmolpreet



--
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


Reply | Threaded
Open this post in threaded view
|

Re: 回复: 回复: 回复: difference for 2d polygons return incorrect polygon

axnmol
Hey Luoyo,
I don't think the points you are expecting here are collinear. Thats why the
resultant polygon includes the point (220.240005 , -121.932671).
<http://cgal-discuss.949826.n4.nabble.com/file/t376209/Capture.png>
The graphing software you are using may be doing some rounding error as i
may not be using exact predicates. You can check if these points are
collinear in CGAL as :
 Point_2 x, y, z;
    x = Point_2(220.240005, -121.932671);
    y = Point_2(-369.040009, -439.420013);
    z = Point_2(-49.0955925, -267.043030);
 if (CGAL::collinear(x, y, z))std::cout << "yes";

Regards.



--
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


Reply | Threaded
Open this post in threaded view
|

回复: 回复: 回复: 回复: difference for 2d polygons return incorrect polygon

Luoyu
Hey axnmol,

If I use the CGAL::collinear() with three Point_2 variables to check the point is or not collinear, the function tells me the point is not collinear with the segment, but when I use the CGAL::Segment_2::collinear_has_on() to check the point is or not collinear, and this function tells me the point is collinear with the segment.

Does the CGAL::collinear() has any difference with CGAL::Segment_2::collinear_has_on()?

void testPointCollinear()
{
    Point_2 startPoint(220.240005, -121.932671);
    Point_2 endPoint(-369.040009, -439.420013);
    Point_2 checkPoint(-49.0955925, -267.043030);

    CGAL::Segment_2<Kernel> testSegment(startPoint, endPoint);

    if (testSegment.collinear_has_on(checkPoint)) {
        std::cout << "points collinear" << std::endl;
    }
    else {
        std::cout << "points not collinear" << std::endl;
    }
}


And yes, you are right, I convert the Point_2 to the graphing software's struct, the struct defined by the float.

When I convert the Point_2 to the float struct, then convert it back to the Point_2, what should I do to provide the point is collinear with the segment, can you give me some suggest?

发件人: [hidden email] <[hidden email]> 代表 axnmol <[hidden email]>
发送时间: 2020年4月27日 7:58
收件人: [hidden email] <[hidden email]>
主题: Re: [cgal-discuss] 回复: 回复: 回复: difference for 2d polygons return incorrect polygon
 
Hey Luoyo,
I don't think the points you are expecting here are collinear. Thats why the
resultant polygon includes the point (220.240005 , -121.932671).
<http://cgal-discuss.949826.n4.nabble.com/file/t376209/Capture.png>
The graphing software you are using may be doing some rounding error as i
may not be using exact predicates. You can check if these points are
collinear in CGAL as :
 Point_2 x, y, z;
    x = Point_2(220.240005, -121.932671);
    y = Point_2(-369.040009, -439.420013);
    z = Point_2(-49.0955925, -267.043030);
 if (CGAL::collinear(x, y, z))std::cout << "yes";

Regards.



--
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


Reply | Threaded
Open this post in threaded view
|

Re: 回复: 回复: 回复: 回复: difference for 2d polygons return incorrect polygon

axnmol
Hey Luoyo,
I think the function you are looking for is CGAL::Segment_2::has_on(), It
states exactly whether the point lies on the segment or not. The function
CGAL::Segment_2::collinear_has_on() is more like if the points lie in the
rectangular region of which segment is the diagonal of hence considerably
faster.

So try this instead:
void testPointCollinear()
{
    Point_2 startPoint(220.240005, -121.932671);
    Point_2 endPoint(-369.040009, -439.420013);
    Point_2 checkPoint(-49.0955925, -267.043030);

    CGAL::Segment_2<Kernel> testSegment(startPoint, endPoint);

    if (testSegment.has_on(checkPoint)) {
        std::cout << "points collinear" << std::endl;
    }
    else {
        std::cout << "points not collinear" << std::endl;
    }
}



--
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


Reply | Threaded
Open this post in threaded view
|

回复: 回复: 回复: 回复: 回复: difference for 2d polygons return incorrect polygon

Luoyu
Hey axnmol,

I tried to use the CGAL::Segment_2::has_on() to check these points are collinear or not, the function tells me these points are not collinear. So you are right, these points are not collinear that why CGAL::difference can't give me my expecting resultant polygon.

But I must convert to another struct from Point_2 because I can't use CGAL's kernel object type for my program, and when I want to use CGAL polygon boolean operations function then I should convert it back.

Can you give me some suggestions for the problem of conversion loss accuracy in different systems?



发件人: [hidden email] <[hidden email]> 代表 axnmol <[hidden email]>
发送时间: 2020年4月27日 10:01
收件人: [hidden email] <[hidden email]>
主题: Re: [cgal-discuss] 回复: 回复: 回复: 回复: difference for 2d polygons return incorrect polygon
 
Hey Luoyo,
I think the function you are looking for is CGAL::Segment_2::has_on(), It
states exactly whether the point lies on the segment or not. The function
CGAL::Segment_2::collinear_has_on() is more like if the points lie in the
rectangular region of which segment is the diagonal of hence considerably
faster.

So try this instead:
void testPointCollinear()
{
    Point_2 startPoint(220.240005, -121.932671);
    Point_2 endPoint(-369.040009, -439.420013);
    Point_2 checkPoint(-49.0955925, -267.043030);

    CGAL::Segment_2<Kernel> testSegment(startPoint, endPoint);

    if (testSegment.has_on(checkPoint)) {
        std::cout << "points collinear" << std::endl;
    }
    else {
        std::cout << "points not collinear" << std::endl;
    }
}



--
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


Reply | Threaded
Open this post in threaded view
|

Re: 回复: 回复: 回复: 回复: 回复: difference for 2d polygons return incorrect polygon

axnmol
Hey Luoyu,

Glad to know it worked. The type conversion of the Point_2 type and its
usability mainly depends on how your program works. Make sure to avoid any
type of downcasting. There are various solution available for that. I could
have given a further detailed solution, if i had a look at your program.
Moreover i think you can figure it out yourself. If still you need any
assistance, i would be glad to help.

Regards,
Anmolpreet Singh



--
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


Reply | Threaded
Open this post in threaded view
|

回复: 回复: 回复: 回复: 回复: 回复: difference for 2d polygons return incorrect polygon

Luoyu
Hey axnmol,
First of all, very thankul for your answer.

Now I use the CGAL::Construct_project_point_2 function to recalculate the point if the point is close to the segment enough,  before every difference operation, then I get my expecting resultant polygon.

But I have a question about the CGAL::Construct_project_point_2.

If my understanding is right, does the function returns me a collinear point according to a point and a segment?



发件人: [hidden email] <[hidden email]> 代表 axnmol <[hidden email]>
发送时间: 2020年4月27日 14:59
收件人: [hidden email] <[hidden email]>
主题: Re: [cgal-discuss] 回复: 回复: 回复: 回复: 回复: difference for 2d polygons return incorrect polygon
 
Hey Luoyu,

Glad to know it worked. The type conversion of the Point_2 type and its
usability mainly depends on how your program works. Make sure to avoid any
type of downcasting. There are various solution available for that. I could
have given a further detailed solution, if i had a look at your program.
Moreover i think you can figure it out yourself. If still you need any
assistance, i would be glad to help.

Regards,
Anmolpreet Singh



--
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


Reply | Threaded
Open this post in threaded view
|

Re: 回复: 回复: 回复: 回复: 回复: 回复: difference for 2d polygons return incorrect polygon

axnmol
Yup, It will give you Point_2 object as the output which has x - coordinate
as you give in the arguments and it lies on the provided X monotone curve (
In your case the segment constructed by two points ).
 
Anmolpreet Singh



--
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