/// <summary> /// 切割为简单多边形 /// </summary> /// <param name="poly"></param> /// <returns></returns> public Poly ConvertToSimplePoly2D(Poly poly) { List <IgnoreSideInfo> ignoreSideInfos = new List <IgnoreSideInfo>(); Vector3d startVertA; Vector3d endVertA; PolySide sideAB; Vector3d[] outsideVertexs; Vector3d[] insideVertexs; while (true) { //判断是否存在内环多边形,当不存在内环时,结束算法,返回最后生成的多边形 if (poly.vertexsList.Count <= 1) { return(poly); } outsideVertexs = poly.vertexsList[0]; for (int i = 1; i < poly.vertexsList.Count; i++) { insideVertexs = poly.vertexsList[i]; for (int j = 1; j < insideVertexs.Length; j++) { ignoreSideInfos.Clear(); startVertA = insideVertexs[j]; AddIgnoreSideInfos(poly, i, j, ignoreSideInfos); for (int k = 0; k < outsideVertexs.Length; k++) { endVertA = outsideVertexs[k]; if (ignoreSideInfos.Count == 2) { ignoreSideInfos.RemoveAt(1); } AddIgnoreSideInfos(poly, 0, k, ignoreSideInfos); if (HavOverlayPoint(poly, endVertA)) { continue; } sideAB = geoAlgor.CreatePolySide(startVertA, endVertA); if (HavCrossPoint(poly, sideAB, ignoreSideInfos.ToArray())) { continue; } poly = CreatePolyByRemoveRing(poly, i, j, k, sideAB); i = poly.vertexsList.Count; j = insideVertexs.Length; break; } } if (i == 0) { break; } else if (i == poly.vertexsList.Count - 1) { i = -1; } } } }