public IList <DepthPointEx> ConvexHull(IList <DepthPointEx> points) { if (points.Count <= 3) { return(points); } _points = points; var pointsSortedByAngle = SortPoints(); int index = 1; while (index + 1 < pointsSortedByAngle.Count) { var value = PointAngleComparer.Compare(pointsSortedByAngle[index - 1], pointsSortedByAngle[index + 1], pointsSortedByAngle[index]); if (value < 0) { index++; } else { pointsSortedByAngle.RemoveAt(index); if (index > 1) { index--; } } } pointsSortedByAngle.Add(pointsSortedByAngle.First()); return(pointsSortedByAngle); }
private IList <DepthPointEx> SortPoints() { var p0 = GetMinimumPoint(); var comparer = new PointAngleComparer(p0); var sortedPoints = new List <DepthPointEx>(_points); sortedPoints.Remove(p0); sortedPoints.Insert(0, p0); sortedPoints.Sort(1, sortedPoints.Count - 1, comparer); return(sortedPoints); }