Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Oignon convex hull
#1
Hello everyone,
I have been working on a projet for a while now and I don't get my code to work
The problem looks quite simple :

Given a set of points : [[x1,y1],[x2,y2],...,[xn,yn]]
I want to calculate and plot the consecutive convex hulls of the set until the last one containes less than 3 points.


I have been trying to use scipyand the ConvexHull geometry module but I can't remove the points from the current oignon layer to compute the next one and codes like the one from Tom switzer don't seem to work ...
Can you help me and give me advises please ?
I realy need your help,
Thanks a lot,
Scientifix

I would like to get something like this :

[Image: demoOnionPeeling_03.png]
Reply
#2
I cant get your code to work either Think
Reply
#3
True, its quite difficult without a piece of code Rolleyes 
This is the core structure of the code :

def min_convex(points):
    
    oignon_layers = []    
    
    while len(points) > 4:
        layer = convex_hull_graham(points)
        oignon_layers += [layer]
        points = [x for x in points if x not in layer] # I don't know any correct method to remove couples from list of couples
            
    if Plot == True:
        x = [x[0] for x in points]
        y = [y[0] for y in points]
        plt.scatter(x,y,marker = 'o')       #plot all points  
        for x in oignon_layers:               # plot convex layers
             plot convex hull defined by layer x #have been trying to do this with plt.Polygon or scipy.ConvexHull but then I have problems of                                                                      type   
        plt.show()

In order to calculate the convex hull of my set of points, I have been using this code https://gist.github.com/arthur-e/5cf5296...1f3c3398b8
Reply
#4
Here is my new code :
Oups,made a mistake with the code ... I don't know how to edit :(
Can you explain me my mistake ?
Thanks a lot,
Scientifix

Here is the correct one :
from scipy.spatial import ConvexHull
import matplotlib.pyplot as plt
import numpy as np

points = np.random.rand(30, 2)

Plot = True

def min_convex(points):
 
    oignon_layers = []    
 
    while len(points) > 4:
        layer = ConvexHull(points)
        oignon_layers.append(layer)
        points =  points = np.delete(points, layer.vertices, axis=0)
 
    if Plot == True:
          plt.plot(points[:,0], points[:,1], 'o')
          for layer in oignon_layers:
              for simplex in layer.simplices:
                 plt.plot(points[simplex, 0], points[simplex, 1], 'k-')  
    plt.show()
with the error:
Error:
plt.plot(points[simplex, 0], points[simplex, 1],'k-')  IndexError: index 24 is out of bounds for axis 0 with size 4
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help in solving Oignon convex hull petermarsi 1 1,775 Apr-28-2021, 10:23 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020