7

Consider the following example.

Code

% pdflatex -shell-escape test.tex

\documentclass{article}

\usepackage{auto-pst-pdf,pstricks-add}
\usepackage[locale=DE]{siunitx}

\ExplSyntaxOn
  \cs_new_eq:NN \calc \fp_eval:n
\ExplSyntaxOff

\def\Label#1{\ncput*{\small\SI{#1}{\cm}}}

\begin{document}

\def\bredde{18 }
\def\laengde{\calc{1.5*\bredde} }
\def\radius{3.0 }
\def\afstand{6.5 }
\def\afstandB{\calc{\afstand/2}}
\centering
\psset{unit=0.44cm}
\begin{pspicture}(\laengde,\bredde)
  \psframe(0,0)(\laengde,\bredde)
  \pnodes{P}
    (!\laengde 2 div \afstand sub \bredde \radius add 2 div)%
    (!\laengde \afstand sub 2 div \bredde \radius sub 2 div)%
    (!\laengde 2 div \bredde \radius add 2 div)%
    (!\laengde \afstand add 2 div \bredde \radius sub 2 div)%
    (!\laengde 2 div \afstand add \bredde \radius add 2 div)
  \multido{\iA=0+1,\iB=-2+1}{5}{%
    \psdot(P\iA)
    \pscircle(P\iA){\radius}
    \psline[linestyle=dotted]%
      (!\laengde \iB\space \afstand mul add 2 div \bredde 2 div 5 3 div \radius mul sub)%
      (!\laengde \iB\space \afstand mul add 2 div \bredde 2 div 5 3 div \radius mul add)
  }
  \multido{\iD=-1+1}{2}{%
    \psline[linestyle=dotted]%
      (!\laengde 2 div 10 3 div \radius mul sub
        \bredde \radius add 2 div \iD\space \radius mul add)%
      (!\laengde 2 div 10 3 div \radius mul add
        \bredde \radius add 2 div \iD\space \radius mul add)
  }
 \psset{arrows=|*-|*,nrot=:U}
  \pcline[offset=-6pt]%
    (!\laengde 2 div \afstand sub \bredde 2 div 5 3 div \radius mul sub)%
    (!\laengde 2 div \bredde 2 div 5 3 div \radius mul sub)
  \Label{\afstand}
  \pcline[offset=6pt]%
    (!\laengde 2 div \afstand sub \bredde 2 div 5 3 div \radius mul add)%
    (!\laengde \afstand sub 2 div \bredde 2 div 5 3 div \radius mul add)
  \Label{\afstandB}
  \pcline[offset=6pt]%
    (!\laengde 2 div 10 3 div \radius mul sub \bredde \radius sub 2 div)%
    (!\laengde 2 div 10 3 div \radius mul sub \bredde \radius add 2 div)
  \Label{\radius}
 \psset{linestyle=none,arrows=none}
  \pcline[offset=-9pt](0,0)(0,\bredde)
  \Label{\bredde}
  \pcline[offset=9pt](0,0)(\laengde,0)
  \Label{\laengde}
\end{pspicture}

\end{document}

Output

enter image description here

Question

I have the desired output but the code is not very elegant. I have improved the code somewhat, already, but it can be even better, I think.

1
  • @Bugbusters 18cm. Have I typed 15cm somewhere? Apr 25, 2013 at 7:10

3 Answers 3

4
\documentclass{article}

