Evenly spaced points on boundary of polygon

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











up vote
10
down vote

favorite
4












I have a polygon and I would like to generate $n$ evenly spaced points along the boundary.







share|improve this question


















  • 3




    Welcome! If you have already tried, please share your attempt with us, and it will be easier for us to help
    – Johu
    Aug 30 at 21:07














up vote
10
down vote

favorite
4












I have a polygon and I would like to generate $n$ evenly spaced points along the boundary.







share|improve this question


















  • 3




    Welcome! If you have already tried, please share your attempt with us, and it will be easier for us to help
    – Johu
    Aug 30 at 21:07












up vote
10
down vote

favorite
4









up vote
10
down vote

favorite
4






4





I have a polygon and I would like to generate $n$ evenly spaced points along the boundary.







share|improve this question














I have a polygon and I would like to generate $n$ evenly spaced points along the boundary.









share|improve this question













share|improve this question




share|improve this question








edited Aug 30 at 21:01









David G. Stork

21.3k11646




21.3k11646










asked Aug 30 at 20:25









SidTheSloth

512




512







  • 3




    Welcome! If you have already tried, please share your attempt with us, and it will be easier for us to help
    – Johu
    Aug 30 at 21:07












  • 3




    Welcome! If you have already tried, please share your attempt with us, and it will be easier for us to help
    – Johu
    Aug 30 at 21:07







3




3




Welcome! If you have already tried, please share your attempt with us, and it will be easier for us to help
– Johu
Aug 30 at 21:07




Welcome! If you have already tried, please share your attempt with us, and it will be easier for us to help
– Johu
Aug 30 at 21:07










5 Answers
5






active

oldest

votes

















up vote
7
down vote













You can use piecewise linear interpolation:



Let's generate a random polygon:



