Computing the Convex Hull of two non intersecting polygon in scipy - convex-hull

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.

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]

Find the first point where a line touches a convex hull

First I have ploted a convex hull for given points using convexHull Matlab function:
x = [4*rand(10,1)-2];
y = [rand(10,1)+5];
DT = delaunayTriangulation(x,y);
C = convexHull(DT);
plot(DT.Points(:,1),DT.Points(:,2),'.','MarkerSize',10)
hold on
plot(DT.Points(C,1),DT.Points(C,2),'r')
This convex hull is just an example, it can be any other convex hull. We assume that convex hull is inside parabola y=x^2.
Then I want to find first point on convex hull that touches line y=[(a^2+1)/a]x-1, when we start from a=1 and it can go until a=+\infty if never touches convex hull (when convex hull is on LHS).
How that can be accomplished? My final goal is to find a on the figure.
For each corner (x_i, y_i) of the polygon solve quadratic equation for a_i.
y_i*a_i = (a_i^2 + 1)*x_i - 1
You can obtain the equation by putting the point coordinates into the line equation. Next, discard solutions that are not relevant for You (a<1). Once this is done, sort solutions by a. If you also need the index of corresponding vertex, sort function in Matlab gives you indexing array as an additional output. You can then plot the line.
As a corner case, the line may hit two vertices. This is not a problem if you just need a. If you want the vertex id, just discard one arbitrarily, or use some additional rule.

Dividing convex hull into multiple hulls in 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.

how can I identify points are inside convex hull in Matlab separately

I created 3D convex hull plot in Matlab. It seems in this function, some of laser points were used for facets of convex hull, but some other points are situated inside convex hull . My question is that how can I identify these points in Matlab separately. Which way is applicable for calculating the perpendicular distance of these points situated inside of convex hull to the nearest convex hull facet (distance from each point to the closest facet of the convex hull)?
I would be very grateful if you could introduce me some references about convex hull function.
On the Matlab file exchange, there is a great function called inhull, which will test whether your points are inside the hull or not. I'm not sure that it provides the distance from the points to the nearest facet, but perhaps the methods used in the code would be simple to change to provide this output.
Check out the function, tsearchn.
The following code creates a sphere in 3D and computes the delaunay triangularization. We then set-up testpoints variable with points to test if they are inside the sphere or not. t returns indices back into TRI for tetrahedra facet that are closest to the point or NaN if the point is outside the sphere.
[X,Y,Z] = sphere(N);
TRI = delaunay(X(:),Y(:),Z(:));
testpoints = [0 0 0; 0 .5 0; 1 2 0]
t = tsearchn([X(:) Y(:) Z(:)],TRI,testpoints)
figure;
trisurf(TRI,X(:),Y(:),Z(:));
Output is,
t =
8182
7779
NaN

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).