Dividing convex hull into multiple hulls in matlab - matlab

I am facing a problem on how to break down a convex hull into multiple hulls. I know how to merge convex hulls but is there any way to divide them, although them being a being of a same category.
Is there any algorithm where a convex hull is divided with the same boundary being shared with other hulls?
I want to implement this in Matlab.
Thanks in advance.

Related

How to efficiently find upper and lower hulls (w.r.t. some dimension) for Convex Hull in dimension d?

There are a few undefined things in the Wikipedia page like "upward ray".
A lot of explanations only deal with 2d. If you pick a dimension you can calculate the convex hull of the points with that dimension dropeed and I think that gives you the extreme points. But how do you determine (computationally, not with epsilon statements) whether the other points are above or below efficiently?
In two dimensions, the convex hull is sometimes partitioned into two
parts, the upper hull and the lower hull, stretching between the
leftmost and rightmost points of the hull. More generally, for convex
hulls in any dimension, one can partition the boundary of the hull
into upward-facing points (points for which an upward ray is disjoint
from the hull), downward-facing points, and extreme points. For
three-dimensional hulls, the upward-facing and downward-facing parts
of the boundary form topological disks.[7]

How to check if given 3d point is outside convex hull

I'm working on a science project. I have a list of xyz-coordinates of voronoi diagram vertices, and a list of points that create my protein's convex-hull (from triangulation). Now some of the vertices lie quite far from the hull and I'd like to filter them out. How can I do it in c++ ? For now it doesn't have to be super optimised, I'm only focused on removing those points.
visualization
I was also thinking to check if a line from voronoi vertex(red crosses) to center of protein(pink sphere) is intersecting with hull face at any point, but I'm not sure how to achive that.
I've read that you can check if a point is inside a polygon by counting the times an infinite line from the point is crossing the hull, but that was for two dimensions. Can similar approach be implemented to suit my needs ?
https://www.geeksforgeeks.org/how-to-check-if-a-given-point-lies-inside-a-polygon/
Let's start with the two-dimensional case. You can find the solution to that on CS.SX:
Determine whether a point lies in a convex hull of points in O(logn)
The idea is that each two consecutive points on the convex hull define a triangular slice of the plane (to some internal point of the hull); you can find the slice in which your point is located, and check whether it's closer to the internal point than the line segment bounding the slide.
For the three-dimensional case, I'm guessing you should be able to do something similar, but the search for the 3 points forming the relevant triangle might be a little tricky. In particular, it would also depend on how the convex hull is represented - as in the 2-d case the convex hull is just a sequence of consecutive points on a cycle.
I know this doesn't quite solve your problem but it's the best I've got given what you've written...

Convex Hull with a predefined number of vertices

I am working on image segmentation and I thought the convex hull can provide me with a simple solution to my problem. Currently I have polygons with for sides (see image below). Due to image processing issues, the shape does not have clean straight sides and hence when I use the standard convex hull (in Matlab) I may get more than the four main corners to define it.
My goal is to force the convex hull algorithm to find the best 4 vertices that will enclose my polygons (i.e. 4 best enclosing vertices per polygon). Is this possible? An example code will be appreciated.
Thanks
The problem of the minimum area bounding polygon is briefly mentioned in "Geometric applications of a matrix-searching algorithm" (see Applications section). It is not simple and is probably not the way for you.
For an easier (but approximate) answer to your question, you can consider the four cardinal directions and find the farthest points in these, which define a quadrilateral. (Also consider the four intermediate directions, which are more appropriate for an axis-aligned rectangle.)
If you insist having an enclosing quadrilateral, you can translate the four edges to the farthest points in the respective perpendicular directions, and find the pairwise intersections.
If you insist having a rectangle, compute the convex hull and find the minimum area or minimum perimeter bounding rectangle by the Rotating Calipers method. https://geidav.wordpress.com/tag/rotating-calipers/

Computing the Convex Hull of two non intersecting polygon in scipy

Is there any scipy method that computes the Convex hull of two non intersecting polygon? I have 2 set of points P1 and P2 and their convex hulls CH(P1) and CH(P2), where the hulls are non intersecting. I want to find the Convex hull of union of points in P1 and P2. Is there any build in method in scipy?
Documentation for Scipy's convex hull implementation can be found here. Simply concatenate the two arrays of points to obtain their union. Feed this set to the convex hull algorithm.
Every point in each polygon lies within the convex hull of its polygon. In turn, both polygons have their convex hull contained entirely inside the larger convex hull. So, every point in each polygon lies within the larger convex hull, meaning it is also valid for the complete union of polygon points.

number of holes in convex hull in matlab

I have used convhulln in matlab to find the surrounding shape of a set of data points in 3D. See history in:
Convhull in Matlab.
A good samaritan helped me to find out how it works in matlab. I need to know the propertion of gaps (holes) inside the 3D volume to the total volume of the convex hull. Is this possible?
thanks.
If I understood your question, I would try this:
find the convex hull of your set of points, which I will call S, using convhull
find the convex hull of the set S', where
S' := S - points_defining_the_convex_hull(S)
(i.e., S' contains the points of S which do not "enlarge" its convex hull, thus the ones which are inside the convex hull itself.)
make the difference/proportion between the volumes of S and S' (trivial, both are convex).
There is a strong assumption on the topology of the hole considered, i.e.
"the convex hull of the S' is the hole".
If you have a more complex topology of holes you can't avoid making active use of it (my guess, of course).