TikZ-PGF Circles – Drawing Circles with a Specific Outer Radius

circlestikz-pgfwidth

For an archery target I need to draw (and fill) a circle which is e.g. exactly 10cm in diameter including its line. However, when using TikZs circle path command the given radius is the middle of the line, therefore the printed circle is too large.

The solution should depend on the current line width.

Here is my code so far. The drawn lines clearly leave the given radius, but should be drawn completly inside it.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=1cm, y=1cm, line width=2mm]
    \path [draw=black,fill=yellow] (0,0) circle (5cm);
    \path [draw=black,fill=red] (0,0) circle (4cm);
    \path [draw=black,fill=green,line width=3mm] (0,0) circle (3cm);
    \draw [thin,gray] (-6,-6) grid (6,6);
\end{tikzpicture}
\end{document}

Example

Best Answer

in tikz any coordinate of any path command is determined for the infinitely thin lines. the real lines lie over them so that their centers matches.

line width of real lines is accessible with length \pgflinewidth. knowing it, it is simple to correct size of some elementary shapes as are rectangles, squares and circles with considering line widths. for example:

  • rectangle: \draw[very thick] (x1+0.5\pgflinewidth,y1+0.5\pgflinewidth) rectangle (x2-0.5\pgflinewidth,y2+0.5\pgflinewidth); where x1, y1 and x2, y2 are coordinates of rectangle. an example of comparison of two rectangles: the red rectangle has width 4cm + \pgflinewidth = 4.1cm, and the width of the yellow (that we can see it borders, it is drawn semitransparent) is exactly 4cm.

\documentclass[tikz, margin=3mm]{standalone}

\begin{document}
\begin{tikzpicture}[line width=2mm]
    \draw[red]   (0,0) rectangle (4,4);
    \draw[yellow,semitransparent]  (0.5\pgflinewidth,0.5\pgflinewidth) rectangle (4cm-0.5\pgflinewidth,4cm-0.5\pgflinewidth);
%
    \draw [thin,gray] (-1,-1) grid (5,5);
\end{tikzpicture}
\end{document}

enter image description here

  • circle: \draw[very thick] (0,0) circle (<radius>-0.5\pgflinewidth); where <radius> circle radius size. an example of comparison of two circles is done similarly as above for rectangles: the red circle has diameter 2cm + \pgflinewidth = 4.1cm, diameter of the the yellow circle is exactly 4cm.

\documentclass[tikz, margin=3mm]{standalone}

\begin{document}
\begin{tikzpicture}[line width=2mm]
    \draw[red]   (0,0) circle (2cm);
    \draw[yellow,semitransparent]  (0,0) circle (2cm-0.5\pgflinewidth);
%
    \draw [thin,gray] (-3,-3) grid (3,3);
\end{tikzpicture}
\end{document}

enter image description here

considering above, the circles from question with outer line border exactly as given with circles' radius are as follows:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=1cm, y=1cm, line width=2mm]
    \path [draw=blue,fill=yellow] (0,0) circle (5cm-0.5\pgflinewidth);
    \path [draw=black,fill=red] (0,0) circle (4cm-0.5\pgflinewidth);
    \path [draw=black,fill=green,line width=3mm] (0,0) circle (3cm-0.5\pgflinewidth);
    \draw [thin,gray] (-6,-6) grid (6,6);
\end{tikzpicture}
\end{document}

enter image description here

Related Question