我有一个多边形,其顶点为P1,P2,P3,..... P11。我的顶点坐标数据类型是double。
我在P1,P7之间也有一条线。
我想在P1和P7之间创建局部凸包,并将原始多边形顶点保留在P7之后。
因此最终的多边形如下;
到目前为止,我将整个多边形转换为凸包,删除凸包中的顶点并添加了壳顶点。它适用于小的多边形,但是当顶点数量增加时,要以这种方式进行管理将不容易。
我试图寻找可用于部分凸包的c#算法,但是除了一些研究之外,我什么都找不到。
有什么想法吗?
答案 0 :(得分:0)
从多边形中删除顶点P8至P11并存储它们,然后在剩下的顶点(P1至P7)上运行凸包转换。之后,重新插入顶点P8至P11(在P7和P1之间)。
答案 1 :(得分:0)
我使用DotSpatial裁剪了多边形
internal static IGeometry Polygonize(IGeometry geometry)
{
var lines = LineStringExtracter.GetLines(geometry);
var polygonizer = new Polygonizer();
polygonizer.Add(lines);
var polys = polygonizer.GetPolygons();
var polyArray = GeometryFactory.ToGeometryArray(polys);
return geometry.Factory.CreateGeometryCollection(polyArray);
}
internal static IGeometry PolygonizeForClip(IGeometry geometry, IPreparedGeometry clip)
{
var lines = LineStringExtracter.GetLines(geometry);
var clippedLines = new List<IGeometry>();
foreach (ILineString line in lines)
{
if (clip.Contains(line))
clippedLines.Add(line);
}
var polygonizer = new Polygonizer();
polygonizer.Add(clippedLines);
var polys = polygonizer.GetPolygons();
var polyArray = GeometryFactory.ToGeometryArray(polys);
return geometry.Factory.CreateGeometryCollection(polyArray);
}
internal static IGeometry SplitPolygon(IGeometry polygon, IGeometry line)
{
var nodedLinework = polygon.Boundary.Union(line);
var polygons = Polygonize(nodedLinework);
// only keep polygons which are inside the input
var output = new List<IGeometry>();
for (var i = 0; i < polygons.NumGeometries; i++)
{
var candpoly = (IPolygon)polygons.GetGeometryN(i);
if (polygon.Contains(candpoly.InteriorPoint))
output.Add(candpoly);
}
return polygon.Factory.BuildGeometry(output);
}
internal static IGeometry ClipPolygon(IGeometry polygon, IPolygonal clipPolygonal)
{
var clipPolygon = (IGeometry)clipPolygonal;
var nodedLinework = polygon.Boundary.Union(clipPolygon.Boundary);
var polygons = Polygonize(nodedLinework);
// only keep polygons which are inside the input
var output = new List<IGeometry>();
for (var i = 0; i < polygons.NumGeometries; i++)
{
var candpoly = (IPolygon)polygons.GetGeometryN(i);
var interiorPoint = candpoly.InteriorPoint;
if (polygon.Contains(interiorPoint) &&
clipPolygon.Contains(interiorPoint))
output.Add(candpoly);
}
return polygon.Factory.BuildGeometry(output);
}
然后
var Splitted = SplitPolygon(Polygon, Line);
然后添加零件。