R = ConvexHullMesh[RandomPoint[Disk, 100]]
polygon = Append[#, #[[1]]] &@MeshCoordinates[R][[MeshCells[R, 2][[1, 1]]]];


enter image description here



Creating a piecewise-linear interpolation which is parameterized by arc length.



t = Prepend[Accumulate[Norm /@ Differences[polygon]], 0.];
γ = Interpolation[Transpose[t, polygon],
InterpolationOrder -> 1,
PeriodicInterpolation -> True
];


Sampling it uniformly:



s = Subdivide[γ[[1, 1, 1]], γ[[1, 1, 2]], 100];
newpts = γ[s];


And plotting the generated points:



Show[
R,
ListPlot[newpts]
]


enter image description here






share|improve this answer



























    up vote
    6
    down vote













    If you just want to generate a graphic, then you could use an Arrow with a custom Arrowheads directive. For example, here is a Polygon object:



    poly = Polygon[
    7.361093855790543, 0.2777667989114292, 8.37955832193947, 4.837661706721057,
    8.064449639390588, 8.016729782194783, 3.518023168010062, 8.74578450698846,
    0.8343834304870779, 2.2170380309534554, 4.807772222882807, 0.09815872747936005,
    7.361093855790543, 0.2777667989114292
    ];

    Graphics[RegionBoundary @ poly]


    enter image description here



    Show 10 evenly spaced points:



    Graphics[
    Arrowheads @ Append[
    ConstantArray[
    .1, Automatic, Graphics[PointSize[Large], Point[0,0]],
    10
    ],
    0
    ],
    Arrow @@ RegionBoundary[poly]
    ]


    enter image description here






    share|improve this answer



























      up vote
      5
      down vote













      You can use BSplineFunction and ParametricPlot with ArcLength as option value for the option MeshFunctions:



      SeedRandom[77]
      pts = RandomReal[-1, 1, 7, 2];
      coords = pts[[FindShortestTour[pts][[2]]]];
      n = 10;

      bsF = BSplineFunction[coords, SplineDegree -> 1];
      ParametricPlot[bsF[t], t, 0, 1, Frame -> True, Axes -> False, AspectRatio -> Automatic,
      MeshFunctions -> ArcLength,
      Mesh -> n,
      MeshStyle -> Directive[Red, PointSize[Large]],
      Epilog -> Red, PointSize[Large] , Point@bsF[0]]


      enter image description here






      share|improve this answer





























        up vote
        4
        down vote













        We could also use mesh functions, as Vitaliy showed here:



        plot = ListLinePlot[
        coords,
        Mesh -> 20,
        MeshFunctions -> "ArcLength"
        ];
        pts = Cases[Normal[plot], Point[pt_] :> pt, Infinity];
        pts = Prepend[pts, First[coords]];

        Graphics[
        Line[coords],
        PointSize[Large], Red, Point[pts]
        ]


        Mathematica graphics



        I reused the polygon in Carl's answer.






        share|improve this answer





























          up vote
          0
          down vote













          I think that the broad scheme of doing it would be as follows:




          1. Load the Polytopes package:



            << Polytopes`




          2. Use the vertices command (e.g. assuming that you are working with an octagon):



            a=Vertices[Octagon]



          3. Set up a function which interpolates between two points using a parameter t.


          4. Use the Map command to calculate the interpolated co-ordinates for any given value of t on successive values of your vertices.






          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',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            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%2f180926%2fevenly-spaced-points-on-boundary-of-polygon%23new-answer', 'question_page');

            );

            Post as a guest






























            5 Answers
            5






            active

            oldest

            votes








            5 Answers
            5






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            7
            down vote













            You can use piecewise linear interpolation:



            Let's generate a random polygon:



            R = ConvexHullMesh[RandomPoint[Disk, 100]]
            polygon = Append[#, #[[1]]] &@MeshCoordinates[R][[MeshCells[R, 2][[1, 1]]]];


            enter image description here



            Creating a piecewise-linear interpolation which is parameterized by arc length.



            t = Prepend[Accumulate[Norm /@ Differences[polygon]], 0.];
            γ = Interpolation[Transpose[t, polygon],
            InterpolationOrder -> 1,
            PeriodicInterpolation -> True
            ];


            Sampling it uniformly:



            s = Subdivide[γ[[1, 1, 1]], γ[[1, 1, 2]], 100];
            newpts = γ[s];


            And plotting the generated points:



            Show[
            R,
            ListPlot[newpts]
            ]


            enter image description here






            share|improve this answer
























              up vote
              7
              down vote













              You can use piecewise linear interpolation:



              Let's generate a random polygon:



              R = ConvexHullMesh[RandomPoint[Disk, 100]]
              polygon = Append[#, #[[1]]] &@MeshCoordinates[R][[MeshCells[R, 2][[1, 1]]]];


              enter image description here



              Creating a piecewise-linear interpolation which is parameterized by arc length.



              t = Prepend[Accumulate[Norm /@ Differences[polygon]], 0.];
              γ = Interpolation[Transpose[t, polygon],
              InterpolationOrder -> 1,
              PeriodicInterpolation -> True
              ];


              Sampling it uniformly:



              s = Subdivide[γ[[1, 1, 1]], γ[[1, 1, 2]], 100];
              newpts = γ[s];


              And plotting the generated points:



              Show[
              R,
              ListPlot[newpts]
              ]


              enter image description here






              share|improve this answer






















                up vote
                7
                down vote










                up vote
                7
                down vote









                You can use piecewise linear interpolation:



                Let's generate a random polygon:



                R = ConvexHullMesh[RandomPoint[Disk, 100]]
                polygon = Append[#, #[[1]]] &@MeshCoordinates[R][[MeshCells[R, 2][[1, 1]]]];


                enter image description here



                Creating a piecewise-linear interpolation which is parameterized by arc length.



                t = Prepend[Accumulate[Norm /@ Differences[polygon]], 0.];
                γ = Interpolation[Transpose[t, polygon],
                InterpolationOrder -> 1,
                PeriodicInterpolation -> True
                ];


                Sampling it uniformly:



                s = Subdivide[γ[[1, 1, 1]], γ[[1, 1, 2]], 100];
                newpts = γ[s];


                And plotting the generated points:



                Show[
                R,
                ListPlot[newpts]
                ]


                enter image description here






                share|improve this answer












                You can use piecewise linear interpolation:



                Let's generate a random polygon:



                R = ConvexHullMesh[RandomPoint[Disk, 100]]
                polygon = Append[#, #[[1]]] &@MeshCoordinates[R][[MeshCells[R, 2][[1, 1]]]];


                enter image description here



                Creating a piecewise-linear interpolation which is parameterized by arc length.



                t = Prepend[Accumulate[Norm /@ Differences[polygon]], 0.];
                γ = Interpolation[Transpose[t, polygon],
                InterpolationOrder -> 1,
                PeriodicInterpolation -> True
                ];


                Sampling it uniformly:



                s = Subdivide[γ[[1, 1, 1]], γ[[1, 1, 2]], 100];
                newpts = γ[s];


                And plotting the generated points:



                Show[
                R,
                ListPlot[newpts]
                ]


                enter image description here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 30 at 21:07









                Henrik Schumacher

                36.8k249103




                36.8k249103




















                    up vote
                    6
                    down vote













                    If you just want to generate a graphic, then you could use an Arrow with a custom Arrowheads directive. For example, here is a Polygon object:



                    poly = Polygon[
                    7.361093855790543, 0.2777667989114292, 8.37955832193947, 4.837661706721057,
                    8.064449639390588, 8.016729782194783, 3.518023168010062, 8.74578450698846,
                    0.8343834304870779, 2.2170380309534554, 4.807772222882807, 0.09815872747936005,
                    7.361093855790543, 0.2777667989114292
                    ];

                    Graphics[RegionBoundary @ poly]


                    enter image description here



                    Show 10 evenly spaced points:



                    Graphics[
                    Arrowheads @ Append[
                    ConstantArray[
                    .1, Automatic, Graphics[PointSize[Large], Point[0,0]],
                    10
                    ],
                    0
                    ],
                    Arrow @@ RegionBoundary[poly]
                    ]


                    enter image description here






                    share|improve this answer
























                      up vote
                      6
                      down vote













                      If you just want to generate a graphic, then you could use an Arrow with a custom Arrowheads directive. For example, here is a Polygon object:



                      poly = Polygon[
                      7.361093855790543, 0.2777667989114292, 8.37955832193947, 4.837661706721057,
                      8.064449639390588, 8.016729782194783, 3.518023168010062, 8.74578450698846,
                      0.8343834304870779, 2.2170380309534554, 4.807772222882807, 0.09815872747936005,
                      7.361093855790543, 0.2777667989114292
                      ];

                      Graphics[RegionBoundary @ poly]


                      enter image description here



                      Show 10 evenly spaced points:



                      Graphics[
                      Arrowheads @ Append[
                      ConstantArray[
                      .1, Automatic, Graphics[PointSize[Large], Point[0,0]],
                      10
                      ],
                      0
                      ],
                      Arrow @@ RegionBoundary[poly]
                      ]


                      enter image description here






                      share|improve this answer






















                        up vote
                        6
                        down vote










                        up vote
                        6
                        down vote









                        If you just want to generate a graphic, then you could use an Arrow with a custom Arrowheads directive. For example, here is a Polygon object:



                        poly = Polygon[
                        7.361093855790543, 0.2777667989114292, 8.37955832193947, 4.837661706721057,
                        8.064449639390588, 8.016729782194783, 3.518023168010062, 8.74578450698846,
                        0.8343834304870779, 2.2170380309534554, 4.807772222882807, 0.09815872747936005,
                        7.361093855790543, 0.2777667989114292
                        ];

                        Graphics[RegionBoundary @ poly]


                        enter image description here



                        Show 10 evenly spaced points:



                        Graphics[
                        Arrowheads @ Append[
                        ConstantArray[
                        .1, Automatic, Graphics[PointSize[Large], Point[0,0]],
                        10
                        ],
                        0
                        ],
                        Arrow @@ RegionBoundary[poly]
                        ]


                        enter image description here






                        share|improve this answer












                        If you just want to generate a graphic, then you could use an Arrow with a custom Arrowheads directive. For example, here is a Polygon object:



                        poly = Polygon[
                        7.361093855790543, 0.2777667989114292, 8.37955832193947, 4.837661706721057,
                        8.064449639390588, 8.016729782194783, 3.518023168010062, 8.74578450698846,
                        0.8343834304870779, 2.2170380309534554, 4.807772222882807, 0.09815872747936005,
                        7.361093855790543, 0.2777667989114292
                        ];

                        Graphics[RegionBoundary @ poly]


                        enter image description here



                        Show 10 evenly spaced points:



                        Graphics[
                        Arrowheads @ Append[
                        ConstantArray[
                        .1, Automatic, Graphics[PointSize[Large], Point[0,0]],
                        10
                        ],
                        0
                        ],
                        Arrow @@ RegionBoundary[poly]
                        ]


                        enter image description here







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Aug 30 at 20:52









                        Carl Woll

                        56k272146




                        56k272146




















                            up vote
                            5
                            down vote













                            You can use BSplineFunction and ParametricPlot with ArcLength as option value for the option MeshFunctions:



                            SeedRandom[77]
                            pts = RandomReal[-1, 1, 7, 2];
                            coords = pts[[FindShortestTour[pts][[2]]]];
                            n = 10;

                            bsF = BSplineFunction[coords, SplineDegree -> 1];
                            ParametricPlot[bsF[t], t, 0, 1, Frame -> True, Axes -> False, AspectRatio -> Automatic,
                            MeshFunctions -> ArcLength,
                            Mesh -> n,
                            MeshStyle -> Directive[Red, PointSize[Large]],
                            Epilog -> Red, PointSize[Large] , Point@bsF[0]]


                            enter image description here






                            share|improve this answer


























                              up vote
                              5
                              down vote













                              You can use BSplineFunction and ParametricPlot with ArcLength as option value for the option MeshFunctions:



                              SeedRandom[77]
                              pts = RandomReal[-1, 1, 7, 2];
                              coords = pts[[FindShortestTour[pts][[2]]]];
                              n = 10;

                              bsF = BSplineFunction[coords, SplineDegree -> 1];
                              ParametricPlot[bsF[t], t, 0, 1, Frame -> True, Axes -> False, AspectRatio -> Automatic,
                              MeshFunctions -> ArcLength,
                              Mesh -> n,
                              MeshStyle -> Directive[Red, PointSize[Large]],
                              Epilog -> Red, PointSize[Large] , Point@bsF[0]]


                              enter image description here






                              share|improve this answer
























                                up vote
                                5
                                down vote










                                up vote
                                5
                                down vote









                                You can use BSplineFunction and ParametricPlot with ArcLength as option value for the option MeshFunctions:



                                SeedRandom[77]
                                pts = RandomReal[-1, 1, 7, 2];
                                coords = pts[[FindShortestTour[pts][[2]]]];
                                n = 10;

                                bsF = BSplineFunction[coords, SplineDegree -> 1];
                                ParametricPlot[bsF[t], t, 0, 1, Frame -> True, Axes -> False, AspectRatio -> Automatic,
                                MeshFunctions -> ArcLength,
                                Mesh -> n,
                                MeshStyle -> Directive[Red, PointSize[Large]],
                                Epilog -> Red, PointSize[Large] , Point@bsF[0]]


                                enter image description here






                                share|improve this answer














                                You can use BSplineFunction and ParametricPlot with ArcLength as option value for the option MeshFunctions:



                                SeedRandom[77]
                                pts = RandomReal[-1, 1, 7, 2];
                                coords = pts[[FindShortestTour[pts][[2]]]];
                                n = 10;

                                bsF = BSplineFunction[coords, SplineDegree -> 1];
                                ParametricPlot[bsF[t], t, 0, 1, Frame -> True, Axes -> False, AspectRatio -> Automatic,
                                MeshFunctions -> ArcLength,
                                Mesh -> n,
                                MeshStyle -> Directive[Red, PointSize[Large]],
                                Epilog -> Red, PointSize[Large] , Point@bsF[0]]


                                enter image description here







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Aug 30 at 21:17

























                                answered Aug 30 at 21:12









                                kglr

                                159k8183382




                                159k8183382




















                                    up vote
                                    4
                                    down vote













                                    We could also use mesh functions, as Vitaliy showed here:



                                    plot = ListLinePlot[
                                    coords,
                                    Mesh -> 20,
                                    MeshFunctions -> "ArcLength"
                                    ];
                                    pts = Cases[Normal[plot], Point[pt_] :> pt, Infinity];
                                    pts = Prepend[pts, First[coords]];

                                    Graphics[
                                    Line[coords],
                                    PointSize[Large], Red, Point[pts]
                                    ]


                                    Mathematica graphics



                                    I reused the polygon in Carl's answer.






                                    share|improve this answer


























                                      up vote
                                      4
                                      down vote













                                      We could also use mesh functions, as Vitaliy showed here:



                                      plot = ListLinePlot[
                                      coords,
                                      Mesh -> 20,
                                      MeshFunctions -> "ArcLength"
                                      ];
                                      pts = Cases[Normal[plot], Point[pt_] :> pt, Infinity];
                                      pts = Prepend[pts, First[coords]];

                                      Graphics[
                                      Line[coords],
                                      PointSize[Large], Red, Point[pts]
                                      ]


                                      Mathematica graphics



                                      I reused the polygon in Carl's answer.






                                      share|improve this answer
























                                        up vote
                                        4
                                        down vote










                                        up vote
                                        4
                                        down vote









                                        We could also use mesh functions, as Vitaliy showed here:



                                        plot = ListLinePlot[
                                        coords,
                                        Mesh -> 20,
                                        MeshFunctions -> "ArcLength"
                                        ];
                                        pts = Cases[Normal[plot], Point[pt_] :> pt, Infinity];
                                        pts = Prepend[pts, First[coords]];

                                        Graphics[
                                        Line[coords],
                                        PointSize[Large], Red, Point[pts]
                                        ]


                                        Mathematica graphics



                                        I reused the polygon in Carl's answer.






                                        share|improve this answer














                                        We could also use mesh functions, as Vitaliy showed here:



                                        plot = ListLinePlot[
                                        coords,
                                        Mesh -> 20,
                                        MeshFunctions -> "ArcLength"
                                        ];
                                        pts = Cases[Normal[plot], Point[pt_] :> pt, Infinity];
                                        pts = Prepend[pts, First[coords]];

                                        Graphics[
                                        Line[coords],
                                        PointSize[Large], Red, Point[pts]
                                        ]


                                        Mathematica graphics



                                        I reused the polygon in Carl's answer.







                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Aug 30 at 22:47

























                                        answered Aug 30 at 22:29









                                        C. E.

                                        47.6k390192




                                        47.6k390192




















                                            up vote
                                            0
                                            down vote













                                            I think that the broad scheme of doing it would be as follows:




                                            1. Load the Polytopes package:



                                              << Polytopes`




                                            2. Use the vertices command (e.g. assuming that you are working with an octagon):



                                              a=Vertices[Octagon]



                                            3. Set up a function which interpolates between two points using a parameter t.


                                            4. Use the Map command to calculate the interpolated co-ordinates for any given value of t on successive values of your vertices.






                                            share|improve this answer
























                                              up vote
                                              0
                                              down vote













                                              I think that the broad scheme of doing it would be as follows:




                                              1. Load the Polytopes package:



                                                << Polytopes`




                                              2. Use the vertices command (e.g. assuming that you are working with an octagon):



                                                a=Vertices[Octagon]



                                              3. Set up a function which interpolates between two points using a parameter t.


                                              4. Use the Map command to calculate the interpolated co-ordinates for any given value of t on successive values of your vertices.






                                              share|improve this answer






















                                                up vote
                                                0
                                                down vote










                                                up vote
                                                0
                                                down vote









                                                I think that the broad scheme of doing it would be as follows:




                                                1. Load the Polytopes package:



                                                  << Polytopes`




                                                2. Use the vertices command (e.g. assuming that you are working with an octagon):



                                                  a=Vertices[Octagon]



                                                3. Set up a function which interpolates between two points using a parameter t.


                                                4. Use the Map command to calculate the interpolated co-ordinates for any given value of t on successive values of your vertices.






                                                share|improve this answer












                                                I think that the broad scheme of doing it would be as follows:




                                                1. Load the Polytopes package:



                                                  << Polytopes`




                                                2. Use the vertices command (e.g. assuming that you are working with an octagon):



                                                  a=Vertices[Octagon]



                                                3. Set up a function which interpolates between two points using a parameter t.


                                                4. Use the Map command to calculate the interpolated co-ordinates for any given value of t on successive values of your vertices.







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Aug 30 at 20:45









                                                GerardF123

                                                764




                                                764



























                                                     

                                                    draft saved


                                                    draft discarded















































                                                     


                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function ()
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f180926%2fevenly-spaced-points-on-boundary-of-polygon%23new-answer', 'question_page');

                                                    );

                                                    Post as a guest













































































                                                    Comments

                                                    Popular posts from this blog

                                                    What does second last employer means? [closed]

                                                    List of Gilmore Girls characters

                                                    Confectionery