计算给定点集的凸包。使用单调链算法。
信息
给定一组点,凸包是形成一个包围所有点的多边形的点子集。所实现的算法是 Andrew 的单调链算法,具有高效的 O(n log n) 运行时间。
(Maonus, [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0), via Wikimedia Commons)
用法
该库由 convexHull 函数组成,该函数接收一个泛型对象列表以及用于 x 和 y 坐标的访问器函数,并返回形成凸包的对象。
import 'package:vector_math/vector_math_64.dart';
import 'package:convex_hull/convex_hull.dart';
// you can use an iterable of any object. Here,
// Vector2 is used.
const points = <Vector2>[
Vector2(1, 2),
Vector2(3.2, 1),
Vector2(1.3, 1),
]
// specify what should be considered as the x and y coordinate
List<Vector2> hull = convexHull<Vector2>(points, x: (e) => e.x, y: (e) => e.y);
