# Half circle node

Some time ago I wanted to create a half-circle node and I used the solution below. However, this solution has one drawback that if you fill the node, the whole circle is filled, not only a half. Is it possible to make sure that only half of the node that is drawn is filled?

MWE:

\documentclass{minimal}
\usepackage{tikz}

\begin{document}

\makeatletter
\tikzset{arc style/.initial={}}
\pgfdeclareshape{half circle}{
\inheritsavedanchors[from=circle]
\inheritanchorborder[from=circle]

\inheritanchor[from=circle]{center}
\inheritanchor[from=circle]{south}
\inheritanchor[from=circle]{west}
\inheritanchor[from=circle]{north}
\inheritanchor[from=circle]{east}

\inheritbackgroundpath[from=circle]

\beforebackgroundpath{
\pgfkeys{/tikz/arc style/.get=\tmp}
\expandafter\tikzset\expandafter{\tmp}
\tikz@options

\centerpoint \pgf@xb=\pgf@x \pgf@yb=\pgf@y

\pgfpathmoveto{\pgfpoint{\pgf@xb}{\pgf@yb}}
\pgfpatharc{0}{-180}{\pgf@xa}

\pgfusepath{draw}
}
}
\makeatother

\begin{tikzpicture}

\fill[fill=black!10] (0,0) rectangle (6,4);
\node[half circle,inner sep=9pt] (a) at (2,2) {};
\node[half circle,inner sep=9pt,fill=white] (b) at (4,2) {};

\end{tikzpicture}

\end{document}

• There is already a semicircle shape in the shapes.geometric library. (Which doesn't answer your question, but might be of interest.) Jan 20 at 20:10
• @TorbjørnT. That would do if I can turn semicircle for 180 degrees. Jan 20 at 20:20
• shape border rotate=180 Jan 20 at 20:20
• @TorbjørnT. It works as a quick fix. The only problem is that the specified node position is not the centre of the half-circle, so I have to fix that manually. Jan 20 at 20:30
• There are lots of predefined anchors for that shape, see the figure in the TikZ manual for an overview. The default anchor is center, you might be after anchor=north, which is the center of the full circle. Jan 20 at 20:33

(Summing up comments.) While this doesn't answer the question of what is wrong with your node shape definition, you are re-inventing the wheel a bit, as the shapes.geometric library already defines a semicircle shape.

The default orientation of that shape is with the arc on top, but you can turn it the other way with shape border rotate=180. And the default anchor is center, which is in the interior of the half circle. To use the midpoint of the diameter as anchor, set anchor=chord center.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\tikzset{
half circle/.style={
semicircle,
shape border rotate=180,
anchor=chord center,
minimum size=5mm
}
}
\begin{document}
\begin{tikzpicture}
\node [half circle, draw=blue, fill=red] at (1,1) {};