How do I draw a circle and its surrounding polygons, for example an octagon, in LaTeX?


How shall I draw thee? Let me count the ways!
I can draw thee with TikZ and PSTricks and pictures

... but there my scansion leaves me and I resume normal operating procedures.

Edited: My original method was using node shapes, but that was simultaneously posted by Debilski above so here's another TikZ method. (I'll leave my original pictures in, though). This method is a bit more like TikZ's "circle" and "rectangle" commands (though not quite) in that it looks a bit as though there is a generic polygon shape, though in reality it is just a regular LaTeX command that expands to the correct drawing instructions. The arguments to the command are the number of sides and the inner radius.



  let \n{len} = {2*#2*tan(360/(2*#1))} in
 ++(0,-#2) ++(\n{len}/2,0) \foreach \x in {1,...,#1} { -- ++(\x*360/#1:\n{len})}}


\draw[red,dashed] (0,0) circle (1);
\draw (0,0) \polygon{8}{1};
\draw[red,dashed] (3,0) circle (1);
\draw (3,0) \polygon{4}{1};
\draw[red,dashed] (6,0) circle (1);
\draw (6,0) \polygon{7}{1};



circles and polygons again

The following is from my original answer, as noted above that was the same as that given by Debilski, but as that answer didn't include pictures I'm leaving these here.

circles and polygons


There is an example in the TikZ/PGF manual:

  \draw[dashed] (10,0) circle (1cm);
  \node[regular polygon, regular polygon sides=8, draw, inner sep=0.707cm] at (10,0) {};
  • 1
    Also in the same manual on page 474, the through library makes it very easy to draw a circumcircle using the circle through option. That way you don't need to specify a radius rather leave it to tikz to calculate what the radius is. This is particularly helpful when scaling the figure.
    – percusse
    Mar 7 '11 at 13:16

Rewritten answer — I had missed point about inscribed circle

In Metapost:

    pair vert[];
    n:=5; radius=3cm;
    for i=0 upto n: 
        vert[i] = radius * dir(360*i/n);
    draw for i=0 upto n-1: vert[i] -- endfor cycle withcolor red; 
        % polygon
    draw for i=0 upto n-1: vert[i] .. endfor cycle withcolor green; 
        % outer circle
    draw for i=0 upto n-1: 1/2*(vert[i]+vert[i+1]) .. endfor cycle withcolor blue; 
        % inner circle, using midpoints.

which makes use of mplib, only available in Luatex, so you have to compile this using lualatex. It gives:

enter image description here

The nice thing about this way of doing things is that you calculate the interior circle using midpoints of lines, rather than with magic numbers or trigonometric identies, giving code that is more obviously correct.


Another way, if you want to use the vertices :


% #1 : number of sides
% #2 : radius of the circumscribed circle
% #3 : Prefix of vertices
% #4 : angle for a rotation around the center 
% The macro defines only the vertices 

\foreach \n in {1,...,#1}{%
+ (#4+\n*360/#1:#2) coordinate (#3\n)}} 

% Draw the polygon
% #1 : options 
% #2 : number of sides
% #3 : the prefix

\draw[#1] (#3\s) 
\foreach \s  in  {2,...,#2}{--(#3\s)}--cycle;

% macro to draw the inscribed circle
% #1 : number of sides 
% #2 : : radius of the circumscribed circle

circle ({#2*cos(180/#1)})


 \path (1,1)  \RegPolygon{5}{3}{S}{18};
 \draw (1,1) circle (3); 
 \path (1,-6)  \RegPolygon{3}{3}{B}{30}; 
 \draw (1,-6) circle (3);  
 \draw (1,1) \DrawCircleIns{5}{3};


enter image description here

The vertices of the pentagon are names S1,S2, etc. and the vertices of the triangle are B1,B2 and B3

  • How can I label vertices? Aug 7 '15 at 1:43

You might have better luck on the version of this site devoted to tex: http://tex.stackexchange.com

nonetheless, you should try using the PSTricks package and drawing whatever shape you need point by point or arc by arc.

For example, here is how you can draw a triangle and a circle:

   %% Triangle in red

   %% Circle in blue with radius 1:

For other n-sided polygons, use something similar to the triangle above, plotting a point for each vertex in the shape.


An easy pstricks solution, to have a circle with an inscribed and a circumscribed pentagons. It uses the pst-poly package:

\documentclass[12pt, x11names, border=1pt]{standalone}

\psset{unit = 2cm, dimen =middle}
    \psset{ linewidth = 0.6pt, dimen =inner}
    \rput{-22.5}{\PstOctogon[PolyName =A, linecolor =DarkOliveGreen3]}
    \psdot[dotstyle = o, dotsize=1.5pt,fillstyle = solid, fillcolor=IndianRed3](A0)
    \makeatletter\psset{unit=\R, linewidth =0.6pt, linecolor=Gold1}\makeatother%
    \psset{linestyle=dashed, linewidth=0.3pt}
    \psline[ linecolor=DarkOliveGreen3 ](B8)(A0)(B1)\psline[ linecolor= Gold1](A0)(A1)


enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy