5

Consider the following example:

\documentclass{article}

\usepackage{pstricks-add}

\def\side{%
  \psline(-2,2)(-1,2)
  \psarc(0,2){1}{180}{0}
  \psline(1,2)(2,2)
  \psline(-1,1)(0,2)(1,1)
}

\begin{document}

\def\length{60}
\psset{unit=79pt}
\begin{pspicture}(-2,-2)(2.15,2.15)
  \multido{\iA=0+90,\iB=-2+1}{4}{%
   \psset{offset=12pt,nrot=:U}
    \rput{\iA}(0,0){\side}
    \pcline[linestyle=dotted]{|<*->|*}(\iB,2)(!\iB\space 1 add 2)
    \ncput*{\length\,cm}
    \pcline[linestyle=dotted]{|<*->|*}(!2 \iB\space 1 add)(2,\iB)
    \ncput*{\length\,cm}
  }
\end{pspicture}

\end{document}

output

As can be seen, the curve in not closed. How do I do this (or at least make it look closed; I don't need to fill the inner, so making it look closed is actually enough)?

Note: If someone has a 'simpler' solution than the ones already provided, I would be glad to see it.

  • You can work with \pscustom – Marco Daniel Sep 16 '13 at 11:09
7

As you don't want to fill the region bounded by segments, then linecap=1 will help here! Note that linecap affects the ends of each line rather than the corner (don't confused it with linejoin). For linejoin see my bonus answer.

enter image description here

\documentclass{article}

\usepackage{pstricks-add}

\def\side{%
  \psline(-2,2)(-1,2)
  \psarc(0,2){1}{180}{0}
  \psline(1,2)(2,2)
  \psline(-1,1)(0,2)(1,1)
}

\begin{document}

\def\length{60}
\psset{unit=79pt,linecap=1}
\begin{pspicture}(-2,-2)(2.15,2.15)
  \multido{\iA=0+90,\iB=-2+1}{4}{%
   \psset{offset=12pt,nrot=:U}
    \rput{\iA}(0,0){\side}
    \pcline[linestyle=dotted]{|<*->|*}(\iB,2)(!\iB\space 1 add 2)
    \ncput*{\length\,cm}
    \pcline[linestyle=dotted]{|<*->|*}(!2 \iB\space 1 add)(2,\iB)
    \ncput*{\length\,cm}
  }
\end{pspicture}

\end{document}

Bonus answer

But if you want to change the corner of concatenated lines, then use linejoin.

enter image description here

7
+500

You must draw a closed curve. A line is an opened curve, you can close it e.g. with \pscustom and \closepath. \pscustom can include also \multido constructs. See the following example for different ways:

\documentclass[pstricks, border=3pt]{standalone}
\usepackage{multido}

\begin{document}
\SpecialCoor
\begin{pspicture}(10,2)
\psset{linewidth=10\pslinewidth}

\psline(0,0)(2,0)(2,1)(0,1)(0,0)

\rput(3,0){%
  \pscustom{%
    \psline(0,0)(2,0)(2,1)(0,1)(0,0)
    \closepath
  }%
}%

\rput(6.5,0.8){%
  \psline(1;-45)(1;45)
  \psline(1;45)(1;135)
  \psline(1;135)(1;225)
  \psline(1;225)(1;315)
}

\rput(9,0.8){%
  \pscustom{%
    \moveto(1;-45)
    \multido{\i=45+90}{4}{%
      \psline(1;\i)
    }%
    \closepath
  }%
}%
\end{pspicture}
\end{document}

This gives:

enter image description here

You cannot use \rput inside of \pscustom to position the lines (at the moment don't know the reason for this). So you need to change the \multido part. Here is a part of your document changed to have close curves (maybe there is a more elegant way):

\documentclass{article}

\usepackage{pstricks-add}

\begin{document}

\def\length{60}
\psset{unit=79pt}
\begin{pspicture}(-2,-2)(2.15,2.15)
  \psset{offset=12pt,nrot=:U}
  \pscustom{%
    \moveto(2,2)
    \multido{\iA=-90+-90,\iB=0+-90}{4}{%
      \psarc(2;\iB){1}{!\iB\space 90 add}{!\iB\space 90 sub}
      \rlineto(1;\iA)}
    \closepath
  }
\end{pspicture}

\end{document}
  • Thank you for the illustrative answer! For some reason I cannot get it to work with my example. Can I make you edit your post to include a closed curve for my code? – Svend Tveskæg Sep 16 '13 at 11:20
  • @SvendTveskæg I edited my post and added a part of your document to show how it might work. \rput doesn't work properly inside \pscustom. – Christoph Sep 16 '13 at 11:46
  • Can we have 4 line segments in \pscustom to create a closed curve but each segment has different color? – kiss my armpit Nov 18 '13 at 4:11
  • 1
    @DonutE.Knot No, because \pscustom uses a single path and a single stroke command. – Christoph Nov 18 '13 at 7:21

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.