Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to know if it is possible to draw an image like this in 3D using tikz? I am having some text around this picture, which looks great in tikz, but I am unable to draw this kind of 3D figure in tikz. Also the shadows around it looks quite complex to me.

Any examples, ideas, suggestions?

enter image description here

Thank You !

share|improve this question
    
yes, it is possible. You can have a look here tex.stackexchange.com/questions/58633/… or here tex.stackexchange.com/questions/42812/3d-bodies-in-tikz for some ideas on lighting and 3D-body-generation. –  LaRiFaRi May 5 at 13:14
    
I will say that this reminds me of a standard icon pack I used back in the day. That pack came with vectors for each icon; if you have a vector for the image, there is little purpose in trying to create it with TikZ (but you can have Inkscape 'convert' it for you). –  Sean Allred May 5 at 13:16
    
should i get this graphic from eps and embed in tikz? is it possible? just to avoid lot of coding. –  Raj May 5 at 13:18
1  
In my opinion this is not suited for TikZ, here you have something “similar”. –  Manuel May 5 at 13:26
1  
@Raj Yes, I would recommend against using TikZ if you have a vector already available. If you have the vector in the same folder, you can just use \includegraphics{my-vector}—no need for TikZ. I would recommend you convert whatever you have to PDF first, just for ease of use. –  Sean Allred May 5 at 13:37

3 Answers 3

up vote 30 down vote accepted

Definitely not perfect in any respect but anyway...

\documentclass[tikz,border=5]{standalone}
\tikzset{pics/.cd,
  disc/.style={
    code={
      \fill [white] ellipse [x radius=2, y radius=2/3];
      \path [left color=black!50, right color=black!50, middle color=black!25] 
        (-2+.05,-1.1) arc (180:360:2-.05 and 2/3-.05*2/3) -- cycle;
      \path [top color=black!25, bottom color=white] 
        (0,.05*2/3) ellipse [x radius=2-.05, y radius=2/3-.05*2/3];
      \path [left color=black!25, right color=black!25, middle color=white] 
        (-2,0) -- (-2,-1) arc (180:360:2 and 2/3) -- (2,0) arc (360:180:2 and 2/3);
      \foreach \r in {225,315}
        \foreach \i [evaluate={\s=30;}] in {0,2,...,30}
          \fill [black, fill opacity=1/50] 
            (0,0) -- (\r+\s-\i:2 and 2/3) -- ++(0,-1) 
            arc (\r+\s-\i:\r-\s+\i:2 and 2/3) -- ++(0,1) -- cycle;
      \foreach \r in {45,135}
        \foreach \i [evaluate={\s=30;}] in {0,2,...,30}
          \fill [black, fill opacity=1/50] 
            (0,0) -- (\r+\s-\i:2 and 2/3) 
            arc (\r+\s-\i:\r-\s+\i:2 and 2/3)  -- cycle;
    }
  },
  disc bottom/.style={
    code={
      \foreach \i in {0,2,...,30}
        \fill [black, fill opacity=1/60] (0,-1.1) ellipse [x radius=2+\i/40, y radius=2/3+\i/60];
      \path pic {disc};
    }
  }
}
\begin{document}
\begin{tikzpicture}

\path (0,0) pic {disc bottom} (0,1.25) pic {disc} (0,2.5) pic {disc};

\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
2  
this is amazing ! :) –  Raj May 5 at 14:20
    
Short and impressive! I added also this to the TeXample TikZ gallery. Most TikZ graphics I bookmark here are yours. –  Stefan Kottwitz Jul 29 at 21:02

I'm afraid I also could not resist giving it a shot with Asymptote. Unlike the TikZ solution, this actually uses an underlying 3d model. In particular, the "white ring" around the top emerged naturally as a result of rounding the corner, together with Asymptote's shading capabilities.

\documentclass[margin=10pt,convert]{standalone}
\usepackage{asypictureB}
\begin{document}
\begin{asypicture}{name=disk}
    settings.outformat = "png";
    settings.render=16;
    unitsize(2cm);
    import three;
    import roundedpath;
    currentprojection = orthographic(0,4,1);

    int nslices = 20;
    pen colorfunction(int u, real v) {
        real t = (v/nslices)*4pi;
        static pen dark = gray(0.3);
        static pen light = white;
        return interp(dark, light, (sin(t)+1)/2);
    }

    real radius = 2.0, height = 1.0;

    path3 to_revolve = path3(roundedpath((0,0) -- (radius,0) -- (radius,height) -- (0.9 radius, height) -- (0,height), R=0.05), YZplane);
    surface disk = surface(to_revolve, c=O, axis=Z, n=nslices, color = colorfunction);
    draw(disk);

    pen undercolorfunction(int u, real v) {
        pen overpen = colorfunction(u,v);
        real r = point(to_revolve, u).y;
        return interp(black, overpen, (r/radius)^5);
    }

    surface underdisk = surface(to_revolve, c=O, axis=Z, n=nslices, color=undercolorfunction);

    draw(shift(-1.2*height*Z)*underdisk);
    draw(shift(-2.4*height*Z)*underdisk);

