我想寫一段代碼給出一個多邊形列表(定義爲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);
現在這兩個在一起很容易合併的多邊形但是他們有點overzelous任何多邊形開放空間被忽略並且開放區域被簡單地組合成單個多邊形,意思是這樣的:
發生。現在這顯然是錯誤的,因爲這兩個多邊形彼此不接觸。兩種方法都會出現相同的結果。結果將與輸入相同。任何想法如何解決這個問題?溶劑不需要使用削波器庫(我沒有與它結合),但我確實需要一些使用由點列表定義的多邊形的東西輸入是一個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
爲例
這個描述的輸入是一個有洞的正方形。
有人甚至知道如何最好地描述這個問題?多邊形中的多邊形被合併?不允許飛地? – Thijser
我想我可能已經找到了溶劑,但這將取決於答案https://stackoverflow.com/questions/34263601/algoritm-for-translating-list-of-wallsections-into-coherent-polygon – Thijser