I am working on a program where I need to draw a shape which is a
regular convex polygon. The parameters I am given is the number of
sides and the radius of the of the circumscribing circle. Let's say
the bottom side of the polygon is to be horizontal, I am trying to
calculate coordinates of its vertices so that I can draw it. I can
calculate many of polygon's properties like the length of its side or
its area, but I am a little stuck calculating the coordinates of its
vertices. Any advice is highly appreciated.
Leo
Hi Leo,
the vertices of a regular n-gon with circumradius R are:
for n even:
Xn(k)=R*[-sin(k*2*pi/n-pi/n) cos(k*2*pi/n-pi/n)] ,
and for n odd:
Xn(k)=R*[-sin(k*2*pi/n-2*pi/n) cos(k*2*pi/n-2*pi/n)];
where k = 0, 1, ..., n-1 .
Best regards,
Avni
Ben
While Avni and Ben both gave what I'm sure are excellent answers, I'm a little dumber than that mathematically. When I read the above I pictured x and y coordinates as needed in the form: (x,y) for the center and (x+a, y+b) for the vertices.
I'm not sure Leo is as helpless as me, but could someone get me from Avni or Ben's formulae to xy coordinates?
Hi,
They do give the coordinates, although not explicitely for you.
The key is that the coordinates x, y of points on a unit circle
centered at origin are x = cos(t), y = sin(t)
That is for any circle centered in (a, b) with radius r :
x = a + r*cos(t), y = b + r*sin(t).
I'll generally discard the r factor and the offset (a, b) for
the sequel.
For vertices of a regular n-gon inscribed in the circle, the angles
are 2pi/n apart from each other (2pi is in radian, that is 360 degree
all further angles are in radian).
That is x[k] = cos(t0 + k*2pi/n) , y[k] = sin(t0 + k*2pi/n)
the t0 being the angle of some [given] vertex.
Ben has choosen t0 = 0, and has written the coordinates (x, y) as
a complex number z = x + i*y, a usual way to represent points on
a plane, but totally equivallent to (x, y), just easing some
calculations. For instance writing cos(t) + i*sin(t) as exp(i*t)
and using rules for exponentiation gives "at once" the formulas
for cos(n*t), cos(a+b) etc...
However the requirement was :
"the bottom side of the polygon is to be horizontal"
Hence Ben formulas is false, as it has choosen its first vertex (t0)
at (1, 0) or introducing r at (r, 0), written as z0 = r + 0*i.
The bottom side is then not always horizontal, depending on n.
Avni has choosen an other t0, introducing two separate cases
n odd : then a vertex is at (0, R), angle t0 = pi/2
n even : then the upper side is also horizontal and a vertex is at
angle t0 = pi/2 - pi/n
As cos(pi/2 + t) = - sin(t) and sin(pi/2 - t) = cos(t),
this results into his set of formulas.
Coordinates of a point X being written as [x y] (the space to
separate coordinates is not a so good choice however)
I would prefer choosing the initial vertex at one end of this
bottom side ! this results into a formula which doesn't depend
on the parity of n.
That is t0 = -pi/2 + pi/n whatever n.
Then apply cos(-pi/2 + t) = sin(t) and sin(-pi/2 + t) = -cos(t),
this results into the coordinates of the k-th vertex :
x[k] = a + r*sin(pi/n + k*2pi/n)
y[k] = b - r*cos(pi/n + k*2pi/n)
Best Regards.
--
Philippe Ch., mail : chephi...@free.fr
site : http://mathafou.free.fr/ (recreational mathematics)
Mark
You can conveniently use polar coordinate form of equation of circle
passing through origin to obtain the vertices. a is length of a
polygon side,
R is Circum-radius. Using Law of Sines for each triangle in the
polygon,
where al is angle contained in the circle segment looking at origin,
al = 2 Pi/n = t step for polygon of n sides to get coordinates of
vertices.
r/ sin(t + al) = a/ sin(al) = 2R, sin(al) = a / 2R,
(x,y) = 2 R (cos(t), sin(t) ) sin ( t + arcsin ( a / 2R ) )
t = 0,2 Pi, with step al.
Narasimham