Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpha shape vertices do not seem to be in the correct order #252

Open
MaxwellHogan opened this issue Nov 7, 2023 · 0 comments
Open

Alpha shape vertices do not seem to be in the correct order #252

MaxwellHogan opened this issue Nov 7, 2023 · 0 comments

Comments

@MaxwellHogan
Copy link

I am trying to use the Alpha Shapes 2D alpha shapes methods to create a polygon based on a group of points. I have found that when I try to plot the alpha shapes it appears that the points are not organised in such a way that it will make it possible to properly plot the polygon. See the image below for clarification,
Figure_1
The left plot shows the outcome when Alpha_shape_2 with the blue x showing the REGULAR finite vertices of the alpha shape.
The right shows the outcome when using the weighted alpha shape method.
In both examples you can see how the red polygon criss-crosses back and forth - which is the issue I am trying to resolve. Is this correct behaviour or is there something I can do to resolve this?
The (mostly)full code is shown below:

my_points = {load my points from file}
my_points_weighted = {load my weighted points from file}

fig, (ax, ax1) = plt.subplots(1, 2)
# fig, ax = plt.subplots(figsize = (4,8))
ax.scatter(my_points[:,0], my_points[:,1], marker='x',c = 'orange')

## alpha shape
lst = [Point_2(p[0], p[1]) for p in my_points]
t = Alpha_shape_2(lst, 10000, GENERAL)
t.make_alpha_shape(lst)
optimal_alphas = t.find_optimal_alpha(1)
print(optimal_alphas.next())
print("alpha", t.set_alpha(optimal_alphas.next()))


## weighted alpha shape 
weighting = {load my point weightings from file}
lst_wp = [Weighted_point_2(Point_2(p[0], p[1]), weighting[int(p[1]),int(p[0])]) for p in my_points_weighted]
was = Weighted_alpha_shape_2()
was.make_alpha_shape(lst_wp)

# alpha_shape_vertices
# if t.classify(v) == REGULAR
alpha_vertices_weighted = np.array([(v.point().x(), v.point().y()) for v in was.finite_vertices() if was.classify(v) == REGULAR ], dtype=int)
alpha_vertices = np.array([(v.point().x(), v.point().y()) for v in t.finite_vertices() if t.classify(v) == REGULAR ], dtype=int)

poly = patches.Polygon(alpha_vertices, alpha = .3, color = 'r')
ax.scatter(alpha_vertices[:,0], alpha_vertices[:,1], marker='x')
ax.add_patch(poly)
ylim = ax.get_ylim()
ax.set_ylim(ylim[1], ylim[0])

poly = patches.Polygon(alpha_vertices_weighted, alpha = .3, color = 'r')
ax1.scatter(alpha_vertices_weighted[:,0], alpha_vertices_weighted[:,1], marker='x')
ax1.add_patch(poly)
ylim = ax1.get_ylim()
ax1.set_ylim(ylim[1], ylim[0])

plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant