# Regular polygon and tkz-euclide

Is there any slick way to create an n-sided (n is some arbitrary integer, e.g. n = 23) regular polygon, inscribed into a circle, using tkz-euclide?

Or do I have to use the plain TikZ functions (not as intuitive as tkz-euclide)?

I find your lack of faith disturbing...

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric,calc}
\begin{document}
\begin{tikzpicture}
\node[regular polygon,regular polygon sides=23,draw,minimum height=5cm] (a) at (0,0) {};
\draw[red] let \p1=($(a.corner 1)-(a.center)$), \n1={veclen(\x1,\y1)} in circle (\n1);
\foreach \x[count=\xi] in {A,B,...,W}{
\node (a-\xi) at ([shift={({90+(\xi-1)*360/23}:3mm)}]a.corner \xi) {\x};
}
\end{tikzpicture}
\end{document}


• And if I'd like to label the vertices A,B,C,...? What should be added then? Mar 8, 2015 at 17:28
• @marmistrz Added. Mar 8, 2015 at 17:34
• Thanks! Could you please explain how the lines 6-8 work? Mar 8, 2015 at 17:46
• Nice (+1)! I had no idea the ... syntax could handle alphabetic sequences automatically. Mar 8, 2015 at 18:16
• @marmistrz It goes through every corner anchor which TikZ automatically numbers starting from the top. Then it places a node at each of those but instead placing them right on the anchor it shifts them the amount of 23 degrees depending on the number of iteration which is held in \xi. It's just a compact notation trust me nothing fancy happening. Mar 8, 2015 at 19:02

A PSTricks solution using the pst-poly package:

\documentclass{article}

\usepackage{pst-poly}

% parameters
\def\sides{12}

\begin{document}

\rput(0,0){\PstPolygon[PolyNbSides = \sides, unit = \radius]}
\end{pspicture}

\end{document}


• +1 for not threatening the use of the dark side of the force Mar 8, 2015 at 17:45
• @DavidCarlisle I don't follow you but I'm glad I haven't used 'the dark side of the force'. :) Mar 8, 2015 at 17:46
• See the link at the top of the other answer:-) Mar 8, 2015 at 17:49

A MetaPost solution using a macro of my own. Example shamelessly inspired from Svend Tveskæg's answer.

\documentclass[border=2bp]{standalone}
\usepackage{luamplib}
\begin{document}
\begin{mplibcode}
vardef regular_polygon(expr center, radius, n) =
save angl; angl := 360/n;
(right for i = 1 upto n-1: -- dir(i*angl) endfor -- cycle)
enddef;
beginfig(0);
draw regular_polygon(origin, 4cm, 12);
draw fullcircle scaled 8cm;
endfig;
\end{mplibcode}
\end{document}


Edit Another version, a bit more elaborated, with alphabetic labels. The number of summits n must be lower than 27 to keep the labeling coherent :-)

\documentclass[border=2bp]{standalone}
\usepackage{luamplib}
\mplibsetformat{metafun}
\mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
vardef regular_polygon(expr centre, radius, n) =
clearxy; save angl; angl := 360/n;
z0 = centre + radius*right; freelabel("$A$", z0, centre);
z0 for i = 1 upto n-1:
hide(z[i] = z[i-1] rotatedaround(centre, angl);
freelabel("$" & char(65+i) & "$", z[i], centre))
-- z[i]
endfor -- cycle
enddef;
beginfig(0);
draw regular_polygon(origin, 4cm, 12) withcolor red;
draw fullcircle scaled 8cm;
endfig;
\end{mplibcode}
\end{document}