\end{asypicture}
\end{document}

The result:

share|improve this answer
2  
Added bonus is that you can embed the model into the PDF. –  bb010g May 6 at 1:39

I worked on Mark's solution to make it look more similar to the original picture.

\documentclass[tikz,border=5]{standalone}

\usetikzlibrary{fadings}
\tikzfading[name=fade out,
inner color=transparent!0, outer color=transparent!100]

\def\factor{4}
\def\xradius{2}
\def\yradius{2/\factor}
\def\height{1.05cm}
\def\xandy{2 and 2/\factor}

\tikzset{
  pics/.cd, %
  disc/.style ={
    code = {
      %% the foundation
      \path [fill=black!15] (-\xradius,0) -- (-\xradius,-\height) arc
      (180:360:\xandy) -- (\xradius,0) arc (0:180:\xandy);%
      \path [top color=black!25, bottom color=white, opacity=0.2] (0,0) ellipse
      [x radius=\xradius, y radius =\yradius];%
      \path [left color=black!25, right color=black!15] (-\xradius,0) --
      (-\xradius,-\height) arc (180:240:\xandy) -- +(0,\height) arc
      (240:180:\xandy);%
      \path [left color=black!15, right color=black!30] (\xradius,0) --
      (\xradius,-\height) arc (360:320:\xandy) -- +(0,\height) arc
      (320:360:\xandy);

      %% rays in front
      \foreach \col/\r/\shift/\stop/\opacity in {%
        black/205/25/20/100, %
        black/295/35/30/100, %
        black/295/30/30/200, %
        black/295/25/20/300, %
        white/245/14/14/100, %
        white/245/12/12/20, %
        white/245/10/10/10} {%
        \foreach \i [evaluate={\opposite=\r-180;}] in {0,1,...,\stop}{%
          \fill [\col, fill opacity = 1/\opacity] (\opposite:0.1 and
          0.1/\factor) -- (\r+\shift-\i:\xandy) -- ++(0,-\height) arc
          (\r+\shift-\i:\r-\shift+\i:\xandy) -- +(0,\height) -- cycle; }}

      %% rays in back
      \foreach \r/\shift/\stop/\opacity in {%
        25/25/20/100, %
        115/35/3/150,%
        115/30/23/100} {%
        \foreach \i [evaluate={\opposite=\r-180;}] in {0,1,...,\stop}{%
          \fill [black, fill opacity = 1/\opacity] (\opposite:0.1 and 0.1/\factor) --
          (\r+\shift-\i:\xandy) arc (\r+\shift-\i:\r-\shift+\i:\xandy) --
          cycle; }}

      %% masking the four edges in the center
      \foreach \i in {0.1, 0.2, ..., 0.4}%
      \fill[black!15, opacity=0.7, path fading=fade out] 
      (0,0) ellipse[x radius=\i, y radius =\i/\factor];

      %% the light and the dark arcs
      \foreach \i [evaluate={\start=185+10*\i; \finish=355-10*\i;}]%
      in {0.1, 0.2, ..., 1.5}{%
        \draw[white, opacity=0.04, line width=\i, yshift=0.02cm]
        (\start:\xandy) arc (\start:\finish:\xandy);

        \draw[black!80, opacity=0.05, line width=\i, yshift=-\height]
        (\start:\xandy) arc (\start:\finish:\xandy); }
    }
  },% 
  disc bottom/.style = {
    code = {
      \foreach \i/\opacity in {%
        1/20,2/20,3/20,4/30,5/35,6/40,7/60,8/80,9/100,10/100,11/100,12/100}%
        \fill [black, fill opacity = 1/\opacity, yshift=-0.03cm] (0,-\height)
        ellipse [x radius = \xradius+\i/40, y radius = \yradius+\i/20/\factor]; 
      \path pic {disc};
    }
  },%
  disc top/.style = {
    code = {
      \foreach \i/\opacity in {%
        2/60, 3/55, 4/50,5/40, 6/35, 7/30, 8/20, 9/20, 10/20, 11/20, 12/20,
        13/20, 14/20, 15/20, 16/20, 17/20, 18/20, 19/20, 20/20, 21/20, 22/20,
        23/20, 24/20, 25/20, 26/20}%
        \fill [black, fill opacity = 1/\opacity, yshift=-0.35cm] (0,-\height)
        ellipse [x radius = \xradius-\i/40, y radius = \yradius-\i/20/\factor];
      \path pic {disc};
    }
  }
}

\begin{document}
\begin{tikzpicture}
  \path (0,0) pic {disc bottom} (0,1.4) pic {disc top} (0,2.8) pic {disc top};
\end{tikzpicture}
\end{document}

UPDATE: the dimensions are parametrizable. But you might need to shift the discs and the shadow below accordingly.

Stacked discs

share|improve this answer

Your Answer

 
discard

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.