\usepackage{auto-pst-pdf,pstricks-add}
\usepackage[locale=DE]{siunitx}
\newcommand\Label[2][:U]{\ncput*[nrot=#1]{\small\SI{#2}{\cm}}}
\begin{document}

\def\bredde{18 }
\edef\laengde{\the\numexpr3*\bredde/2\relax\space}
\def\radius{3.0 }
\def\afstand{6.5 }
\def\afstandB{3.25 }
\centering
\psset{unit=0.44cm}
\begin{pspicture}(\laengde,\bredde)
  \psframe(0,0)(\laengde,\bredde)
  \multido{\iA=1+1,\iB=-2+1}{5}{%
    \rput(!\laengde 2 div \bredde 2 div){% all relative to the center
      \pnode(!\iB\space \afstandB mul \radius 2 div \iA\space 2 mod 0 eq { neg } if ){P\iA}
      \psdot(P\iA)\pscircle(P\iA){\radius}
      \psline[linestyle=dotted](!\psGetNodeCenter{P\iA} P\iA.x \radius 1.5 mul 1 add)
                               (!\psGetNodeCenter{P\iA} P\iA.x \radius -1.5 mul 1 sub) }
  }
  \pcline[linestyle=dotted,nodesep=-\radius](P1)(P5)
  \pcline[linestyle=dotted,nodesep=-\radius,offset=-\radius](P1)(P5)

 \psset{arrows=|*-|*}
  \pcline(!\psGetNodeCenter{P1} P1.x P1.y \radius 2 mul sub 1 sub)%
         (!\psGetNodeCenter{P3} P3.x P3.y \radius 2 mul sub 1 sub)\Label{\afstand}
  \pcline(!\psGetNodeCenter{P1} P1.x P1.y \radius add 1 add)%
         (!\psGetNodeCenter{P2} P2.x P2.y \radius 2 mul add 1 add)\Label{\afstandB}
  \pcline(!\psGetNodeCenter{P2} P2.x \radius sub \afstandB sub 1 sub P2.y)%
         (!\psGetNodeCenter{P1} P1.x \radius sub 1 sub P1.y )\Label{\radius}
  \uput[90](!\laengde 2 div 0){\small\SI{\laengde}{\cm}}
  \uput[0]{90}(!0 \bredde 2 div){\small\SI{\bredde}{\cm}}
\end{pspicture}

\end{document}

If you don't want to do the devision by hand, use the following:

\psset{unit=0.44cm}
\def\bredde{18 }
\edef\laengde{\the\numexpr3*\bredde/2\relax\space}
\def\radius{3.0 }
\def\afstand{6.5 }
\makeatletter
\newlength\Lafstand \Lafstand=\afstand\p@
\newlength\LafstandB \LafstandB=0.5\Lafstand
\edef\afstand{\strip@pt\Lafstand\noexpand\space}
\edef\afstandB{\strip@pt\LafstandB\noexpand\space}
\makeatother
11
  • Very elegant, Herbert! Apr 25, 2013 at 7:44
  • How can I define \afstandB as half of \afstand? I tried \def\afstand{6.5 } \def\afstandB{\afstand 2 div } (among other things) but then the value of \afstandB is not printed. Apr 27, 2013 at 12:42
  • use a length as shown in my other answers.
    – user2478
    Apr 27, 2013 at 13:06
  • I tried following your idea by using \newlength\afstandB \afstandB=\afstand\psunit \afstandB=\dimexpr\afstand/2 but that is wrong. Apr 27, 2013 at 13:16
  • From this idea I have also tried \newlength\afstandB \afstandB=\afstand\psunit \afstandB=0.5\afstandB but again it fails. Apr 27, 2013 at 13:49
7

I believe this solution is much simpler than the existing ones. Without declaring nodes! :-)

enter image description here

\documentclass[pstricks]{standalone}
\usepackage{pst-node,multido}
\usepackage[locale=DE]{siunitx}


\def\Label#1{\ncput*[nrot=:U]{\large\SI{#1}{\cm}}}

\def\Inner{{%
\psset{xunit=3.25cm,yunit=3cm}
\begin{pspicture}(8,6)
    \bgroup
        \psset{linewidth=3pt}
        \multips(2,3.5)(2,0){3}{\qdisk(0,0){3pt}\pscircle{3cm}}
        \multips(3,2.5)(2,0){2}{\qdisk(0,0){3pt}\pscircle{3cm}}
    \egroup
    \bgroup
        \psset{linestyle=dotted}
        \multips(1,2.5)(0,1){2}{\psline(6,0)}
        \multirput(2,4.5)(1,0){5}{\pcline[nodesep=-.25cm](0,0)(0,-3)}
    \egroup
    \psset{arrows=|*-|*}
    \pcline[offset=-.6cm](2,1.5)(4,1.5)\Label{6.5}
    \pcline[offset=.6cm](2,4.5)(3,4.5)\Label{3.25}
    \pcline[offset=.35cm](1,2.5)(1,3.5)\Label{3.0}
\end{pspicture}}}

\begin{document}
\pspicture(27,18)
    \rput[bl](.5,0){\Inner}
    \psframe[linewidth=3pt](27,18)
    \psset{linestyle=none}
    \pcline[offset=-12pt](0,0)(0,18)\Label{18}
    \pcline[offset=12pt](0,0)(27,0)\Label{27}
\endpspicture
\end{document}
2
  • Is the x/y ratio correct now that it is 18 instead of 15? I would guess that something, e.g. \pcline[offset=-12pt](0,0)(0,6) \pcline[offset=12pt](0,0)(8,0), had to be changed in the code... and maybe something else, but I am not sure. Apr 25, 2013 at 7:22
  • Nice, but I still don't get how it can be (0,6) and (8,0). The lenghts of the side has a ratio of 3/2 but 8/6 != 3/2. Apr 25, 2013 at 7:35
5

Here is a TikZ solution.

First, with dimensions:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}
 \definecolor{r1}{RGB}{0,129,188}
 \definecolor{r2}{RGB}{252,177,49}
 \definecolor{r3}{RGB}{35,34,35}
 \definecolor{r4}{RGB}{0,157,87}
 \definecolor{r5}{RGB}{218,30,38}
 \coordinate (r1) at (-6.5,1.5);
 \coordinate (r2) at (-3.25,-1.5);
 \coordinate (r3) at (0,1.5);
 \coordinate (r4) at (3.25,-1.5);
 \coordinate (r5) at (6.5,1.5);
 \pgfmathsetmacro\whitemargin{1mm}
 \pgfmathsetmacro\radiusout{3cm + .5*\whitemargin pt}
 \pgfmathsetmacro\radiusin{2.5cm - .5*\whitemargin pt}
 \begin{scope}
   \clip (-13.5,0) rectangle (13.5,9);
   \foreach \col in {r5,r4,r3,r2,r1}{
     \path[draw=white,line width=\whitemargin pt,fill=\col,even odd rule]
     (\col) circle (\radiusout pt) circle (\radiusin pt);
   }
 \end{scope}
 \begin{scope}
   \clip (-13.5,-9) rectangle (13.5,0);
   \foreach \col in {r1,r2,r3,r4,r5}{
     \path[draw=white,line width=\whitemargin pt,fill=\col,even odd rule]
     (\col) circle (\radiusout pt) circle (\radiusin pt);
   }
 \end{scope}

 \begin{scope}[on background layer]
   \begin{scope}[font=\Large,line width=.6mm,draw=gray,text=gray,fill=gray]
     \tikzset{
       dim/.style={fill=white,sloped},
       line/.style={|-|,shorten >=-.5\pgflinewidth,shorten <=-.5\pgflinewidth},
     }
     % flag dimensions
     \draw[<->] (-13.5, 8.5) -- node[dim]{27,0~cm} (13.5, 8.5);
     \draw[<->] (-13, -9) -- node[dim]{18,0~cm} (-13, 9);
     % ring centers
     \foreach \center in {r1,r2,r3,r4,r5}{\fill (\center) circle (1mm);}
     % ring dimensions
     \draw[dashed,line width=.3mm]
     (-10.5,0 |- r1) -- (10.5,0 |- r1)
     (-10.5,0 |- r2) -- (10.5,0 |- r2);
     \draw[line] (-10.5,0 |- r2) -- node[dim]{3,0~cm} (-10.5,0 |- r1);
     \foreach \center in {r1,r2,r3,r4,r5}{
       \draw[dashed,line width=.3mm] (\center |- 0,5) -- (\center |- 0,-5);
     }
     \draw[line] (r1 |- 0,5) -- node[dim]{3,25~cm} (r2 |- 0,5);
     \draw[line] (r1 |- 0,-5) -- node[dim]{6,5~cm} (r3 |- 0,-5);
   \end{scope}
 \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

