public static List <OpenTK.Vector3> DouglasPeucker(ref List <OpenTK.Vector3> points, int startIndex, int lastIndex, float epsilon) { float dmax = 0f; int index = startIndex; for (int i = index + 1; i < lastIndex; ++i) { float d = UtilOld.PointLineDistance(points[i], points[startIndex], points[lastIndex]); if (d > dmax) { index = i; dmax = d; } } if (dmax > epsilon) { List <OpenTK.Vector3> res1 = DouglasPeucker(ref points, startIndex, index, epsilon); List <OpenTK.Vector3> res2 = DouglasPeucker(ref points, index, lastIndex, epsilon); //watch out the coordinate system List <OpenTK.Vector3> finalRes = new List <OpenTK.Vector3>(); for (int i = 0; i < res1.Count - 1; ++i) { finalRes.Add(res1[i]); } for (int i = 0; i < res2.Count; ++i) { finalRes.Add(res2[i]); } return(finalRes); } else { return(new List <OpenTK.Vector3>(new OpenTK.Vector3[] { points[startIndex], points[lastIndex] })); } }