TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to replicate the following figure here

enter image description here

and this is what I have so far


        \begin{scope}[shift = {(#1,#2)}
            \fill[red] (0,0) circle (0.5);
            \clip (0,0) circle (0.5);
            \shade[shading=ball,ball color=white,1] (0.15,0.25) circle (0.7);



        \tkzDefPoint(0,0){A}         \tkzDefPoint(0.9*\length,-\height){B}
        \tkzDefPoint(2*\length,0){C} \tkzDefPoint(1.1*\length, \height){D}

                \tkzDefPoint(0,0){A1}         \tkzDefPoint(0.9*\length,-\height){B1}
                \tkzDefPoint(2*\length,0){C1} \tkzDefPoint(1.1*\length, \height){D1}

        \tkzDrawSegments(A,A1 B1,B C1,C D1,D);  
%               \ball{2}{2}

By using the tips I got from this question. I think I almost got it, but the code will not compile when uncommenting the last line. What is the reason for this?

Other means create this image would also appreciated, it is always refreshing to see different approaches to a problem.

share|improve this question
You forgot to close the scope options: \begin{scope}[shift = {(#1,#2)}]. You also have an undefined option for \shade: instead of \shade[shading=ball,ball color=white,1], write \shade[ball color=white]. I would also suggest \shade[ball color=white] (0.15,0.25) circle (1); – hpesoj626 Jun 23 '13 at 12:22

A possible solution:




\pgfdeclareradialshading[tikz@ball]{my ball}{\pgfqpoint{5bp}{10bp}}{%

\pgfdeclareradialshading[tikz@ball]{new ball}{\pgfqpoint{12bp}{12bp}}{%

% code by percusse:
% http://tex.stackexchange.com/a/74237/13304
\pgfdeclareradialshading{ball shadow}{\pgfpointorigin}%

 % to make possible use "myball color=..." 
\tikzoption{my ball color}{\pgfutil@colorlet{tikz@ball}{#1}\def\tikz@shading{my ball}\tikz@addmode{\tikz@mode@shadetrue}}

\tikzoption{new ball color}{\pgfutil@colorlet{tikz@ball}{#1}\def\tikz@shading{new ball}\tikz@addmode{\tikz@mode@shadetrue}}

\tikzoption{ball shadow color}{\pgfutil@colorlet{tikz@ball}{#1}\def\tikz@shading{ball shadow}\tikz@addmode{\tikz@mode@shadetrue}}

        \begin{scope}[shift = {(#2,#3)}]
          \node[shading=ball shadow,xscale=2,yscale=0.3,circle,minimum size=7mm] 
            at (0.15,-0.225){};
          % test to decide which shading use: special one for white balls
          % not 100% efficient: maybe it's better to use directly a custom
          % white ball shading, but this way one could always use 
          % "my ball color=green" say
            \shade[my ball color=#1] (0.15,0.25) circle (0.5);
            \shade[new ball color=#1] (0.15,0.25) circle (0.5);



    \tkzDefPoint(0,0){A}         \tkzDefPoint(0.9*\length,-1.1\height){B}
    \tkzDefPoint(1.9*\length,0){C} \tkzDefPoint(1.1*\length, \height){D}
    %\tkzDrawPolygon(A,B,C,D) % Beware to put the right segments in foreground
    % now this can not be a polygon: need to be split
    % Same would apply to the shifted one if the balls touch the upper layer
    \tkzDrawSegments(C,D D,A);

            \tkzDefPoint(1.9*\length,0){C1} \tkzDefPoint(1.1*\length, \height){D1}

    \tkzDrawSegments(A,A1 C1,C D1,D);
      % other segments in foreground
      \tkzDrawSegments(A,B B,C);

    % balls: beware the order matters

The result:

enter image description here

The tricks are:

  • define the shading in a similar way as How to shade mindmap concepts? so that the \ball command, besides the usual capability of being shifted, can also set the color;
  • draw specific segments, like the segment B,B1 in the foreground layer: in such a way balls seem to be in background;
  • draw the balls with a precise order: to not use too much the pgfonlayer enviroment, the simplest thing to do is to first draw the balls behind, proceeding then with the other ones.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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