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












9














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






















  • RegionBoundary? To get coordinates you can do RegionBoundary@mesh // MeshCoordinates
    – b3m2a1
    yesterday












  • @b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
    – Aaron Stevens
    yesterday










  • 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.
    – b3m2a1
    yesterday
















9














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






















  • RegionBoundary? To get coordinates you can do RegionBoundary@mesh // MeshCoordinates
    – b3m2a1
    yesterday












  • @b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
    – Aaron Stevens
    yesterday










  • 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.
    – b3m2a1
    yesterday














9












9








9







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













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 yesterday









Aaron StevensAaron Stevens

319110




319110












  • RegionBoundary? To get coordinates you can do RegionBoundary@mesh // MeshCoordinates
    – b3m2a1
    yesterday












  • @b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
    – Aaron Stevens
    yesterday










  • 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.
    – b3m2a1
    yesterday


















  • RegionBoundary? To get coordinates you can do RegionBoundary@mesh // MeshCoordinates
    – b3m2a1
    yesterday












  • @b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
    – Aaron Stevens
    yesterday










  • 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.
    – b3m2a1
    yesterday
















RegionBoundary? To get coordinates you can do RegionBoundary@mesh // MeshCoordinates
– b3m2a1
yesterday






RegionBoundary? To get coordinates you can do RegionBoundary@mesh // MeshCoordinates
– b3m2a1
yesterday














@b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
– Aaron Stevens
yesterday




@b3m2a1 I mean to find the "shapes" that are not touching the outside. I don't need the coordinates of the outer edge.
– Aaron Stevens
yesterday












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.
– b3m2a1
yesterday




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.
– b3m2a1
yesterday










2 Answers
2






active

oldest

votes


















8














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























  • Yep that was the simple answer I was expecting haha. Thanks!
    – Aaron Stevens
    yesterday






  • 2




    @kglr Wow, I'm impressed. Where did you find this syntax? The doc page of MeshCellIndex does not show it as example...
    – Henrik Schumacher
    yesterday






  • 1




    @HenrikSchumacher, blind search trying some objects returned by vm["Properties"]:)
    – kglr
    yesterday










  • @HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
    – Aaron Stevens
    yesterday



















7














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





















    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









    8














    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























    • Yep that was the simple answer I was expecting haha. Thanks!
      – Aaron Stevens
      yesterday






    • 2




      @kglr Wow, I'm impressed. Where did you find this syntax? The doc page of MeshCellIndex does not show it as example...
      – Henrik Schumacher
      yesterday






    • 1




      @HenrikSchumacher, blind search trying some objects returned by vm["Properties"]:)
      – kglr
      yesterday










    • @HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
      – Aaron Stevens
      yesterday
















    8














    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























    • Yep that was the simple answer I was expecting haha. Thanks!
      – Aaron Stevens
      yesterday






    • 2




      @kglr Wow, I'm impressed. Where did you find this syntax? The doc page of MeshCellIndex does not show it as example...
      – Henrik Schumacher
      yesterday






    • 1




      @HenrikSchumacher, blind search trying some objects returned by vm["Properties"]:)
      – kglr
      yesterday










    • @HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
      – Aaron Stevens
      yesterday














    8












    8








    8






    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














    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 yesterday

























    answered yesterday









    kglrkglr

    178k9198409




    178k9198409












    • Yep that was the simple answer I was expecting haha. Thanks!
      – Aaron Stevens
      yesterday






    • 2




      @kglr Wow, I'm impressed. Where did you find this syntax? The doc page of MeshCellIndex does not show it as example...
      – Henrik Schumacher
      yesterday






    • 1




      @HenrikSchumacher, blind search trying some objects returned by vm["Properties"]:)
      – kglr
      yesterday










    • @HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
      – Aaron Stevens
      yesterday


















    • Yep that was the simple answer I was expecting haha. Thanks!
      – Aaron Stevens
      yesterday






    • 2




      @kglr Wow, I'm impressed. Where did you find this syntax? The doc page of MeshCellIndex does not show it as example...
      – Henrik Schumacher
      yesterday






    • 1




      @HenrikSchumacher, blind search trying some objects returned by vm["Properties"]:)
      – kglr
      yesterday










    • @HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
      – Aaron Stevens
      yesterday
















    Yep that was the simple answer I was expecting haha. Thanks!
    – Aaron Stevens
    yesterday




    Yep that was the simple answer I was expecting haha. Thanks!
    – Aaron Stevens
    yesterday




    2




    2




    @kglr Wow, I'm impressed. Where did you find this syntax? The doc page of MeshCellIndex does not show it as example...
    – Henrik Schumacher
    yesterday




    @kglr Wow, I'm impressed. Where did you find this syntax? The doc page of MeshCellIndex does not show it as example...
    – Henrik Schumacher
    yesterday




    1




    1




    @HenrikSchumacher, blind search trying some objects returned by vm["Properties"]:)
    – kglr
    yesterday




    @HenrikSchumacher, blind search trying some objects returned by vm["Properties"]:)
    – kglr
    yesterday












    @HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
    – Aaron Stevens
    yesterday




    @HenrikSchumacher Exactly what I was thinking! I'll definitely look at those properties though and see if there are other useful things.
    – Aaron Stevens
    yesterday











    7














    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


























      7














      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
























        7












        7








        7






        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












        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 yesterday









        Henrik SchumacherHenrik Schumacher

        49.8k469143




        49.8k469143






























            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.





            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%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

            An IMO inspired problem

            Management

            Has there ever been an instance of an active nuclear power plant within or near a war zone?