【问题标题】:clipper lib problems when using holes使用孔时的裁剪器库问题
【发布时间】:2013-10-01 08:57:14
【问题描述】:

我正在开发一个 gis 类型的 2d 地图生成器,我正在使用 Clipper 库。 我在构造过程中注意到一些错误,我认为我做错了什么,所以我运行了这个例子,问题是内部三角形,应该是一个洞没有被考虑在内,它被添加为一个完整的多边形解决方案。 如果我使用 lib 中的函数反转多边形,三角形会完全消失。 从昨天开始,我一直在解决这个问题,但我还没有弄清楚我做错了什么。 有人对这个图书馆有任何问题吗?这是一个常见的错误吗?


我使用了这个sn-p的代码,直接取自你的网站

包括“clipper.hpp”

//from clipper.hpp ...
//typedef signed long long long64;
//struct IntPoint {long64 X; long64 Y;};
//typedef std::vector<IntPoint> Polygon;
//typedef std::vector<Polygon> Polygons;
...
using namespace ClipperLib;

Polygons subj(2), clip(1), solution;

//define outer blue 'subject' polygon
subj[0].push_back(IntPoint(180,200));
subj[0].push_back(IntPoint(260,200));
subj[0].push_back(IntPoint(260,150));
subj[0].push_back(IntPoint(180,150));

//define subject's inner triangular 'hole' (with reverse orientation)
subj[1].push_back(IntPoint(215,160));
subj[1].push_back(IntPoint(230,190));
subj[1].push_back(IntPoint(200,190));

//define orange 'clipping' polygon
clip[0].push_back(IntPoint(190,210));
clip[0].push_back(IntPoint(240,210));
clip[0].push_back(IntPoint(240,130));
clip[0].push_back(IntPoint(190,130));

DrawPolygons(subj, 0x160000FF, 0x600000FF); //blue
DrawPolygons(clip, 0x20FFFF00, 0x30FF0000); //orange

//perform intersection ...
Clipper c;
c.AddPolygons(subj, ptSubject);
c.AddPolygons(clip, ptClip);
c.Execute(ctIntersection, solution, pftNonZero, pftNonZero);
DrawPolygons(solution, 0x3000FF00, 0xFF006600); //solution shaded green

我应该看穿三角形雕刻出来的洞,对吗? 我尝试了一个更简单的场景,里面有一个正方形和一个三角形,我执行了不同的操作,比如减法 xor 和差异我总是得到 2 个多边形,看起来这些操作根本没有执行。

【问题讨论】:

    标签: c++ dictionary graphics 2d polygon


    【解决方案1】:

    Clipper 库已经过广泛测试,并且拥有相当多的用户,因此我相信问题会出现在您的代码中。另外,我不确定您尝试了哪个示例代码,但所有提供的示例都经过了全面测试(在 C++、C# 和 Delphi 中)。

    Angus - Clipper 库的作者

    【讨论】:

      猜你喜欢
      • 2013-10-20
      • 2011-02-08
      • 2017-05-22
      • 1970-01-01
      • 1970-01-01
      • 2011-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多