Getting points in convex hull
up vote
0
down vote
favorite
I have two overlapping sets of points T and B.
I want to return all points from T that are within the convex hull of B
I compute the convex hulls as follows
from scipy.spatial import Convexhull
import numpy as np
T=np.asarray(T)
B=np.asarray(B)
Thull = ConvexHull(T)
Bhull = ConvexHull(B)
How do I do the spatial query?
python python-3.x scipy
add a comment |
up vote
0
down vote
favorite
I have two overlapping sets of points T and B.
I want to return all points from T that are within the convex hull of B
I compute the convex hulls as follows
from scipy.spatial import Convexhull
import numpy as np
T=np.asarray(T)
B=np.asarray(B)
Thull = ConvexHull(T)
Bhull = ConvexHull(B)
How do I do the spatial query?
python python-3.x scipy
Possible duplicate of What's an efficient way to find if a point lies in the convex hull of a point cloud?
– user8408080
Nov 10 at 2:13
nearly, but not quite, I don't want a true/false response. I want to add all points from T that are inside convexhull B to a new object.
– Gary Nobles
Nov 10 at 7:38
Have you seen the answer?
– user8408080
Nov 22 at 11:52
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have two overlapping sets of points T and B.
I want to return all points from T that are within the convex hull of B
I compute the convex hulls as follows
from scipy.spatial import Convexhull
import numpy as np
T=np.asarray(T)
B=np.asarray(B)
Thull = ConvexHull(T)
Bhull = ConvexHull(B)
How do I do the spatial query?
python python-3.x scipy
I have two overlapping sets of points T and B.
I want to return all points from T that are within the convex hull of B
I compute the convex hulls as follows
from scipy.spatial import Convexhull
import numpy as np
T=np.asarray(T)
B=np.asarray(B)
Thull = ConvexHull(T)
Bhull = ConvexHull(B)
How do I do the spatial query?
python python-3.x scipy
python python-3.x scipy
edited Nov 10 at 0:30
eyllanesc
69.7k93052
69.7k93052
asked Nov 10 at 0:07
Gary Nobles
191113
191113
Possible duplicate of What's an efficient way to find if a point lies in the convex hull of a point cloud?
– user8408080
Nov 10 at 2:13
nearly, but not quite, I don't want a true/false response. I want to add all points from T that are inside convexhull B to a new object.
– Gary Nobles
Nov 10 at 7:38
Have you seen the answer?
– user8408080
Nov 22 at 11:52
add a comment |
Possible duplicate of What's an efficient way to find if a point lies in the convex hull of a point cloud?
– user8408080
Nov 10 at 2:13
nearly, but not quite, I don't want a true/false response. I want to add all points from T that are inside convexhull B to a new object.
– Gary Nobles
Nov 10 at 7:38
Have you seen the answer?
– user8408080
Nov 22 at 11:52
Possible duplicate of What's an efficient way to find if a point lies in the convex hull of a point cloud?
– user8408080
Nov 10 at 2:13
Possible duplicate of What's an efficient way to find if a point lies in the convex hull of a point cloud?
– user8408080
Nov 10 at 2:13
nearly, but not quite, I don't want a true/false response. I want to add all points from T that are inside convexhull B to a new object.
– Gary Nobles
Nov 10 at 7:38
nearly, but not quite, I don't want a true/false response. I want to add all points from T that are inside convexhull B to a new object.
– Gary Nobles
Nov 10 at 7:38
Have you seen the answer?
– user8408080
Nov 22 at 11:52
Have you seen the answer?
– user8408080
Nov 22 at 11:52
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Here is an example of what you want using the function defined in the other question I posted in the comments:
from scipy.spatial import Delaunay
import numpy as np
import matplotlib.pyplot as plt
def in_hull(p, hull):
"""
Test if points in `p` are in `hull`
`p` should be a `NxK` coordinates of `N` points in `K` dimensions
`hull` is either a scipy.spatial.Delaunay object or the `MxK` array of the
coordinates of `M` points in `K`dimensions for which Delaunay triangulation
will be computed
"""
if not isinstance(hull,Delaunay):
hull = Delaunay(hull)
return hull.find_simplex(p)>=0
T = np.random.rand(30,2)
B = T + np.array([[0.4, 0] for i in range(30)])
plt.plot(T[:,0], T[:,1], 'o')
plt.plot(B[:,0], B[:,1], 'o')
new_points = T[in_hull(T,B)]
plt.plot(new_points[:,0], new_points[:,1], 'x', markersize=8)
This finds all points of T
in the hull of B
and saves them in new_points
. I also plot it, so you see the result
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Here is an example of what you want using the function defined in the other question I posted in the comments:
from scipy.spatial import Delaunay
import numpy as np
import matplotlib.pyplot as plt
def in_hull(p, hull):
"""
Test if points in `p` are in `hull`
`p` should be a `NxK` coordinates of `N` points in `K` dimensions
`hull` is either a scipy.spatial.Delaunay object or the `MxK` array of the
coordinates of `M` points in `K`dimensions for which Delaunay triangulation
will be computed
"""
if not isinstance(hull,Delaunay):
hull = Delaunay(hull)
return hull.find_simplex(p)>=0
T = np.random.rand(30,2)
B = T + np.array([[0.4, 0] for i in range(30)])
plt.plot(T[:,0], T[:,1], 'o')
plt.plot(B[:,0], B[:,1], 'o')
new_points = T[in_hull(T,B)]
plt.plot(new_points[:,0], new_points[:,1], 'x', markersize=8)
This finds all points of T
in the hull of B
and saves them in new_points
. I also plot it, so you see the result
add a comment |
up vote
0
down vote
Here is an example of what you want using the function defined in the other question I posted in the comments:
from scipy.spatial import Delaunay
import numpy as np
import matplotlib.pyplot as plt
def in_hull(p, hull):
"""
Test if points in `p` are in `hull`
`p` should be a `NxK` coordinates of `N` points in `K` dimensions
`hull` is either a scipy.spatial.Delaunay object or the `MxK` array of the
coordinates of `M` points in `K`dimensions for which Delaunay triangulation
will be computed
"""
if not isinstance(hull,Delaunay):
hull = Delaunay(hull)
return hull.find_simplex(p)>=0
T = np.random.rand(30,2)
B = T + np.array([[0.4, 0] for i in range(30)])
plt.plot(T[:,0], T[:,1], 'o')
plt.plot(B[:,0], B[:,1], 'o')
new_points = T[in_hull(T,B)]
plt.plot(new_points[:,0], new_points[:,1], 'x', markersize=8)
This finds all points of T
in the hull of B
and saves them in new_points
. I also plot it, so you see the result
add a comment |
up vote
0
down vote
up vote
0
down vote
Here is an example of what you want using the function defined in the other question I posted in the comments:
from scipy.spatial import Delaunay
import numpy as np
import matplotlib.pyplot as plt
def in_hull(p, hull):
"""
Test if points in `p` are in `hull`
`p` should be a `NxK` coordinates of `N` points in `K` dimensions
`hull` is either a scipy.spatial.Delaunay object or the `MxK` array of the
coordinates of `M` points in `K`dimensions for which Delaunay triangulation
will be computed
"""
if not isinstance(hull,Delaunay):
hull = Delaunay(hull)
return hull.find_simplex(p)>=0
T = np.random.rand(30,2)
B = T + np.array([[0.4, 0] for i in range(30)])
plt.plot(T[:,0], T[:,1], 'o')
plt.plot(B[:,0], B[:,1], 'o')
new_points = T[in_hull(T,B)]
plt.plot(new_points[:,0], new_points[:,1], 'x', markersize=8)
This finds all points of T
in the hull of B
and saves them in new_points
. I also plot it, so you see the result
Here is an example of what you want using the function defined in the other question I posted in the comments:
from scipy.spatial import Delaunay
import numpy as np
import matplotlib.pyplot as plt
def in_hull(p, hull):
"""
Test if points in `p` are in `hull`
`p` should be a `NxK` coordinates of `N` points in `K` dimensions
`hull` is either a scipy.spatial.Delaunay object or the `MxK` array of the
coordinates of `M` points in `K`dimensions for which Delaunay triangulation
will be computed
"""
if not isinstance(hull,Delaunay):
hull = Delaunay(hull)
return hull.find_simplex(p)>=0
T = np.random.rand(30,2)
B = T + np.array([[0.4, 0] for i in range(30)])
plt.plot(T[:,0], T[:,1], 'o')
plt.plot(B[:,0], B[:,1], 'o')
new_points = T[in_hull(T,B)]
plt.plot(new_points[:,0], new_points[:,1], 'x', markersize=8)
This finds all points of T
in the hull of B
and saves them in new_points
. I also plot it, so you see the result
edited Nov 19 at 16:37
answered Nov 10 at 15:55
user8408080
98239
98239
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234848%2fgetting-points-in-convex-hull%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of What's an efficient way to find if a point lies in the convex hull of a point cloud?
– user8408080
Nov 10 at 2:13
nearly, but not quite, I don't want a true/false response. I want to add all points from T that are inside convexhull B to a new object.
– Gary Nobles
Nov 10 at 7:38
Have you seen the answer?
– user8408080
Nov 22 at 11:52