我正在尝试编写一段代码,给定一个多边形列表(定义为IntPoints的列表列表),检查它们是否相互接触,如果是,则将它们合并成一个多边形。为了做到这一点,我已经尝试了以下两种方法:
List<List<IntPoint>> output=new List<List<IntPoint>>();
output = Clipper.SimplifyPolygons(input,PolyFillType.pftPositive);
和
Clipper c = new Clipper();
c.AddPaths(input, PolyType.ptClip, true);
c.Execute(ClipType.ctUnion, output);
现在这两种方法都可以轻松地合并多边形,但它们有点过于热衷于忽略任何多边形的开放空间,并将开放区域简单地合并成单个多边形,这意味着像这样的事情发生了: 。
现在这显然是错误的,因为这两个多边形互相不接触。两种方法都会产生相同的结果。有什么办法可以解决这个问题吗?解决方案不必使用clipper库(我不一定要用它),但我需要使用由输入点列表定义的多边形,其中输入是一个List>,而Intpoint只是包含x和y的结构体。
编辑:我注意到当一个多边形没有另一个多边形内部时,这个问题也会发生,所以解决方案总是“填充”。
编辑:这里还有一个输入可能是什么样子的例子。
input[0][0]
{ClipperLib.IntPoint}
X: -724
Y: -472
input[0][1]
{ClipperLib.IntPoint}
X: 428
Y: -472
input[0][2]
{ClipperLib.IntPoint}
X: 428
Y: -472
input[0][3]
{ClipperLib.IntPoint}
X: 428
Y: 632
input[0][4]
{ClipperLib.IntPoint}
X: 428
Y: 632
input[0][5]
{ClipperLib.IntPoint}
X: -724
Y: 632
input[0][6]
{ClipperLib.IntPoint}
X: -724
Y: 632
input[0][7]
{ClipperLib.IntPoint}
X: -724
Y: -472
input[0][8]
{ClipperLib.IntPoint}
X: -88
Y: -218
input[0][9]
{ClipperLib.IntPoint}
X: -107
Y: -218
input[0][10]
{ClipperLib.IntPoint}
X: -107
Y: -218
input[0][11]
{ClipperLib.IntPoint}
X: -107
Y: -209
input[0][12]
{ClipperLib.IntPoint}
X: -107
Y: -209
input[0][13]
{ClipperLib.IntPoint}
X: -320
Y: -172
input[0][14]
{ClipperLib.IntPoint}
X: -320
Y: -172
input[0][15]
{ClipperLib.IntPoint}
X: -320
Y: 132
input[0][16]
{ClipperLib.IntPoint}
X: -320
Y: 132
input[0][17]
{ClipperLib.IntPoint}
X: -88
Y: 173
input[0][18]
{ClipperLib.IntPoint}
X: -88
Y: 173
input[0][19]
{ClipperLib.IntPoint}
X: -88
Y: -201
input[0][20]
{ClipperLib.IntPoint}
X: -88
Y: -201
input[0][21]
{ClipperLib.IntPoint}
X: -88
Y: -218
这里描述的输入是一个带有切口的正方形。