4

I looking for drawing some forms with Tikz using the following code :

\begin{figure}
\centering

\shade[ball color=gray] (0,4) circle (5ex);
\shade[ball color=black] (1,4) circle (5ex);

\shade[ball color=gray] (7,4) circle (5ex);
\shade[ball color=black] (9,4) circle (5ex);

\shade[ball color=gray] (4,1) circle (5ex);
\shade[ball color=black] (5,1) circle (5ex);
\shade[ball color=gray!70] (4.5,0) circle (5ex);
\end{tikzpicture}

\label{fig1chap3}

\end{figure}

but I cannot figure out how to draw the framed forms as the following picture : enter image description here

  • 1
    Please complete your code snippet to be compilable! – Kurt Aug 9 '16 at 22:22
  • @Kurt my code included in a chapter which itself included in a main.tex – Ans Piter Aug 9 '16 at 22:28
  • 1
    @Ans Piter: What Kurt meant was that you should construct a compilable example just with the relevant code for your question. Minimal Working Example. – hpekristiansen Aug 9 '16 at 22:49
8

Clipping can helping here a lot, a starting point:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
  radius=10mm,
]
  \begin{scope}
    \clip (0, 0) circle;
    \fill[red] (0, 0) circle;
    \fill[red!50!blue, overlay] (13mm, 0) circle;
  \end{scope}
\end{tikzpicture}
\end{document}

Result

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
  radius=10mm,
]
  \begin{scope}[even odd rule]
    \clip[overlay]
      (-11mm, -11mm) rectangle (11mm, 11mm)
      (13mm, 0) circle;
    \fill[red] (0, 0) circle;
  \end{scope}
  \begin{scope}[xshift=4mm]
    \clip (0, 0) circle;
    \clip (13mm, 0) circle;
    \fill[red!50!blue] (0, 0) circle;
  \end{scope}
  \begin{scope}[xshift=8mm, even odd rule]
    \clip[overlay]
      (13mm - 11mm, -11mm) rectangle (13mm + 11mm, 11mm)
      (0, 0) circle;
    \fill[blue] (13mm, 0) circle;
  \end{scope}
\end{tikzpicture}
\end{document}

Result

Using two circles for clipping for the left or right side of the previous drawing will not work:

\begin{scope}[even odd rule]
  \clip (0, 0) circle[]
        (13mm, 0) circle;
  \fill[red] (0, 0) circle;
\end{scope}

The problem is the border of the first circle in the area of the second circle. There, the circle is drawn with a faint line. The problem is worked around by using a larger area for the first circle.

With shading

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
  radius=10mm,
]
  \begin{scope}[even odd rule]
    \clip[overlay]
      (-11mm, -11mm) rectangle (11mm, 11mm)
      (13mm, 0) circle[];
    ;
    \fill[shading=ball, ball color=red] (0, 0) circle;
  \end{scope}
  \begin{scope}[xshift=4mm]
    \clip (0, 0) circle;
    \clip (13mm, 0) circle;
    \fill[shading=ball, ball color=red!50!blue] (0, 0) circle;
  \end{scope}
  \begin{scope}[xshift=8mm, even odd rule]
    \clip[overlay]
      (13mm - 11mm, -11mm) rectangle (13mm + 11mm, 11mm)
      (0, 0) circle;
    \fill[shading=ball, ball color=blue] (13mm, 0) circle;
  \end{scope}
\end{tikzpicture}
\end{document}

Result shading

  • 2
    not clipping seems less work though on first sight \begin{tikzpicture} \fill[red](0,0) arc (60:300:1) arc (-120:-240:1) --cycle; \fill[green] (0.5,0) arc (60:-60:1) arc (-120:-240:1); \fill[blue](1,0) arc (120:-120:1) arc (-60:60:1) --cycle; \end{tikzpicture} – percusse Aug 9 '16 at 22:42
  • how I can use the ball form instead circle ? – Ans Piter Aug 9 '16 at 22:46

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.