本文共 2333 字,大约阅读时间需要 7 分钟。
////// Convex Hull compute. /// /// The source image points. /// /// private static void ConvexhullCompute(ref Point[] srcPoints,ref ListstartPoints, ref List endPoints) { Point start; Point end; double a = 0, b = 0; int signa = 0, signb = 0; int max = srcPoints.Length; double temp = 0.0; int t = 0; double tx = 0.0; for (int i = 0; i < max; i++) { start = srcPoints[i]; for (int k = i + 1; k < max; k++) { end = srcPoints[k]; if (start.X == end.X) { for (int j = 0; j < max; j++) { if ((!(signa > 0 && signb > 0)) && (j != i && j != k)) { t = srcPoints[j].X; if (t > start.X) signa++; if (t < start.X) signb++; } } } else { a = (double)(end.Y - start.Y) / (double)(end.X - start.X); b = (double)start.Y - (double)start.X * a; for (int j = 0; j < max; j++) { if ((!(signa > 0 && signb > 0)) && (j != i && j != k)) { temp = a * (double)srcPoints[j].X + b; tx = (double)srcPoints[j].Y; if (temp > tx) signa++; if (temp < tx) signb++; } } } if (signa * signb == 0) { startPoints.Add(start); endPoints.Add(end); } signb = 0; signa = 0; } } }