c# - 部分凸包
问题描述
我有一个顶点为 P1、P2、P3、.....P11 的多边形。我的顶点坐标数据类型是双精度的。
我在 P1,P7 之间也有一条线。
我想在 P1 和 P7 之间创建一个部分凸包,并在 P7 之后保留我的原始多边形顶点。
所以最终的多边形如下;
到目前为止,我将整个多边形转换为凸包,删除凸包中的顶点并添加包顶点。它适用于小多边形,但当顶点数增加时,以这种方式管理并不容易。
我试图寻找可用于部分凸包的 c# 算法,但除了一些研究之外我找不到任何东西。
有任何想法吗?
解决方案
我使用 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);
然后添加部分。
推荐阅读
- ios - 将嵌套的 div 类添加到 blockerList.json
- python - 在弹出窗口中选择元素不会复制我手动单击它时发生的情况
- ios - Interface should be changed before time-consuming task starts in Swift
- firebase - 如何设置 web firebase web
- c++ - 带有交叉编译、模块和库的 CMake 设置
- flutter - 如何修复 angel-dart 的获取包
- javascript - 错误:SearchBox(...):渲染没有返回任何内容。这通常意味着缺少 return 语句。或者,不渲染任何内容,返回 null
- c# - 散列或加密或两者都存储用户的密码?C# Winforms
- excel - Excel replace each char in a string contained in another list
- mysql - Spring Data JPA 只接受持久化数据的时间