How to generate a triangular grid from a list of points?Point lattice leading to triangle latticeCombining 3 graphics of different coordinate systemsCreate triangular mesh from random list of pointsInterpolation on a regular square grid spanning a triangular domainHow to generate grid points on boundary of $[-1,1]^d$ for arbitrary dimension $d$ and specified resolution?How to generate the rows of data points from a model?How to apply $overliner(x,y)$ to shapes with straight lines or absolute values?How to make a cow smaller (in BubbleChart3D plot)How to plot a 2D triangular latticeHow to generate animation from manipulate?Point lattice leading to triangle lattice

Why do Russians call their women expensive ("дорогая")?

Different PCB color ( is it different material? )

Can you move on your turn, and then use the Ready Action to move again on another creature's turn?

If Sweden was to magically float away, at what altitude would it be visible from the southern hemisphere?

Do creatures all have the same statistics upon being reanimated via the Animate Dead spell?

Points within polygons in different projections

Is there an evolutionary advantage to having two heads?

Can a wire having a 610-670 THz (frequency of blue light) AC frequency supply, generate blue light?

My player wants to cast multiple charges of magic missile from a wand

The qvolume of an integer

Can a non-EU citizen travel within the Schengen area without identity documents?

Creating Fictional Slavic Place Names

Biblical Basis for 400 years of silence between old and new testament

Intuition behind eigenvalues of an adjacency matrix

How to prevent bad sectors?

Is having a hidden directory under /etc safe?

If a problem only occurs randomly once in every N times on average, how many tests do I have to perform to be certain that it's now fixed?

How did early x86 BIOS programmers manage to program full blown TUIs given very few bytes of ROM/EPROM?

How was Apollo supposed to rendezvous in the case of a lunar abort?

Tic-Tac-Toe for the terminal

Adding strings in lists together

What does the behaviour of water on the skin of an aircraft in flight tell us?

Uncommanded roll at high speed

Thousands and thousands of words



How to generate a triangular grid from a list of points?


Point lattice leading to triangle latticeCombining 3 graphics of different coordinate systemsCreate triangular mesh from random list of pointsInterpolation on a regular square grid spanning a triangular domainHow to generate grid points on boundary of $[-1,1]^d$ for arbitrary dimension $d$ and specified resolution?How to generate the rows of data points from a model?How to apply $overliner(x,y)$ to shapes with straight lines or absolute values?How to make a cow smaller (in BubbleChart3D plot)How to plot a 2D triangular latticeHow to generate animation from manipulate?Point lattice leading to triangle lattice













7












$begingroup$


I am newbie with mathematica and the other day I saw a function that generates points from an original one defined as:



h[x_, y_, 0] := Prepend[Table[Cos[2 Pi k/6] + x, Sin[2 Pi k/6] + y, k,6], 0, 0]

