This is an implementation of the Gift-Wrapping algorithm for calculating the convex hull of a set of points in 2D space. This example is for Unity C#. The code is listed below this readme.
To compute the convex hull of a list of points (List<Vector3>
), it's super easy:
var convexHull = ConvexHull.compute(points);
If you want to the convex hull to loop back to the beginning (duplicate vertex at the end of the hull), you can additionally pass a second parameter:
var convexHull = ConvexHull.compute(points, true);
Then, to render it, it's as easy as something like:
for(var i = 1; i < convexHull.Count; i++)
Gizmos.DrawLine(convexHull[i-1], convexHull[i]);
Hi, what license is this code available under? Thank you!