Second without dimension:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}
 \definecolor{r1}{RGB}{0,129,188}
 \definecolor{r2}{RGB}{252,177,49}
 \definecolor{r3}{RGB}{35,34,35}
 \definecolor{r4}{RGB}{0,157,87}
 \definecolor{r5}{RGB}{218,30,38}
 \coordinate (r1) at (-6.5,1.5);
 \coordinate (r2) at (-3.25,-1.5);
 \coordinate (r3) at (0,1.5);
 \coordinate (r4) at (3.25,-1.5);
 \coordinate (r5) at (6.5,1.5);
 \pgfmathsetmacro\whitemargin{1mm}
 \pgfmathsetmacro\radiusout{3cm + .5*\whitemargin pt}
 \pgfmathsetmacro\radiusin{2.5cm - .5*\whitemargin pt}
 \begin{scope}
   \clip (-13.5,0) rectangle (13.5,9);
   \foreach \col in {r5,r4,r3,r2,r1}{
     \path[draw=white,line width=\whitemargin pt,fill=\col,even odd rule]
     (\col) circle (\radiusout pt) circle (\radiusin pt);
   }
 \end{scope}
 \begin{scope}
   \clip (-13.5,-9) rectangle (13.5,0);
   \foreach \col in {r1,r2,r3,r4,r5}{
     \path[draw=white,line width=\whitemargin pt,fill=\col,even odd rule]
     (\col) circle (\radiusout pt) circle (\radiusin pt);
   }
 \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

1
  • Really nice! This will go into my 'nice drawings with LaTeX' directory. :) Nov 24, 2013 at 10:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .