7/5/2023 0 Comments Lies of p plot![]() It looks like you already have a way to get the convex hull for your point cloud. But you're dealing with a convex hull, so it should suit your needs. Note that this will work only for convex polygons. The runtime complexity of this approach (once you already have the convex hull) is O(n) where n is the number of edges that the convex hull has. This other Stack Overflow topic includes a solution to finding which "side" of a line a point is on:ĭetermine Which Side of a Line a Point Lies If the target point is to the "left" of all of the vectors, then it is contained by the polygon otherwise, it lies outside the polygon. When doing this, treat the edges as vectors pointing counter-clockwise around the convex hull. For each of the edges, check whether your target point lies to the "left" of that edge. Then loop over all of the edges of the convex hull in counter-clockwise order. Would not want to know how long this would take with QHull.įirst, obtain the convex hull for your point cloud. import numpy as npĪ = np.r_įor the example, I solved the problem for 10000 points in 10 dimensions. In fact, the mere problem of finding out whether a point can be expressed as a convex combination of another set of points can be formulated as a linear programming problem. Moreover, finding the convex hull is computationally expensive, especially in higher dimensions. I would not use a convex hull algorithm, because you do not need to compute the convex hull, you just want to check whether your point can be expressed as a convex combination of the set of points of whom a subset defines a convex hull. # plot tested points `p` - black are inside hull, red outside Lines = LineCollection(edge_points, color='g') ![]() """Add a line between the i-th and j-th points, if not in the list already"""Įdge_points.append(hull.points ]) Plt.plot(hull.points, hull.points, 'o', hold=1) ![]() Poly = Pol圜ollection(hull.points, facecolors='w', edgecolors='b') For 2D data only, given by Nx2 arrays: def plot_in_hull(p, hull):įrom llections import Pol圜ollection, LineCollection If you have matplotlib installed, you can also use the following function that calls the first one and plots the results. It can be used like this: tested = np.random.rand(20,3) It returns a boolean array where True values indicate points that lie in the given convex hull. `hull` is either a object or the `MxK` array of theĬoordinates of `M` points in `K`dimensions for which Delaunay triangulation `p` should be a `NxK` coordinates of `N` points in `K` dimensions Here is an easy solution that requires only scipy: def in_hull(p, hull): ![]()
0 Comments
Leave a Reply. |