[pstricks] changing hatching linestyle

Denis Girou Denis.Girou at idris.fr
Mon Sep 2 21:02:17 CEST 2002


>>>>> "R.K.Mehta" == R K Mehta <R.K.Mehta> writes:

    R.K.Mehta> I want to change the hatching linestyle which is continuous by default 
    R.K.Mehta> into dotted line. Pl help.

    R.K.Mehta> Here is the example:

    R.K.Mehta> \begin{pspicture}(0,0)(16.0,7.0)
    R.K.Mehta> \psframe[linestyle=dashed,fillstyle=hlines*](4.5,.5)(9.5,5.5)
    R.K.Mehta> ...

    R.K.Mehta> I want to change hlinestyle into dotedline style.

  If the solution sent by Herbert Voss (see also the example of the page 28 in
the PSTricks documentation) is not enough for you needs and if you really want
to have dotted or dashed lines to fill a region, this is not straightforward.
This is not permitted with the existing functionalities and must be added by a
mixture of TeX and PostScript code, adding some new macros and modifying few
existing ones.

  You can try the following code:

\documentclass{article}

\usepackage{pstricks}

\makeatletter

% D.G. addition begin - Sep.  1, 2002

% To define dashed and dotted hatched styles

\def\pshs at solid{0 setlinecap }

\def\pshs at dashed{[ \psk at dash ] 0 setdash }

\def\pshs at dotted{[ 0 \psk at dotsep CLW add ] 0 setdash 1 setlinecap }

\def\psset at hatchstyle#1{%
\@ifundefined{pshs@#1}%
{\@pstrickserr{Hatch style `#1' not defined}\@eha}%
{\edef\pshatchstyle{#1}}}

\psset at hatchstyle{solid}

\def\pst at linefill{%
% D.G. modification begin - Sep.  1, 2002
\@nameuse{pshs@\pshatchstyle}
% D.G. modification end
\psk at hatchangle rotate
\psk at hatchwidth SLW
\pst at usecolor\pshatchcolor
\psk at hatchsep 
\tx at LineFill}

\pst at def{LineFill}<{%
gsave
  abs CLW add
  /a ED
  a 0 dtransform
  round exch round exch 2 copy idtransform
  exch Atan rotate idtransform
  pop
  /a ED
  .25 .25 itransform
  pathbbox
  /y2 ED
  a Div ceiling cvi
  /x2 ED
  /y1 ED
  a Div cvi
  /x1 ED
  /y2 y2 y1 sub def
  clip
  newpath
% D.G. modification begin - Sep.  1, 2002
%  2 setlinecap
% D.G. modification end
  systemdict
  /setstrokeadjust
    known { true setstrokeadjust } if
    x2 x1 sub 1 add
    { x1 a mul y1 moveto
      0 y2 rlineto
      stroke
      /x1 x1 1 add def } repeat
  grestore
pop pop}>

\makeatother

\pagestyle{empty}

\begin{document}

\begin{figure}
  \begin{pspicture}(3.5,0)(14.8,6.8)
    \psframe[fillstyle=hlines](4.5,.5)(9.5,5.5)
    \pscircle[fillstyle=solid,fillcolor=white](7,3){1.5}
    \psline{->}(3.5,3)(11.5,3)
    \psline(7,0)(7,2)
    \psline(7.0,2.5)(7,3.5)
    \psline{->}(7.0,4.0)(7,6.3)
    \rput(7.1,6.5){$j$Im[z]}
    \rput[l](11.6,3){Re[z]}
    \rput[r](6.8,4.7){Unstable}
    \rput[l](7.2,4.7){Unstable}
    \rput[r](6.8,1.1){Unstable}
    \rput[l](7.2,1.1){Unstable}
    \rput(7,2.2){Stable}
    \rput(7,3.7){Stable}
    \rput[l](10,4.5){Unshaded Area: Stable Region}
    \rput[l](10,4.0){Shaded Area: Unstable Region}
  \end{pspicture}
  \caption{Showing stable(unshaded) and unstable(shaded) region in z-plane}
\end{figure}

\begin{figure}
  \begin{pspicture}(3.5,0)(14.8,6.8)
    \psframe[fillstyle=hlines,hatchstyle=dotted](4.5,.5)(9.5,5.5)
    \pscircle[fillstyle=solid,fillcolor=white](7,3){1.5}
    \psline{->}(3.5,3)(11.5,3)
    \psline(7,0)(7,2)
    \psline(7.0,2.5)(7,3.5)
    \psline{->}(7.0,4.0)(7,6.3)
    \rput(7.1,6.5){$j$Im[z]}
    \rput[l](11.6,3){Re[z]}
    \rput[r](6.8,4.7){Unstable}
    \rput[l](7.2,4.7){Unstable}
    \rput[r](6.8,1.1){Unstable}
    \rput[l](7.2,1.1){Unstable}
    \rput(7,2.2){Stable}
    \rput(7,3.7){Stable}
    \rput[l](10,4.5){Unshaded Area: Stable Region}
    \rput[l](10,4.0){Shaded Area: Unstable Region}
  \end{pspicture}
  \caption{Showing stable(unshaded) and unstable(shaded) region in z-plane}
\end{figure}

\begin{figure}
  \begin{pspicture}(3.5,0)(14.8,6.8)
    \psframe[fillstyle=hlines,hatchstyle=dashed,dash=0.3 0.15]
            (4.5,.5)(9.5,5.5)
    \pscircle[fillstyle=solid,fillcolor=white](7,3){1.5}
    \psline{->}(3.5,3)(11.5,3)
    \psline(7,0)(7,2)
    \psline(7.0,2.5)(7,3.5)
    \psline{->}(7.0,4.0)(7,6.3)
    \rput(7.1,6.5){$j$Im[z]}
    \rput[l](11.6,3){Re[z]}
    \rput[r](6.8,4.7){Unstable}
    \rput[l](7.2,4.7){Unstable}
    \rput[r](6.8,1.1){Unstable}
    \rput[l](7.2,1.1){Unstable}
    \rput(7,2.2){Stable}
    \rput(7,3.7){Stable}
    \rput[l](10,4.5){Unshaded Area: Stable Region}
    \rput[l](10,4.0){Shaded Area: Unstable Region}
  \end{pspicture}
  \caption{Showing stable(unshaded) and unstable(shaded) region in z-plane}
\end{figure}

\begin{figure}
  \begin{pspicture}(3.5,0)(14.8,6.8)
    \psframe[fillstyle=vlines,hatchstyle=dashed,hatchsep=0.4,hatchcolor=red]
            (4.5,.5)(9.5,5.5)
    \pscircle[fillstyle=solid,fillcolor=white](7,3){1.5}
    \psline{->}(3.5,3)(11.5,3)
    \psline(7,0)(7,2)
    \psline(7.0,2.5)(7,3.5)
    \psline{->}(7.0,4.0)(7,6.3)
    \rput(7.1,6.5){$j$Im[z]}
    \rput[l](11.6,3){Re[z]}
    \rput[r](6.8,4.7){Unstable}
    \rput[l](7.2,4.7){Unstable}
    \rput[r](6.8,1.1){Unstable}
    \rput[l](7.2,1.1){Unstable}
    \rput(7,2.2){Stable}
    \rput(7,3.7){Stable}
    \rput[l](10,4.5){Unshaded Area: Stable Region}
    \rput[l](10,4.0){Shaded Area: Unstable Region}
  \end{pspicture}
  \caption{Showing stable(unshaded) and unstable(shaded) region in z-plane}
\end{figure}

\end{document}


D.G.



More information about the PSTricks mailing list