Picking mesh elements that are not on the border of the mesh

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












9












$begingroup$


As an example, let's say I use a set of random points to create a Voronoi mesh



pts = RandomReal[-1, 1, 100, 2];
VoronoiMesh[pts, -1, 1]


and get something that looks like this:



enter image description here



My question is: Is there an efficient way to determine which of the regions (mesh elements, whatever you call them) are not touching the edge of the mesh? I know that there are a lot of built in functions that give properties of elements in a mesh, but I am unfamiliar with them, and I can't seem to find an efficient way to do this beyond "looping" through all elements and just picking which elements do not have points that touch the edge.










share|improve this question









$endgroup$











  • $begingroup$
    RegionBoundary? To get coordinates you can do RegionBoundary@mesh // MeshCoordinates
    $endgroup$
    – b3m2a1
    Jan 7 at 22:45











  • $begingroup$
    @b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
    $endgroup$
    – Aaron Stevens
    Jan 7 at 22:52










  • $begingroup$
    Ah I did a lazy read through and figured you wanted the boundary. Always possible to take a complement with the boundary cells, though, to get the interior.
    $endgroup$
    – b3m2a1
    Jan 7 at 22:53















9












$begingroup$


As an example, let's say I use a set of random points to create a Voronoi mesh



pts = RandomReal[-1, 1, 100, 2];
VoronoiMesh[pts, -1, 1]


and get something that looks like this:



enter image description here



My question is: Is there an efficient way to determine which of the regions (mesh elements, whatever you call them) are not touching the edge of the mesh? I know that there are a lot of built in functions that give properties of elements in a mesh, but I am unfamiliar with them, and I can't seem to find an efficient way to do this beyond "looping" through all elements and just picking which elements do not have points that touch the edge.










share|improve this question









$endgroup$











  • $begingroup$
    RegionBoundary? To get coordinates you can do RegionBoundary@mesh // MeshCoordinates
    $endgroup$
    – b3m2a1
    Jan 7 at 22:45











  • $begingroup$
    @b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
    $endgroup$
    – Aaron Stevens
    Jan 7 at 22:52










  • $begingroup$
    Ah I did a lazy read through and figured you wanted the boundary. Always possible to take a complement with the boundary cells, though, to get the interior.
    $endgroup$
    – b3m2a1
    Jan 7 at 22:53













9












9








9





$begingroup$


As an example, let's say I use a set of random points to create a Voronoi mesh



pts = RandomReal[-1, 1, 100, 2];
VoronoiMesh[pts, -1, 1]


and get something that looks like this:



enter image description here



My question is: Is there an efficient way to determine which of the regions (mesh elements, whatever you call them) are not touching the edge of the mesh? I know that there are a lot of built in functions that give properties of elements in a mesh, but I am unfamiliar with them, and I can't seem to find an efficient way to do this beyond "looping" through all elements and just picking which elements do not have points that touch the edge.










share|improve this question









$endgroup$




As an example, let's say I use a set of random points to create a Voronoi mesh



pts = RandomReal[-1, 1, 100, 2];
VoronoiMesh[pts, -1, 1]


and get something that looks like this:



enter image description here



My question is: Is there an efficient way to determine which of the regions (mesh elements, whatever you call them) are not touching the edge of the mesh? I know that there are a lot of built in functions that give properties of elements in a mesh, but I am unfamiliar with them, and I can't seem to find an efficient way to do this beyond "looping" through all elements and just picking which elements do not have points that touch the edge.







performance-tuning mesh






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 7 at 22:30









Aaron StevensAaron Stevens

319110




319110











  • $begingroup$
    RegionBoundary? To get coordinates you can do RegionBoundary@mesh // MeshCoordinates
    $endgroup$
    – b3m2a1
    Jan 7 at 22:45











  • $begingroup$
    @b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
    $endgroup$
    – Aaron Stevens
    Jan 7 at 22:52










  • $begingroup$
    Ah I did a lazy read through and figured you wanted the boundary. Always possible to take a complement with the boundary cells, though, to get the interior.
    $endgroup$
    – b3m2a1
    Jan 7 at 22:53
















  • $begingroup$
    RegionBoundary? To get coordinates you can do RegionBoundary@mesh // MeshCoordinates
    $endgroup$
    – b3m2a1
    Jan 7 at 22:45











  • $begingroup$
    @b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
    $endgroup$
    – Aaron Stevens
    Jan 7 at 22:52










  • $begingroup$
    Ah I did a lazy read through and figured you wanted the boundary. Always possible to take a complement with the boundary cells, though, to get the interior.
    $endgroup$
    – b3m2a1
    Jan 7 at 22:53















