凸壳计算代码:
public static PointD[] calcConvexHull(PointD[] points)
{
// 按 x 坐标对点进行排序
Array.Sort(points, (p1, p2) => p1.X.CompareTo(p2.X));
// 创建下凸壳
var lowerHull = new List<PointD>();
foreach (var point in points)
{
while (lowerHull.Count >= 2 &&
Cross(lowerHull[lowerHull.Count - 2], lowerHull[lowerHull.Count - 1], point) <= 0)
{
lowerHull.RemoveAt(lowerHull.Count - 1);
}
lowerHull.Add(point);
}
// 创建上凸壳
var upperHull = new List<PointD>();
for (int i = points.Length - 1; i &