Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convex hull routines in scipy.spatial gives me back my original set of points

I have a set of points and want to find the convex hull. When I give them to scipy.spatial (either ConvexHull or Delaunay), I just get the original set of points back. By construction, this should not be the case.

Here are the points as a pickled numpy array. My code is given below:

import pickle
from scipy import spatial
import matplotlib.pyplot as plt

points = pickle.load( open( "points.p", "rb" ) )

hullpoints = spatial.ConvexHull(points).points


# plot points
fig = plt.figure()
ax = fig.gca(projection='3d')
# ax.plot(points[:, 0], points[:, 1], points[:, 2], 'r.') # original points
ax.plot(hullpoints[:, 0], hullpoints[:, 1], hullpoints[:, 2], 'r.') # convex hull of points


# set labels and show()
ax.set_xlabel('Player 1')
ax.set_ylabel('Player 2')
ax.set_zlabel('Player 3')
plt.show()

Obviously some of these points are interior to the convex hull and should be removed via spatial.ConvexHull(points) or spatial.Delaunay(points), as done in the 2d examples given here.

Does anyone know why I'm getting the original set of points back? I could brute-force find the exterior points and plot only those (ultimate goal is a surface plot for exterior shape approximated by the points), but it seems that scipy.spatial should be able to do this.

like image 752
benten Avatar asked Oct 15 '13 21:10

benten


People also ask

What is convex hull of a set of points?

The convex hull may be defined either as the intersection of all convex sets containing a given subset of a Euclidean space, or equivalently as the set of all convex combinations of points in the subset.

How to solve convex hull?

The brute force method for determining convex hull is to construct a line connecting two points and then verify whether all points are on the same side or not. There are such n(n – 1) /2 lines with n points, and each line is compared with the remaining n – 2 points to see if they fall on the same side.

What is a convex hull give an example?

One might think of the points as being nails sticking out of a wooden board: then the convex hull is the shape formed by a tight rubber band that surrounds all the nails. A vertex is a corner of a polygon. For example, the highest, lowest, leftmost and rightmost points are all vertices of the convex hull.


1 Answers

Your are using the .points attribute which gives you back the input points. Try to use the .simplices attribute instead, which gives you the "points forming the simplical facets of the convex hull".

See the documentation for more info.

like image 113
Saullo G. P. Castro Avatar answered Sep 24 '22 14:09

Saullo G. P. Castro