h[x_, y_, n_] :=DeleteDuplicates[Flatten[Table[Cos[2 Pi k/6] + #1, Sin[2 Pi k/6] + #2, k, 6] & @@@h[x, y, n - 1], 1]]


So I started from this function and tried to create a triangle lattice with a new function definied as:



L[x_, y_, n_] :=Show@Graphics@While[j < Length[h[x, y, n] + 1], 
For[i = 1, i < Length[h[x, y, n] + 1] , i++ ,
If[EuclideanDistance[h[x, y, n][[j]], h[x, y, n][[i]]] == 1,
Line[h[x, y, n][[j]], h[x, y, n][[i]]],
Point[h[x, y, n][[j]], h[x, y, n][[i]]]]]; j++]


But it doesn't work... I wanted to connect all the dots that were seperated by a distance of 1 and plot a graphic with them. It seems that i am not using for as it should properly be.










share|improve this question











$endgroup$











  • $begingroup$
    I've edited your question to include a link to what you saw the other day. In the future, make sure to do this so that you can give questions and answerers their proper credit! In addition, once you have enough rep (which I think you do), make sure to upvote questions and/or answers that you found useful (which includes the now-linked ones, I assume, since you asked a question about it!).
    $endgroup$
    – march
    May 15 at 23:33















7












$begingroup$


I am newbie with mathematica and the other day I saw a function that generates points from an original one defined as:



h[x_, y_, 0] := Prepend[Table[Cos[2 Pi k/6] + x, Sin[2 Pi k/6] + y, k,6], 0, 0]

h[x_, y_, n_] :=DeleteDuplicates[Flatten[Table[Cos[2 Pi k/6] + #1, Sin[2 Pi k/6] + #2, k, 6] & @@@h[x, y, n - 1], 1]]


So I started from this function and tried to create a triangle lattice with a new function definied as:



L[x_, y_, n_] :=Show@Graphics@While[j < Length[h[x, y, n] + 1], 
For[i = 1, i < Length[h[x, y, n] + 1] , i++ ,
If[EuclideanDistance[h[x, y, n][[j]], h[x, y, n][[i]]] == 1,
Line[h[x, y, n][[j]], h[x, y, n][[i]]],
Point[h[x, y, n][[j]], h[x, y, n][[i]]]]]; j++]


But it doesn't work... I wanted to connect all the dots that were seperated by a distance of 1 and plot a graphic with them. It seems that i am not using for as it should properly be.










share|improve this question











$endgroup$











  • $begingroup$
    I've edited your question to include a link to what you saw the other day. In the future, make sure to do this so that you can give questions and answerers their proper credit! In addition, once you have enough rep (which I think you do), make sure to upvote questions and/or answers that you found useful (which includes the now-linked ones, I assume, since you asked a question about it!).
    $endgroup$
    – march
    May 15 at 23:33













7












7








7





$begingroup$


I am newbie with mathematica and the other day I saw a function that generates points from an original one defined as:



h[x_, y_, 0] := Prepend[Table[Cos[2 Pi k/6] + x, Sin[2 Pi k/6] + y, k,6], 0, 0]

h[x_, y_, n_] :=DeleteDuplicates[Flatten[Table[Cos[2 Pi k/6] + #1, Sin[2 Pi k/6] + #2, k, 6] & @@@h[x, y, n - 1], 1]]


So I started from this function and tried to create a triangle lattice with a new function definied as:



L[x_, y_, n_] :=Show@Graphics@While[j < Length[h[x, y, n] + 1], 
For[i = 1, i < Length[h[x, y, n] + 1] , i++ ,
If[EuclideanDistance[h[x, y, n][[j]], h[x, y, n][[i]]] == 1,
Line[h[x, y, n][[j]], h[x, y, n][[i]]],
Point[h[x, y, n][[j]], h[x, y, n][[i]]]]]; j++]


But it doesn't work... I wanted to connect all the dots that were seperated by a distance of 1 and plot a graphic with them. It seems that i am not using for as it should properly be.










share|improve this question











$endgroup$




I am newbie with mathematica and the other day I saw a function that generates points from an original one defined as:



h[x_, y_, 0] := Prepend[Table[Cos[2 Pi k/6] + x, Sin[2 Pi k/6] + y, k,6], 0, 0]

h[x_, y_, n_] :=DeleteDuplicates[Flatten[Table[Cos[2 Pi k/6] + #1, Sin[2 Pi k/6] + #2, k, 6] & @@@h[x, y, n - 1], 1]]


So I started from this function and tried to create a triangle lattice with a new function definied as:



L[x_, y_, n_] :=Show@Graphics@While[j < Length[h[x, y, n] + 1], 
For[i = 1, i < Length[h[x, y, n] + 1] , i++ ,
If[EuclideanDistance[h[x, y, n][[j]], h[x, y, n][[i]]] == 1,
Line[h[x, y, n][[j]], h[x, y, n][[i]]],
Point[h[x, y, n][[j]], h[x, y, n][[i]]]]]; j++]


But it doesn't work... I wanted to connect all the dots that were seperated by a distance of 1 and plot a graphic with them. It seems that i am not using for as it should properly be.







graphics lattices






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 16 at 6:38









user64494

3,90211323




3,90211323










asked May 15 at 19:58









LilGregLilGreg

362




362











  • $begingroup$
    I've edited your question to include a link to what you saw the other day. In the future, make sure to do this so that you can give questions and answerers their proper credit! In addition, once you have enough rep (which I think you do), make sure to upvote questions and/or answers that you found useful (which includes the now-linked ones, I assume, since you asked a question about it!).
    $endgroup$
    – march
    May 15 at 23:33
















  • $begingroup$
    I've edited your question to include a link to what you saw the other day. In the future, make sure to do this so that you can give questions and answerers their proper credit! In addition, once you have enough rep (which I think you do), make sure to upvote questions and/or answers that you found useful (which includes the now-linked ones, I assume, since you asked a question about it!).
    $endgroup$
    – march
    May 15 at 23:33















$begingroup$
I've edited your question to include a link to what you saw the other day. In the future, make sure to do this so that you can give questions and answerers their proper credit! In addition, once you have enough rep (which I think you do), make sure to upvote questions and/or answers that you found useful (which includes the now-linked ones, I assume, since you asked a question about it!).
$endgroup$
– march
May 15 at 23:33




$begingroup$
I've edited your question to include a link to what you saw the other day. In the future, make sure to do this so that you can give questions and answerers their proper credit! In addition, once you have enough rep (which I think you do), make sure to upvote questions and/or answers that you found useful (which includes the now-linked ones, I assume, since you asked a question about it!).
$endgroup$
– march
May 15 at 23:33










4 Answers
4






active

oldest

votes


















7












$begingroup$

Try this:



R = DelaunayMesh[h[0, 0, 2]]


enter image description here



You may grab the edge indices with



MeshCells[R, 1]





share|improve this answer









$endgroup$




















    6












    $begingroup$

    You can use NearestNeighborGraph as follows:



    Line[##] & @@@ EdgeList@NearestNeighborGraph[h[0, 0, 1]] // Graphics


    enter image description here






    share|improve this answer









    $endgroup$




















      6












      $begingroup$

      Your code wasn't far off, though the other answers may be more elegant.



      This works:



      L2[x_, y_, n_] := Module[pts,
      pts = h[x, y, n];
      Show[Graphics[
      Point[pts],
      Table[
      If[EuclideanDistance[pts[[i]], pts[[j]]] == 1,
      Line[pts[[i]], pts[[j]]]], i, Length[pts], j, Length[pts]]
      ]]]

      L2[0, 0, 2]


      enter image description here






      share|improve this answer









      $endgroup$




















        5












        $begingroup$

        Another way to use NearestNeighborGraph:



        NearestNeighborGraph[h[0, 0, 1], VertexCoordinates -> h[0, 0, 1]]


        enter image description here



        Alternatively, you can use RelationGraph:



        RelationGraph[.1 < EuclideanDistance@## <= 1 &, h[0, 0, 1], VertexCoordinates -> h[0, 0, 1]]



        same picture




        To remove the vertices and to get a Graphics object you can use:



        Show @ NearestNeighborGraph[h[0, 0, 1], VertexCoordinates -> h[0, 0, 1], 
        VertexShapeFunction -> None]


        enter image description here






        share|improve this answer











        $endgroup$












        • $begingroup$
          Thank you for your help! I didn't know there was a function, I appreciate your help.
          $endgroup$
          – LilGreg
          May 16 at 17:48











        Your Answer








        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%2f198425%2fhow-to-generate-a-triangular-grid-from-a-list-of-points%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        7












        $begingroup$

        Try this:



        R = DelaunayMesh[h[0, 0, 2]]


        enter image description here



        You may grab the edge indices with



        MeshCells[R, 1]





        share|improve this answer









        $endgroup$

















          7












          $begingroup$

          Try this:



          R = DelaunayMesh[h[0, 0, 2]]


          enter image description here



          You may grab the edge indices with



          MeshCells[R, 1]





          share|improve this answer









          $endgroup$















            7












            7








            7





            $begingroup$

            Try this:



            R = DelaunayMesh[h[0, 0, 2]]


            enter image description here



            You may grab the edge indices with



            MeshCells[R, 1]





            share|improve this answer









            $endgroup$



            Try this:



            R = DelaunayMesh[h[0, 0, 2]]


            enter image description here



            You may grab the edge indices with



            MeshCells[R, 1]






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 15 at 20:02









            Henrik SchumacherHenrik Schumacher

            63.2k587176




            63.2k587176





















                6












                $begingroup$

                You can use NearestNeighborGraph as follows:



                Line[##] & @@@ EdgeList@NearestNeighborGraph[h[0, 0, 1]] // Graphics


                enter image description here






                share|improve this answer









                $endgroup$

















                  6












                  $begingroup$

                  You can use NearestNeighborGraph as follows:



                  Line[##] & @@@ EdgeList@NearestNeighborGraph[h[0, 0, 1]] // Graphics


                  enter image description here






                  share|improve this answer









                  $endgroup$















                    6












                    6








                    6





                    $begingroup$

                    You can use NearestNeighborGraph as follows:



                    Line[##] & @@@ EdgeList@NearestNeighborGraph[h[0, 0, 1]] // Graphics


                    enter image description here






                    share|improve this answer









                    $endgroup$



                    You can use NearestNeighborGraph as follows:



                    Line[##] & @@@ EdgeList@NearestNeighborGraph[h[0, 0, 1]] // Graphics


                    enter image description here







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered May 15 at 23:19









                    marchmarch

                    17.8k22970




                    17.8k22970





















                        6












                        $begingroup$

                        Your code wasn't far off, though the other answers may be more elegant.



                        This works:



                        L2[x_, y_, n_] := Module[pts,
                        pts = h[x, y, n];
                        Show[Graphics[
                        Point[pts],
                        Table[
                        If[EuclideanDistance[pts[[i]], pts[[j]]] == 1,
                        Line[pts[[i]], pts[[j]]]], i, Length[pts], j, Length[pts]]
                        ]]]

                        L2[0, 0, 2]


                        enter image description here






                        share|improve this answer









                        $endgroup$

















                          6












                          $begingroup$

                          Your code wasn't far off, though the other answers may be more elegant.



                          This works:



                          L2[x_, y_, n_] := Module[pts,
                          pts = h[x, y, n];
                          Show[Graphics[
                          Point[pts],
                          Table[
                          If[EuclideanDistance[pts[[i]], pts[[j]]] == 1,
                          Line[pts[[i]], pts[[j]]]], i, Length[pts], j, Length[pts]]
                          ]]]

                          L2[0, 0, 2]


                          enter image description here






                          share|improve this answer









                          $endgroup$















                            6












                            6








                            6





                            $begingroup$

                            Your code wasn't far off, though the other answers may be more elegant.



                            This works:



                            L2[x_, y_, n_] := Module[pts,
                            pts = h[x, y, n];
                            Show[Graphics[
                            Point[pts],
                            Table[
                            If[EuclideanDistance[pts[[i]], pts[[j]]] == 1,
                            Line[pts[[i]], pts[[j]]]], i, Length[pts], j, Length[pts]]
                            ]]]

                            L2[0, 0, 2]


                            enter image description here






                            share|improve this answer









                            $endgroup$



                            Your code wasn't far off, though the other answers may be more elegant.



                            This works:



                            L2[x_, y_, n_] := Module[pts,
                            pts = h[x, y, n];
                            Show[Graphics[
                            Point[pts],
                            Table[
                            If[EuclideanDistance[pts[[i]], pts[[j]]] == 1,
                            Line[pts[[i]], pts[[j]]]], i, Length[pts], j, Length[pts]]
                            ]]]

                            L2[0, 0, 2]


                            enter image description here







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered May 16 at 0:47









                            MelaGoMelaGo

                            1,53717




                            1,53717





















                                5












                                $begingroup$

                                Another way to use NearestNeighborGraph:



                                NearestNeighborGraph[h[0, 0, 1], VertexCoordinates -> h[0, 0, 1]]


                                enter image description here



                                Alternatively, you can use RelationGraph:



                                RelationGraph[.1 < EuclideanDistance@## <= 1 &, h[0, 0, 1], VertexCoordinates -> h[0, 0, 1]]



                                same picture




                                To remove the vertices and to get a Graphics object you can use:



                                Show @ NearestNeighborGraph[h[0, 0, 1], VertexCoordinates -> h[0, 0, 1], 
                                VertexShapeFunction -> None]


                                enter image description here






                                share|improve this answer











                                $endgroup$












                                • $begingroup$
                                  Thank you for your help! I didn't know there was a function, I appreciate your help.
                                  $endgroup$
                                  – LilGreg
                                  May 16 at 17:48















                                5












                                $begingroup$

                                Another way to use NearestNeighborGraph:



                                NearestNeighborGraph[h[0, 0, 1], VertexCoordinates -> h[0, 0, 1]]


                                enter image description here



                                Alternatively, you can use RelationGraph:



                                RelationGraph[.1 < EuclideanDistance@## <= 1 &, h[0, 0, 1], VertexCoordinates -> h[0, 0, 1]]



                                same picture




                                To remove the vertices and to get a Graphics object you can use:



                                Show @ NearestNeighborGraph[h[0, 0, 1], VertexCoordinates -> h[0, 0, 1], 
                                VertexShapeFunction -> None]


                                enter image description here






                                share|improve this answer











                                $endgroup$












                                • $begingroup$
                                  Thank you for your help! I didn't know there was a function, I appreciate your help.
                                  $endgroup$
                                  – LilGreg
                                  May 16 at 17:48













                                5












                                5








                                5





                                $begingroup$

                                Another way to use NearestNeighborGraph:



                                NearestNeighborGraph[h[0, 0, 1], VertexCoordinates -> h[0, 0, 1]]


                                enter image description here



                                Alternatively, you can use RelationGraph:



                                RelationGraph[.1 < EuclideanDistance@## <= 1 &, h[0, 0, 1], VertexCoordinates -> h[0, 0, 1]]



                                same picture




                                To remove the vertices and to get a Graphics object you can use:



                                Show @ NearestNeighborGraph[h[0, 0, 1], VertexCoordinates -> h[0, 0, 1], 
                                VertexShapeFunction -> None]


                                enter image description here






                                share|improve this answer











                                $endgroup$



                                Another way to use NearestNeighborGraph:



                                NearestNeighborGraph[h[0, 0, 1], VertexCoordinates -> h[0, 0, 1]]


                                enter image description here



                                Alternatively, you can use RelationGraph:



                                RelationGraph[.1 < EuclideanDistance@## <= 1 &, h[0, 0, 1], VertexCoordinates -> h[0, 0, 1]]



                                same picture




                                To remove the vertices and to get a Graphics object you can use:



                                Show @ NearestNeighborGraph[h[0, 0, 1], VertexCoordinates -> h[0, 0, 1], 
                                VertexShapeFunction -> None]


                                enter image description here







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited May 16 at 7:14

























                                answered May 16 at 7:08









                                kglrkglr

                                195k10216438




                                195k10216438











                                • $begingroup$
                                  Thank you for your help! I didn't know there was a function, I appreciate your help.
                                  $endgroup$
                                  – LilGreg
                                  May 16 at 17:48
















                                • $begingroup$
                                  Thank you for your help! I didn't know there was a function, I appreciate your help.
                                  $endgroup$
                                  – LilGreg
                                  May 16 at 17:48















                                $begingroup$
                                Thank you for your help! I didn't know there was a function, I appreciate your help.
                                $endgroup$
                                – LilGreg
                                May 16 at 17:48




                                $begingroup$
                                Thank you for your help! I didn't know there was a function, I appreciate your help.
                                $endgroup$
                                – LilGreg
                                May 16 at 17:48

















                                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%2f198425%2fhow-to-generate-a-triangular-grid-from-a-list-of-points%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

                                Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

                                Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

                                What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company