$begingroup$
RegionBoundary? To get coordinates you can do RegionBoundary@mesh // MeshCoordinates
$endgroup$
– b3m2a1
Jan 7 at 22:45





$begingroup$
RegionBoundary? To get coordinates you can do RegionBoundary@mesh // MeshCoordinates
$endgroup$
– b3m2a1
Jan 7 at 22:45













$begingroup$
@b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
$endgroup$
– Aaron Stevens
Jan 7 at 22:52




$begingroup$
@b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
$endgroup$
– Aaron Stevens
Jan 7 at 22:52












$begingroup$
Ah I did a lazy read through and figured you wanted the boundary. Always possible to take a complement with the boundary cells, though, to get the interior.
$endgroup$
– b3m2a1
Jan 7 at 22:53




$begingroup$
Ah I did a lazy read through and figured you wanted the boundary. Always possible to take a complement with the boundary cells, though, to get the interior.
$endgroup$
– b3m2a1
Jan 7 at 22:53










2 Answers
2






active

oldest

votes


















9












$begingroup$

vm = VoronoiMesh[pts, -1, 1]
HighlightMesh[vm, MeshCellIndex[vm, 2, "Interior"]]


enter image description here



Related: Boundary cells of a mesh?



Show[vm, Epilog -> Opacity[.7, Orange], MeshPrimitives[vm, 2, "Interior"]]


enter image description here






share|improve this answer











$endgroup$












  • $begingroup$
    Yep that was the simple answer I was expecting haha. Thanks!
    $endgroup$
    – Aaron Stevens
    Jan 7 at 22:55






  • 2




    $begingroup$
    @kglr Wow, I'm impressed. Where did you find this syntax? The doc page of MeshCellIndex does not show it as example...
    $endgroup$
    – Henrik Schumacher
    Jan 7 at 23:29






  • 1




    $begingroup$
    @HenrikSchumacher, blind search trying some objects returned by vm["Properties"]:)
    $endgroup$
    – kglr
    Jan 8 at 0:00










  • $begingroup$
    @HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
    $endgroup$
    – Aaron Stevens
    Jan 8 at 12:45


















7












$begingroup$

For planar MeshRegion that arise from DelaunayMesh or VoronoiMesh, usually



R["InteriorFaces"]


should work.



A more general and more transparent ways is to use the package "IGraphM`" by Szabolcs as follows:



Needs["IGraphM`"]

A = IGMeshCellAdjacencyMatrix[R, 1, 2];
bndedges = Random`Private`PositionsOf[Total[A, 2], 1];
interiorfaces = Random`Private`PositionsOf[Total[A[[bndedges]]], 0];

HighlightMesh[R, Thread[2, interiorfaces]]


enter image description here






share|improve this answer









