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

How_to_adjust_convex_hull_in_3D #1

Open
Ali1990dashti opened this issue May 26, 2021 · 6 comments
Open

How_to_adjust_convex_hull_in_3D #1

Ali1990dashti opened this issue May 26, 2021 · 6 comments

Comments

@Ali1990dashti
Copy link

Dear @tylerjereddy,
Firstly, thanks for informative videos.
I am using scipy (version 1.6.3) to create convex hulls. My points are in 3D but when I use the spatial.ConvexHull it behave strange. My points are creating a regular grid and I want points that are in the exterior part of the grid to be regarded as my border. In the fig I have shown my points. I tried the following code but when I check the vertices of my hull, I did not see the points that I have highlighted by a blue line in my fig.
I appreciate your consideration in advance.

first_surf.txt

import numpy as np
import scipy
from scipy import spatial
pts=np.loadtxt ('first_surf.txt', delimiter="\t")
hull = spatial.ConvexHull(pts[:,:])

cunvex_hull

@tylerjereddy
Copy link
Owner

If the point are exactly co-linear/co-planar they may be ignored by Qhull because of general position/degeneracy.

You could probably make a simple 2D grid to start with and study what happens there when the points are all co-linear. Qhull does have some options for dealing with these situations to some extent: http://www.qhull.org/html/qh-optq.htm#Qc

You'll probably find much more intuitive behavior if you have randomly-generated points, since they won't be co-linear/co-planar. I think many convex hull algorithms encounter failures with co-linearity.

@Ali1990dashti
Copy link
Author

Dear @tylerjereddy,
Thanks for your informative feedback. I tried to create a hull for my points without their z (2D). I used the following syntax:
hull = spatial.ConvexHull(pts[:,:2])
then, it gave me only four points which are corners of my point cloud. It ignored all the points which are between corner points.

@tylerjereddy
Copy link
Owner

I didn't check closely, but perhaps many of the other points lie on a straight line, so they'd get ignored because of degeneracy?

You could use np.random module to produce some random 2D points to get an idea of how that compares with your more structured data.

@Ali1990dashti
Copy link
Author

Dear @tylerjereddy ,
Thanks for paying attention to my issue. I already checked results withrandon point (I used this notebook and video of you), but my points are in 3D and corner point (shown on my fig) are in a straight line but their Z values are different. I mean they have the same X but different Y and Z values or the same Y and different X and Z values.

@tylerjereddy
Copy link
Owner

Like I said above, it sounds like you may have co-linear points because they share a coordinate value, which is a source of degeneracy for convex hull algorithms, and will often cause them to fail or produce output you do not expect.

If you really want the convex hull of this point set, you can try one of two strategies:

  1. microscopically perturb the positions to avoid co-linearity. You can check the Qhull options and feed them into spatial.ConvexHull -- you should be able to find an option that perturbs the input values slightly, but be warned it may still not do what you want.
  2. For simple cases of degeneracy you can try to rotate your entire point set to avoid sharing the same coordinate values. For true co-linearity this won't help much.

@Ali1990dashti
Copy link
Author

Dear @tylerjereddy
Thanks for your help. I will follow your hints. I do appreciate your patience and support.

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

2 participants