7

I am trying to write a report on some equipment that I used during some analysis, the diagram is shown below:

enter image description here

I attempt to re-create this with tikz, here is my attempt so far

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
% draw main body
\fill[gray!40!black!20](0,0) rectangle (5cm,7.5cm);
% draw bottom
\fill[red!80!black!70](0,0) rectangle (5cm,2cm);
% draw top
\draw[fill = blue](0,6) rectangle (5cm,7.5cm);
% draw circles at top of diagram
\fill[cyan!70!white](1.5,7)circle(0.5cm);
\fill[cyan!70!white](3.5,7)circle(0.5cm);
% draw lines 
\draw (1,7.5)--(0.5,9);
\draw (2,7.5)--(2.5,9);

\draw (3,7.5)--(2.5,9);
\draw (4,7.5)--(4.5,9);

\end{tikzpicture}
\end{document}

resulting in:

enter image description here

which to be fair is terrible. I am struggling to find a way of (1) generating the top of the diagram i.e. the top bit and make it seem that the beams are traveling away from the source. How would I do this?

Also, I realize that I'll have to play around with this a lot to make it look anywhere near the original diagram, but I thought I'd start by getting the main details in order. Can anyone suggest any way of making my attempt look a bit closer to the diagram, keeping in mind that my tikz skills are very limited.

  • 2
    I suggest you to use Inkscape to draw it and export as pdf image. – Sigur Jul 30 '13 at 18:18
10

This type of diagram may be more efficiently drawn in Inkscape and the likes but, with a little bit of patience, is totally within the remit of TikZ.

To convey that the beams are traveling away from the source, I suggest using a shade, like below. The code is far from optimal, especially in terms of maintainability, but the important bits are there. Feel free to improve it.

output screenshot

\documentclass{article}

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[thick]
        % grey metallic part
        \def\xgrey{1.2}
        \def\ygrey{0}
        \def\hgrey{1}
    \shadedraw[%
        draw                = black,%
        left color  = gray!20,%
        right color = gray!90,%
        rounded corners = 1,
    ] (-\xgrey,\ygrey) rectangle (\xgrey,{\ygrey+\hgrey});

    % red part
    \def\yred{-.5}
    \def\hred{.5}
    \shadedraw[%
        draw                = black,%
        left color  = red!20,%
        right color = red!90,%
        rounded corners = 1,
    ] (-\xgrey,\yred) rectangle (\xgrey,{\yred+\hred});
    \def\yred{-.5}
    \def\hred{.5}
    \def\redratio{1.1}
    \shade[%
        left color  = blue!20,%
        right color = blue!90,%
        opacity=.2,
        rounded corners = 1,
    ] (-\xgrey,\yred) rectangle (\xgrey,{\yred+\hred});
    \draw [rounded corners = 1,
    ] (-{\redratio*\xgrey},\yred) rectangle ({\redratio*\xgrey},{\yred+\hred});

    % blue part
    \begin{scope}[scale=1.8,shift={(0,1)}]
        \shadedraw[%
            left color  = blue!20,%
            right color = blue!90,%
            rounded corners=3,
        ]    (-.11,0)
            -- (.11,0)
            -- (.76,-.2)
            -- (.78,-.53)
            -- (-.78,-.53)
            -- (-.76,-.2)
            -- cycle;
        \draw[rounded corners=1] (-.78,-.53) rectangle (.78,-.58);
        \shadedraw[%
            left color  = blue!20,%
            right color = blue!90,%
            rounded corners=1,
        ] (-.11,0) -- (.11,0) -- (.11,.-.53) -- (-.11,.-.53) -- cycle;
    \end{scope}

    % ellipses and beams
    \def\rayyangle{15}
    \def\yray{3}
    \def\hray{4}
    \def\a{.4}
    \def\b{.1}
    \def\afactor{1.2}
    \def\bfactor{1.5}
    \newcommand\stuffray[1]{
        \draw[rotate={#1},fill=gray!90,thin]  ellipse ({\a*\afactor} and {\b*\bfactor});
        \draw[rotate={#1},fill=gray!20,thin]  ellipse ({\a} and {\b});
        \path[%
            rotate={#1},
            shade,%
            bottom color = gray!20,%
            top color = gray!1,%
            opacity=.5,
        ]    (-\a,0)
            -- (-\a,{\hray})
            -- (\a,{\hray})
            -- (\a,0)
            -- cycle;
        \draw[black,very thin,rotate={#1},opacity=.1] (-\a,0) -- (-\a,{\hray});
        \draw[black,very thin,rotate={#1},opacity=.1] (\a,0) -- (\a,{\hray});
    }

    \def\xrayshift{.72}
    \def\yrayshift{1.45}
    \begin{scope}[shift={(-\xrayshift,\yrayshift)}]
        \stuffray{\rayyangle}
    \end{scope}
     \begin{scope}[shift={(\xrayshift,\yrayshift)}]
            \stuffray{-\rayyangle}
    \end{scope}
\end{tikzpicture}
\end{document}
  • 2
    This is awesome. – KatyB Jul 31 '13 at 6:42
6

This might be a start, but, as said above in the comments, I think drawing this with e.g. Inkscape might be more efficient.

\documentclass{standalone}

\usepackage{tikz}

\def\beamr{0.5}
\def\beamlen{3}
\def\width{2.3}
\def\topwidth{3}
\def\toptopwidth{0.5}
\def\topheighta{0.8}
\def\topheightb{1.0}
\def\midwidth{0.4}

\newcommand\drawbeam{
  \draw[draw=black!75, fill=black, fill opacity=0.2] 
       (-\beamr, 0) -- (-\beamr, \beamlen) -- (\beamr, \beamlen) -- (\beamr, 0);
  \draw[draw=black!75, fill=white] 
       (0, 0) ellipse ({\beamr} and 0.1);
}

\begin{document}
\begin{tikzpicture}
\clip (-2, -3) rectangle (2, 2);
\fill[black!5] (-2, -3) rectangle (2, 2);

\begin{scope}[yshift=-75]
\shadedraw[draw=black, left color=red!20, right color=red!90, rounded corners=1] 
   ({-0.5*\width},0) rectangle ({0.5*\width},1);
\end{scope}

\begin{scope}[yshift=-50]
\shadedraw[draw=black, left color=gray!10, right color=gray!90] 
   ({-0.5*\width},0) rectangle ({0.5*\width},1);
\end{scope}

\begin{scope}[yshift=-26]
\shadedraw[draw=black, left color=blue!20, right color=blue!60, rounded corners=4] 
   ({-0.5*\topwidth},0) -- ({0.5*\topwidth},0) -- ({0.5*\topwidth},\topheighta) -- ({0.5*\toptopwidth},\topheightb)
   -- ({-0.5*\toptopwidth}, \topheightb) -- (-0.5*\topwidth,\topheighta) -- cycle;
\end{scope}

\begin{scope}[rotate=10, xshift=-20]
\drawbeam
\end{scope}
\begin{scope}[rotate=-10, xshift=20]
\drawbeam
\end{scope}

\begin{scope}[yshift=-26]
\shadedraw[draw=black, left color=blue!60, right color=blue!90, rounded corners=2]
   (-0.5*\midwidth,0) rectangle (0.5*\midwidth,\topheightb);
\end{scope}

\end{tikzpicture}
\end{document}

enter image description here

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.