$endgroup$












    Your Answer





    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "387"
    ;
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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%2fmathematica.stackexchange.com%2fquestions%2f189008%2fpicking-mesh-elements-that-are-not-on-the-border-of-the-mesh%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    9












    $begingroup$

    vm = VoronoiMesh[pts, -1, 1]
    HighlightMesh[vm, MeshCellIndex[vm, 2, "Interior"]]


    enter image description here



    Related: Boundary cells of a mesh?



    Show[vm, Epilog -> Opacity[.7, Orange], MeshPrimitives[vm, 2, "Interior"]]


    enter image description here






    share|improve this answer











    $endgroup$












    • $begingroup$
      Yep that was the simple answer I was expecting haha. Thanks!
      $endgroup$
      – Aaron Stevens
      Jan 7 at 22:55






    • 2




      $begingroup$
      @kglr Wow, I'm impressed. Where did you find this syntax? The doc page of MeshCellIndex does not show it as example...
      $endgroup$
      – Henrik Schumacher
      Jan 7 at 23:29






    • 1




      $begingroup$
      @HenrikSchumacher, blind search trying some objects returned by vm["Properties"]:)
      $endgroup$
      – kglr
      Jan 8 at 0:00










    • $begingroup$
      @HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
      $endgroup$
      – Aaron Stevens
      Jan 8 at 12:45















    9












    $begingroup$

    vm = VoronoiMesh[pts, -1, 1]
    HighlightMesh[vm, MeshCellIndex[vm, 2, "Interior"]]


    enter image description here



    Related: Boundary cells of a mesh?



    Show[vm, Epilog -> Opacity[.7, Orange], MeshPrimitives[vm, 2, "Interior"]]


    enter image description here






    share|improve this answer











    $endgroup$












    • $begingroup$
      Yep that was the simple answer I was expecting haha. Thanks!
      $endgroup$
      – Aaron Stevens
      Jan 7 at 22:55






    • 2




      $begingroup$
      @kglr Wow, I'm impressed. Where did you find this syntax? The doc page of MeshCellIndex does not show it as example...
      $endgroup$
      – Henrik Schumacher
      Jan 7 at 23:29






    • 1




      $begingroup$
      @HenrikSchumacher, blind search trying some objects returned by vm["Properties"]:)
      $endgroup$
      – kglr
      Jan 8 at 0:00










    • $begingroup$
      @HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
      $endgroup$
      – Aaron Stevens
      Jan 8 at 12:45













    9












    9








    9





    $begingroup$

    vm = VoronoiMesh[pts, -1, 1]
    HighlightMesh[vm, MeshCellIndex[vm, 2, "Interior"]]


    enter image description here



    Related: Boundary cells of a mesh?



    Show[vm, Epilog -> Opacity[.7, Orange], MeshPrimitives[vm, 2, "Interior"]]


    enter image description here






    share|improve this answer











    $endgroup$



    vm = VoronoiMesh[pts, -1, 1]
    HighlightMesh[vm, MeshCellIndex[vm, 2, "Interior"]]


    enter image description here



    Related: Boundary cells of a mesh?



    Show[vm, Epilog -> Opacity[.7, Orange], MeshPrimitives[vm, 2, "Interior"]]


    enter image description here







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 7 at 22:56

























    answered Jan 7 at 22:52









    kglrkglr

    180k9200413




    180k9200413











    • $begingroup$
      Yep that was the simple answer I was expecting haha. Thanks!
      $endgroup$
      – Aaron Stevens
      Jan 7 at 22:55






    • 2




      $begingroup$
      @kglr Wow, I'm impressed. Where did you find this syntax? The doc page of MeshCellIndex does not show it as example...
      $endgroup$
      – Henrik Schumacher
      Jan 7 at 23:29






    • 1




      $begingroup$
      @HenrikSchumacher, blind search trying some objects returned by vm["Properties"]:)
      $endgroup$
      – kglr
      Jan 8 at 0:00










    • $begingroup$
      @HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
      $endgroup$
      – Aaron Stevens
      Jan 8 at 12:45
















    • $begingroup$
      Yep that was the simple answer I was expecting haha. Thanks!
      $endgroup$
      – Aaron Stevens
      Jan 7 at 22:55






    • 2




      $begingroup$
      @kglr Wow, I'm impressed. Where did you find this syntax? The doc page of MeshCellIndex does not show it as example...
      $endgroup$
      – Henrik Schumacher
      Jan 7 at 23:29






    • 1




      $begingroup$
      @HenrikSchumacher, blind search trying some objects returned by vm["Properties"]:)
      $endgroup$
      – kglr
      Jan 8 at 0:00










    • $begingroup$
      @HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
      $endgroup$
      – Aaron Stevens
      Jan 8 at 12:45















    $begingroup$
    Yep that was the simple answer I was expecting haha. Thanks!
    $endgroup$
    – Aaron Stevens
    Jan 7 at 22:55




    $begingroup$
    Yep that was the simple answer I was expecting haha. Thanks!
    $endgroup$
    – Aaron Stevens
    Jan 7 at 22:55




    2




    2




    $begingroup$
    @kglr Wow, I'm impressed. Where did you find this syntax? The doc page of MeshCellIndex does not show it as example...
    $endgroup$
    – Henrik Schumacher
    Jan 7 at 23:29




    $begingroup$
    @kglr Wow, I'm impressed. Where did you find this syntax? The doc page of MeshCellIndex does not show it as example...
    $endgroup$
    – Henrik Schumacher
    Jan 7 at 23:29




    1




    1




    $begingroup$
    @HenrikSchumacher, blind search trying some objects returned by vm["Properties"]:)
    $endgroup$
    – kglr
    Jan 8 at 0:00




    $begingroup$
    @HenrikSchumacher, blind search trying some objects returned by vm["Properties"]:)
    $endgroup$
    – kglr
    Jan 8 at 0:00












    $begingroup$
    @HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
    $endgroup$
    – Aaron Stevens
    Jan 8 at 12:45




    $begingroup$
    @HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
    $endgroup$
    – Aaron Stevens
    Jan 8 at 12:45











    7












    $begingroup$

    For planar MeshRegion that arise from DelaunayMesh or VoronoiMesh, usually



    R["InteriorFaces"]


    should work.



    A more general and more transparent ways is to use the package "IGraphM`" by Szabolcs as follows:



    Needs["IGraphM`"]

    A = IGMeshCellAdjacencyMatrix[R, 1, 2];
    bndedges = Random`Private`PositionsOf[Total[A, 2], 1];
    interiorfaces = Random`Private`PositionsOf[Total[A[[bndedges]]], 0];

    HighlightMesh[R, Thread[2, interiorfaces]]


    enter image description here






    share|improve this answer









    $endgroup$

















      7












      $begingroup$

      For planar MeshRegion that arise from DelaunayMesh or VoronoiMesh, usually



      R["InteriorFaces"]


      should work.



      A more general and more transparent ways is to use the package "IGraphM`" by Szabolcs as follows:



      Needs["IGraphM`"]

      A = IGMeshCellAdjacencyMatrix[R, 1, 2];
      bndedges = Random`Private`PositionsOf[Total[A, 2], 1];
      interiorfaces = Random`Private`PositionsOf[Total[A[[bndedges]]], 0];

      HighlightMesh[R, Thread[2, interiorfaces]]


      enter image description here






      share|improve this answer









      $endgroup$















        7












        7








        7





        $begingroup$

        For planar MeshRegion that arise from DelaunayMesh or VoronoiMesh, usually



        R["InteriorFaces"]


        should work.



        A more general and more transparent ways is to use the package "IGraphM`" by Szabolcs as follows:



        Needs["IGraphM`"]

        A = IGMeshCellAdjacencyMatrix[R, 1, 2];
        bndedges = Random`Private`PositionsOf[Total[A, 2], 1];
        interiorfaces = Random`Private`PositionsOf[Total[A[[bndedges]]], 0];

        HighlightMesh[R, Thread[2, interiorfaces]]


        enter image description here






        share|improve this answer









        $endgroup$



        For planar MeshRegion that arise from DelaunayMesh or VoronoiMesh, usually



        R["InteriorFaces"]


        should work.



        A more general and more transparent ways is to use the package "IGraphM`" by Szabolcs as follows:



        Needs["IGraphM`"]

        A = IGMeshCellAdjacencyMatrix[R, 1, 2];
        bndedges = Random`Private`PositionsOf[Total[A, 2], 1];
        interiorfaces = Random`Private`PositionsOf[Total[A[[bndedges]]], 0];

        HighlightMesh[R, Thread[2, interiorfaces]]


        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 7 at 22:46









        Henrik SchumacherHenrik Schumacher

        51.1k469146




        51.1k469146



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Mathematica Stack Exchange!


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

            Use MathJax to format equations. MathJax reference.


            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%2fmathematica.stackexchange.com%2fquestions%2f189008%2fpicking-mesh-elements-that-are-not-on-the-border-of-the-mesh%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

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)