我使用Clipper 库。在图中,红色和黑色是剪辑,绿色是多边形。代码如下所示。但是,我不明白为什么(7 3 4 14 9 1 2 6).
我认为生成的联合多边形应该是(1 4 14 9)
?数字是图中所示的顶点。
using System;
using ClipperLib;
using Polygon = System.Collections.Generic.List<ClipperLib.IntPoint>;
using Polygons = System.Collections.Generic.List<System.Collections.Generic.List<ClipperLib.IntPoint>>;
namespace ClipperLibrary_Test
{
class Program
{
static void Main(string[] args)
{
Polygons subj = new Polygons(1);
subj.Add(new Polygon(4));
subj[0].Add(new IntPoint(0, 0));
subj[0].Add(new IntPoint(0, 70));
subj[0].Add(new IntPoint(100, 70));
subj[0].Add(new IntPoint(100, 0));
Polygons clip = new Polygons();
clip.Add(new Polygon(4));
clip[0].Add(new IntPoint(40, 0));
clip[0].Add(new IntPoint(40, 100));
clip[0].Add(new IntPoint(150, 100));
clip[0].Add(new IntPoint(150, 0));
clip.Add(new Polygon(4));
clip[1].Add(new IntPoint(-50, 0));
clip[1].Add(new IntPoint(-50, 100));
clip[1].Add(new IntPoint(60, 100));
clip[1].Add(new IntPoint(60, 0));
Polygons solution = new Polygons();
Clipper c = new Clipper();
c.AddPolygons(subj, PolyType.ptSubject);
c.AddPolygons(clip, PolyType.ptClip);
c.Execute(ClipType.ctUnion, solution, PolyFillType.pftEvenOdd, PolyFillType.pftEvenOdd);
foreach (Polygon p in solution)
{
Console.WriteLine("next ");
foreach (IntPoint pt in p)
{
Console.WriteLine("(" + pt.X + "; " + pt.Y + ")");
}
}
//Console.WriteLine("area: " + Clipper.Area(solution[0]).ToString());
Console.WriteLine(solution.Count);
Console.WriteLine("right: " + c.GetBounds().right + ": left: " + c.GetBounds().left);
}
}
}
编辑:
如果我更改PolyFillType.pftEvenOdd
为PolyFillType.pftNonZero
,它工作正常。谁能解释它如何影响结果?