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

1. ## 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.

2. ## 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 $\displaystyle \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 $\displaystyle \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: $\displaystyle \left(Rcos\left(\frac{2\pi}{n}i\right), Rsin\left(\frac{2\pi}{n}i\right)\right)$.

For a circle with center at $\displaystyle (x_0, y_0)$ rather than the origin, add $\displaystyle x_0$ and $\displaystyle y_0$ to the respective components:
$\displaystyle \left(x_0+ Rcos\left(\frac{2\pi}{n}i\right), y_0+ Rsin\left(\frac{2\pi}{n}i\right)\right)$.

3. ## 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.

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

Originally Posted by Phenomniverse
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.

5. ## 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?

6. ## 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.

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

8. ## 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

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

and

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

with $\displaystyle 0\leq k\leq n$

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

for $\displaystyle 0<k<n$ we get regularly spaced points in between