2

Here is the source code:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
    \draw (0, 0) circle (1cm);
    \path[fill=black] (90:1cm) arc (90:270:1cm);
    \path[fill=black] (0:0cm) arc (-90:90:.5cm);
    \path[fill=white] (0:0cm) arc (90:270:.5cm);
    \path[fill=white] (0, .5) circle (.1cm);
    \path[fill=black] (0, -.5) circle (.1cm);
\end{tikzpicture}

\begin{tikzpicture}
    \draw (0, 0) circle (1cm);
    \filldraw[color=black] (90:1cm) arc (90:270:1cm);
    \fill[color=black] (0, .5) circle (.5cm);
    \fill[color=white] (0, -.5) circle (.5cm);
    \fill[color=white] (0, .5) circle (.1cm);
    \fill[color=black] (0, -.5) circle (.1cm);
\end{tikzpicture}

\end{document}

enter image description here

Both approaches should work, but apparently the first one has some flaws, why?

qed
  • 708

2 Answers2

5

While this may be a rounding errror,it can still be annoying. It's also an artifact of the manner in which you constructed your symbol since you draw and fill a semi-circle. Instead you can do something along the lines of:

\documentclass{article}
\usepackage{tikz}
\begin{document}

    \begin{tikzpicture}
      \draw (0, 0) circle (1cm);
      \path[fill=black] (90:1cm) arc (90:-90:0.5cm)
                        (0,0)    arc (90:270:0.5cm)
                        (0,-1cm) arc (-90:-270:1cm);
      \path[fill=white] (0, 0.5) circle (0.1cm);
      \path[fill=black] (0,-0.5) circle (0.1cm);
    \end{tikzpicture}

\end{document}

enter image description here

A.Ellett
  • 50,533
  • 1
    Well, qed is doing something like this in the second picture, I suppose that it was just an example to show the deeper problem. – yo' Oct 20 '13 at 20:26
  • 1
    @tohecz I noticed that. But I thought the OP could benefit from seeing how to draw and fill the tear-drop portion without having to do it in several parts. – A.Ellett Oct 20 '13 at 20:28
4

Or, you do it in one path:

Code

\documentclass[tikz]{standalone}
\tikzset{
  YinYang/.style={insert path={{[even odd rule, start angle=90, delta angle=180]
    coordinate (@aux) circle              [radius={#1}]
    arc                                   [radius={(#1)/2}]
    arc                                   [radius={#1},     start angle=270]
    arc                                   [radius={(#1)/2}, delta angle=-180]
    ([shift=(down:{(#1)/2})] @aux) circle [radius={(#1)/10}]
    ([shift=(  up:{(#1)/2})] @aux) circle [radius={(#1)/10}]
    % doing the big circle as an edge allows us to only draw that and only fill the rest
    (@aux) edge[to path={circle [radius={#1}]}] ()}}}}
\begin{document}
\tikz\fill[YinYang=1];
\tikz\fill[
    draw=white, every edge/.style,
    even odd rule, inner color=red,  outer color=blue,
    preaction    ={inner color=blue, outer color=red },
    % the preaction uses nonzero rule, so it is essentially only the full circle.
  ] [YinYang=-1];% negative raduius flips the two halves
\end{document}

Output

enter image description hereenter image description here

Qrrbrbirlbel
  • 119,821