ConvexHull cutting corners?

ConvexHull does not always act like I think it should; in some cases it will “cut a corner” and return one less point than expected. In the attached example, it returns only 3 corners of a set of 4 points describing a rectangle.

Am I not understanding what ConvexHull is doing, or is this a bug?


ConvexHullCutCorner.v4p (8.7 kB)

Problem comes that your points are not ordered properly so the result is actually correct in that case.

Here is version with points reordered.

ConvexHullCutCorner_Sort.v4p (12.8 kB)

Hmmm, that’s pretty non-intuitive and restrictive. The ref page for ConvexHull just says “find the hull surrounding all points”. Seems like if it needs sorted points, it should do the sorting internally. Or at least the requirements for the input data should be clearly specified.

And why does it work correctly when one of the points is moved slightly, without changing the order?

I discovered the problem when feeding ConvexHull the output from Contour, so it breaks with the way Contour orders its X/Y data. Again, non-intuitive.

Thanks vux!

ContourConvexHullBug.v4p (10.3 kB)