6

Consider the following example.

Code

\documentclass{article}

\usepackage{pstricks-add}

\begin{document}

\begin{figure}
\psset{unit=0.05}
 \begin{pspicture}(120,216)
  \pnodes{P}(0,0)(0,120)(186,120)(216,120)(216,0)(186,0)(186,30)(186,90)
  \pspolygon(P0)(P1)(P3)(P4)
  \pcline[offset=12pt]{|<->|}(P1)(P3)
  \ncput*[nrot=:U]{216}
  \pcline[offset=12pt]{|<->|}(P3)(P4)
  \ncput*[nrot=:U]{120}
  \pspolygon[linestyle=none,fillstyle=vlines](P2)(P3)(P4)(P5)
  \pswedge[linestyle=none,fillstyle=solid,fillcolor=white](P6){30}{270}{90}
  \pswedge[linestyle=none,fillstyle=solid,fillcolor=white](P7){30}{270}{90}
  \psarc(P6){30}{270}{90}
  \psarc(P7){30}{270}{90}
  \psdot(P6)
  \psdot(P7)
 \end{pspicture}
\end{figure}

\end{document}

Output

enter image description here

Question

The code above seems to be the wrong way of creating the figure. I guess \pscustom is the way to go, but I cannot figure out how to use it; how do I produce the figure in the "best" way using PSTricks? (I would very much like to see how it is done and not just get a comment about using this or that.)

2 Answers 2

6

Two frames and two arcs or \pscustom:

\documentclass{article}
\usepackage{pstricks-add}
\begin{document}

\psset{unit=1pt}
\begin{pspicture}(240,140)
\psframe[dimen=middle](216,120)
\psframe[fillstyle=vlines,linestyle=none](186,0)(216,120)
\psarc[fillstyle=solid,fillcolor=white](186,30){30}{-90}{90}
\psarc[fillstyle=solid,fillcolor=white](186,90){30}{-90}{90}
\psdots(186,30)(186,90)
\pcline[offset=12pt]{|<->|}(0,120)(216,120) \ncput*{216}
\pcline[offset=12pt]{|<->|}(216,120)(216,0) \ncput*[nrot=:U]{120}
\end{pspicture}

\begin{pspicture}(240,140)
\psframe[dimen=middle](216,120)
\pscustom[fillstyle=vlines,hatchcolor=red]{%
  \psarc(186,30){30}{-90}{90}
  \psarc(186,90){30}{-90}{90}
  \psline(186,120)(216,120)(216,0)
}
\psdots(186,30)(186,90)
\pcline[offset=12pt]{|<->|}(0,120)(216,120) \ncput*{216}
\pcline[offset=12pt]{|<->|}(216,120)(216,0) \ncput*[nrot=:U]{120}
\end{pspicture}

\end{document}

enter image description here

Since \psframe draws a closed path (required for proper clipping), it can also be added as the last component in \pscustom if one uses the clipping function:

\documentclass{article}
\usepackage{pstricks-add}% http://tug.org/PSTricks/main.cgi/
\begin{document}

\begin{figure}
\psset{unit=1pt}
\begin{pspicture}(240,140)
\psclip{\psset{linestyle=solid}
  \pscustom{
    \psarc(186,30){30}{-90}{90}
    \psarc(186,90){30}{-90}{90}
    \psframe[dimen=middle](216,120)
  }
}
  \psframe[fillstyle=vlines,linestyle=none](186,0)(216,120)
\endpsclip
\psdots(186,30)(186,90)
\pcline[offset=12pt]{|<->|}(0,120)(216,120) \ncput*{216}% Top dimension
\pcline[offset=12pt]{|<->|}(216,120)(216,0) \ncput*[nrot=:U]{120}% Right dimension
\end{pspicture}
\end{figure}

\end{document}

This also works because of the structure and the way \psframe is drawn (counter-clockwise from middle-left.

4
  • @Herbert Nice! Do you recommend one of the ideas over the other? Apr 3, 2013 at 19:37
  • @SvendMortensen: that depends ... ;-) if I have enough time then I'd use \pscustom ...
    – user2478
    Apr 3, 2013 at 19:42
  • @Werner: Now I understand. That is the complicated variant, because it needs the additional clipping.
    – user2478
    Apr 4, 2013 at 6:46
  • Really nice with three different versions! :-) Apr 4, 2013 at 7:59
1

I am trying to improve the existing answers.

  • Arrow specifier |<->| should be changed to |<*->|* to make the |-like tips properly aligned.
  • It is better to globally pass dimen=middle to \pscustom rather than locally specifying it to every single command which has dimen=outer by default.
  • As the clipped region is drawn after stroking the clipper path, in general it is necessary to stroke again the clipper path after clipping.

    If you want to understand what I mean, I have added hatchcolor=red,hatchsep=1pt to the clipped \psframe in Werner's edit. Originally Werner's setting is hatchcolor=black so it is unnoticeable but now with the color change, the "defect" is visually obvious as follows.

    enter image description here

    That is why restroking is needed after clipping.

  • Using unit=1pt should be avoided because the navigation grid becomes messy.

enter image description here

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-node}
\def\Path[#1]{%
  \pscustom[dimen=middle,#1]{
    \psarc(186,30){30}{-90}{90}
    \psarc(186,90){30}{-90}{90}
    \psframe(216,120)
  }\ignorespaces
}

\begin{document}

\psset{unit=1pt,linewidth=3pt}
\begin{pspicture}(240,140)
\psclip{\Path[linestyle=none]}
  \psframe[fillstyle=vlines,hatchcolor=red,hatchsep=1pt,linestyle=none](186,0)(216,120)
\endpsclip
\Path[]
\psdots(186,30)(186,90)
\pcline[offset=12pt]{|<*->|*}(0,120)(216,120) \ncput*{216}% Top dimension
\pcline[offset=12pt]{|<*->|*}(216,120)(216,0) \ncput*[nrot=:U]{120}% Right dimension
\end{pspicture}

\end{document}
0

You must log in to answer this question.

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