Results 1 to 8 of 8

Thread: Plotting regularly spaced points around the perimeter of a regular polygon

  1. #1
    Newbie
    Joined
    Sep 2017
    From
    Australia
    Posts
    4

    Plotting regularly spaced points around the perimeter of a regular polygon

    Hi,
    I'm writing a little computer program in which 60 small objects arrange themselves into various regular polygon shapes. I've got them to make a square and a triangle (and a circle), but I want to find a simple way to find the x and y coordinates of a given number of points along each side of any regular polygon (the given number will be 60 divided by the number of sides the polygon has). I'm feeling like there should be an easy way to do this, but I don't know what it is. Any help would be much appreciated.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor

    Joined
    Apr 2005
    Posts
    19,455
    Thanks
    2892

    Re: Plotting regularly spaced points around the perimeter of a regular polygon

    To put n objects equally spaced around a circle they must lie on lines that make angles of \frac{2\pi}{n}i radians, where i goes from 1 to n, with the center of the circle. In particular, to lie equally spaced around the unit circle, with radius 1 and the origin as center, the points are \left(cos\left(\frac{2\pi}{n}i\right), sin\left(\frac{2\pi}{n}i\right)\right).

    For a circle with radius R rather than 1, just multiply each component by R: \left(Rcos\left(\frac{2\pi}{n}i\right), Rsin\left(\frac{2\pi}{n}i\right)\right).

    For a circle with center at (x_0, y_0) rather than the origin, add x_0 and y_0 to the respective components:
    \left(x_0+ Rcos\left(\frac{2\pi}{n}i\right), y_0+ Rsin\left(\frac{2\pi}{n}i\right)\right).
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Sep 2017
    From
    Australia
    Posts
    4

    Re: Plotting regularly spaced points around the perimeter of a regular polygon

    Thanks HallsofIvy, but the circle was the easy one. I already had that. I want to know a similar way to plot points along the edges of polygons, eg pentagon, hexagon etc.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    MHF Contributor

    Joined
    Aug 2006
    Posts
    21,494
    Thanks
    2730
    Awards
    1

    Re: Plotting regularly spaced points around the perimeter of a regular polygon

    Quote Originally Posted by Phenomniverse View Post
    Thanks HallsofIvy, but the circle was the easy one. I already had that. I want to know a similar way to plot points along the edges of polygons, eg pentagon, hexagon etc.
    Being a programmer you ought to know basic functions.
    The function $r \exp(\bf{i}\pi\theta)$ is a standard way to write the complex number $z$ where $|z|=r~\&~\theta=\text{Arg}(z)$ OR $r\exp(\bf{i}\pi\theta)=(r \cos (\theta) + \bf{i}r \sin(\theta)$
    co
    Suppose that we want a regular polygon with $n$ edges.
    The define $\zeta=\exp\left( {\dfrac{{2\pi \bf{i}}}{n}} \right)$ The collection of points $\mathcal{V}=\{2\zeta^k|~k=0,~1,~\cdots,~n-1\}$
    is a set of vertices of a regular polygon with $n$ vertices inscribed in a circle centered at $(0,0)$ with radius $2$.
    If you want a different circle just adjust the $2$. To draw the edges, connect consecutive vertices.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Sep 2017
    From
    Australia
    Posts
    4

    Re: Plotting regularly spaced points around the perimeter of a regular polygon

    Thanks Plato. Actually I'm not a programmer, just a dabbler. Similarly with maths. So your explanation goes way over my head. Can you dumb it down a bit for me?
    Follow Math Help Forum on Facebook and Google+

  6. #6
    MHF Contributor
    Joined
    Dec 2012
    From
    Athens, OH, USA
    Posts
    1,123
    Thanks
    467

    Re: Plotting regularly spaced points around the perimeter of a regular polygon

    I'm not sure that I understand what you want. Here's what I think you want. Given a regular polygon with n sides, place m total points on the edges of the polygon so that the "path distances" between consecutive points are all the same, namely the fraction ${n\over m}$ of the length of a side. Here's a diagram with n=5 and m=8:



    Coding of the coordinates of the m points is sufficiently tricky that very few beginning programmers could do it. If you like, I can give you formal code which does exactly this.
    Last edited by johng; Sep 25th 2017 at 06:16 PM.
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Newbie
    Joined
    Sep 2017
    From
    Australia
    Posts
    4

    Re: Plotting regularly spaced points around the perimeter of a regular polygon

    Thanks johng. That looks pretty cool. But my problem is maybe a little simpler than that, since I've got 60 objects I just need to place 12 of them evenly along each side (for a pentagon, or 10 for a hexagon etc). Ideally with an object on each corner. That may or may not be easier than calulating the length of paths that go around corners. I was thinking that if I can work out the coordinates of each corner, I could increment the x and y coordinates for each point according to the gradient of the side that I'm putting the objects on. That's more or less how a created a square and triangle, although it was kind of messy and I just couldn't get my head around a straight forward way of doing that especially for objects with more sides. I'm probably more interested in seeing how to approach the problem than in just being given the code to solve it, although seeing the code might help me to understand the problem better.
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Super Member
    Joined
    Jun 2013
    From
    Lebanon
    Posts
    753
    Thanks
    341

    Re: Plotting regularly spaced points around the perimeter of a regular polygon

    If we want to travel from point A(a,b) to point B(c,d) in a straight line we would use

    x=a+\frac{k}{n}(c-a)

    and

    y=b+\frac{k}{n}(d-b)

    with 0\leq k\leq n

    for k=0 we are at the point A, k=n we are at B

    for 0<k<n we get regularly spaced points in between
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Regular polygon
    Posted in the Geometry Forum
    Replies: 6
    Last Post: Feb 10th 2014, 03:12 AM
  2. Replies: 1
    Last Post: Apr 20th 2012, 11:26 AM
  3. regular polygon
    Posted in the Geometry Forum
    Replies: 11
    Last Post: Jun 12th 2011, 02:10 AM
  4. Replies: 1
    Last Post: Mar 9th 2011, 09:49 PM
  5. [SOLVED] Exponential function - regularly spaced points
    Posted in the Pre-Calculus Forum
    Replies: 1
    Last Post: Jul 25th 2010, 03:04 PM

/mathhelpforum @mathhelpforum