加入多边形集合并使用 Eyeshot 绘制结果轮廓的最简单方法是什么?到目前为止,我只能获得填充区域,但我对轮廓的合并感兴趣。
问问题
468 次
2 回答
1
由于您拥有该区域,因此很容易从中获取轮廓。
// if you know the region is a simple region (not containing full circles) get the curves
List<ICurve> curves = (region.ContourList.FirstOrDefault() as CompositeCurve).CurveList;
据我所知,ICurve 是直线和弧线。所以你可以测试:
bool isLine = curves[0] is Line
bool isArc = curves[0] is Arc
列表中的所有曲线都是有序的,因此您可以轻松地改造该区域。此外,如果region.ContourList
包含超过 1 个轮廓,则意味着您所在的区域有洞。第一个元素将始终是主轮廓,所有后续元素也是轮廓,但属于孔。
轮廓曲线是逆时针方向的,内部是顺时针方向的。
于 2018-05-22T12:31:29.073 回答
0
我想出了这个解决方案。要显示多边形,只需遍历连接区域,遍历ContourList
并创建LinearPaths
.
private List<PolyRegion2D> Joiner(IEnumerable<Polygon2D> polygons) {
// The resulting polygons are unconnected
List<PolyRegion2D> res = new List<PolyRegion2D>();
// Put every polygon in a region to do the unions.
LinkedList<PolyRegion2D> polygonRegions = new LinkedList<PolyRegion2D>();
foreach (Polygon2D polygon in polygons) {
polygonRegions.AddLast(new PolyRegion2D(new Polygon2D[]{polygon}));
}
while (polygonRegions.Count > 0) {
PolyRegion2D first = polygonRegions.First.Value;
polygonRegions.RemoveFirst();
PolyRegion2D union;
LinkedListNode<PolyRegion2D> connected = FindConnected(first, polygonRegions, out union);
if (connected == null) {
// Unconnected polygon
res.Add(first);
} else {
// Intersection found
polygonRegions.Remove(connected);
polygonRegions.AddFirst(union);
}
}
return res;
}
private LinkedListNode<PolyRegion2D> FindConnected(PolyRegion2D poly, LinkedList<PolyRegion2D> polys, out PolyRegion2D union) {
LinkedListNode<PolyRegion2D> node = polys.First;
while(node != null){
PolyRegion2D[] union_ = PolyRegion2D.Union(poly, node.Value);
if (union_.Length == 1) {
union = union_[0];
return node;
}
node = node.Next;
}
union = null;
return null;
}
于 2018-05-21T08:10:16.400 回答