4

I've got a list of points that I'm trying to generate the convex layers for in python.

Currently I'm simply using the following:

def convex_layers(points):
   points = sorted(set(points))
   layers = []
   while points:
      #Create the next convex hull
      hull = convex_hull(points)

      #Create the new list of points
      for point in hull:
         points.remove(point)

      #Update the list of layers
      layers.append(hull)
   return layers 

Which is just to create the convex hulls one at a time. While it works, it seems a lot like trying to multiply simply by repeated addition. So what I'm asking is if there is a more efficient algorithm specifically for creating convex layers from a set of points

Nuclearman
  • 5,029
  • 1
  • 19
  • 35

2 Answers2

3

If you use the monotone chain algorithm, you will have to do the lexicographic sorting only once. Then each successive layer can be found in O(n) time. This ought to be faster than sorting for each layer.

Gene
  • 46,253
  • 4
  • 58
  • 96
  • Interestingly enough something I considered probably about 10 minutes ago. So what you say is currently what is being done. So perhaps it's already running about as good as it can. Updated the post reflect this. – Nuclearman Nov 09 '12 at 04:16
  • Well then okay, accepting my answer might be appropriate. Thanks. – Gene Nov 09 '12 at 04:38
  • True enough. Though still thinking there should be a way to increase the efficiency by avoiding to have to continue through all the remaining points for each layer. Still probably wouldn't be a great improvement. – Nuclearman Nov 09 '12 at 04:44
0

You can try with scipy spatial.convexHull.

Or, I posted some code on GitHub.

kiriloff
  • 25,609
  • 37
  • 148
  • 229
  • 1
    Both of those only produce the convex hull, which is a step in the brute force convex layers. I was actually looking for something like the algorithm described in [this pdf](http://www.cs.princeton.edu/~chazelle/pubs/ConvexLayers.pdf). While I did find that article after accepting the above answer, I ending up deciding against trying to implement it at the time, hence why the answer above is still accepted. – Nuclearman May 27 '13 at 00:16