本文目录#
凸包问题#
给定平面点集,求其凸包(最小凸多边形)。常用算法:Graham Scan、Andrew Monotone Chain、QuickHull。
Andrew 单调链算法#
- 时间复杂度 O(n log n)(排序);
- 对点按 x、y 排序;
- 分别构建下凸壳与上凸壳。
1 | List<Point> convexHull(List<Point> points) { |
Graham Scan#
- 选取最低点作为起点,按极角排序;
- 使用栈维护凸壳,遇到非左转点弹栈。
工程要点#
- 处理重复点与共线;
- 使用 long 避免溢出;
- 对精度要求高的场景使用 BigDecimal 或预处理坐标。
自检清单#
- 是否正确处理共线点?
- 是否确保点集数量足够(n >= 3)?
- 是否测试边界情况(所有点共线、重复点)?
参考资料#
- MIT OCW 6.851 Geometric Algorithms:https://ocw.mit.edu/.../lecture-3-convex-hull-problem/
- Computational Geometry (de Berg) Chapter 1
- CP-Algorithms Convex Hull:https://cp-algorithms.com/geometry/convex_hull.html
本作品系原创,采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,转载请注明出处。