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?










share|improve this question
























  • 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















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?










share|improve this question
























  • 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













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?










share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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


















  • 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












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






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    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

























    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






    share|improve this answer



























      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






      share|improve this answer

























        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






        share|improve this answer














        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







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 19 at 16:37

























        answered Nov 10 at 15:55









        user8408080

        98239




        98239






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Schultheiß

            Verwaltungsgliederung Dänemarks

            Liste der Kulturdenkmale in Wilsdruff