5

I am a little bit confused with the behavior of \reversepath. In my investigation, it seems \reversepath will reverse all preceding paths. For example,

\pathA
\pathB
\reversepath

both path A and B will be reversed,

\pathA
\pathB
\reversepath
\pathC
\reversepath

only path C will be reversed and reversing on A and B is neutralized.

For an illustration purpose, let me take a trivial example in which I want to draw house-like closed curves \Outer and \Inner as follows.

Outer

\psline(2,2)(3,4)(4,1)(4,-3)
\reversepath % becomes (4,-3)(4,1)(3,4)(2,2)
\scale{-1 1}
\psline(2,2)(3,4)(4,1)(4,-3) % becomes (-2,2)(-3,4)(-4,1)(-4,-3)
\closepath % line from (-4,-3) to (4,-3) CCW

enter image description here

Inner

\moveto(1,0)
\psline(1,0)(2,1)(3,0)(3,-2)
\reversepath % becomes (3,-2)(3,0)(2,1)(1,0)
\scale{-1 1}
\psline(1,0)(2,1)(3,0)(3,-2) % becomes (-1,0)(-2,1)(-3,0)(-3,-2)
\closepath % line from (-3,-2) to (3,-2) CCW

enter image description here

Combination

\psline(2,2)(3,4)(4,1)(4,-3)
\reversepath % becomes (4,-3)(4,1)(3,4)(2,2)
\scale{-1 1}
\psline(2,2)(3,4)(4,1)(4,-3) % becomes (-2,2)(-3,4)(-4,1)(-4,-3)
\closepath % line from (-4,-3) to (4,-3) CCW

\scale{-1 1} % neutralize the previous scale

\moveto(1,0)
\psline(1,0)(2,1)(3,0)(3,-2)
\reversepath % becomes (3,-2)(3,0)(2,1)(1,0)
\scale{-1 1}
\psline(1,0)(2,1)(3,0)(3,-2) % becomes (-1,0)(-2,1)(-3,0)(-3,-2)
\closepath % line from (-3,-2) to (3,-2) CCW

enter image description here

Question

In the combination, I want to get a result in which both outer and inner are properly drawn and the area bounded by both curves is filled with red. More precisely, the area enclosed by the inner curve must be transparent.

What causes the defect and how to solve it?

MWE

\documentclass[pstricks,border=1cm]{standalone}

\psset
{
    fillstyle=solid,
    fillcolor=red,
    linewidth=5pt,
}


\def\Outer
{
    \psline(2,2)(3,4)(4,1)(4,-3)
    \reversepath % becomes (4,-3)(4,1)(3,4)(2,2)
    \scale{-1 1}
    \psline(2,2)(3,4)(4,1)(4,-3) % becomes (-2,2)(-3,4)(-4,1)(-4,-3)
    \closepath % line from (-4,-3) to (4,-3) CCW
}

\def\Inner
{
    \moveto(1,0)
    \psline(1,0)(2,1)(3,0)(3,-2)
    \reversepath % becomes (3,-2)(3,0)(2,1)(1,0)
    \scale{-1 1}
    \psline(1,0)(2,1)(3,0)(3,-2) % becomes (-1,0)(-2,1)(-3,0)(-3,-2)
    \closepath % line from (-3,-2) to (3,-2) CCW
}

\begin{document}

\begin{pspicture}[showgrid=t](-5,-5)(5,5)
\pscustom{\Outer}
\end{pspicture}

\begin{pspicture}[showgrid=t](-5,-5)(5,5)
\pscustom{\Inner}
\end{pspicture}

\begin{pspicture}[showgrid=t](-5,-5)(5,5)
\pscustom
{
    \Outer  

    \scale{-1 1} % neutralize the previous scale

    \Inner
}
\end{pspicture}
\end{document}

Another scenario with gradient eofill plus \reversepath

\documentclass[pstricks,border=1cm]{standalone}
\usepackage{pst-grad}

\newpsstyle{gradient}
{
    gradbegin=red,
    gradend=yellow,
    gradangle=30,
    gradmidpoint=0.5,
}

\def\Outer{%
    \psline(2,2)(3,4)(4,1)(4,-3)
    \reversepath % becomes (4,-3)(4,1)(3,4)(2,2)
    \scale{-1 1}
    \psline(2,2)(3,4)(4,1)(4,-3) % becomes (-2,2)(-3,4)(-4,1)(-4,-3)
    \closepath % line from (-4,-3) to (4,-3) CCW
}
\def\Inner{%
    \psline[liftpen=2](1,0)(2,1)(3,0)(3,-1)
    \reversepath % becomes (3,-1)(3,0)(2,1)(1,0)
    \scale{-1 1}
    \psline(1,0)(2,1)(3,0)(3,-1) % becomes (-1,0)(-2,1)(-3,0)(-3,-1)
    \closepath % line from (-3,-1) to (3,-1) CCW
}

\begin{document}
\begin{pspicture}[showgrid=b](-5,-5)(5,5)
\pscustom[fillstyle=gradient,fillcolor=red,linewidth=2mm]
{   
    \code{/clip /eoclip load def}
    \Outer
    \code{-1 1 scale} % to neutralize the previous scale
    \reversepath % to neutralize the next reversepath   
    \Inner
}
\end{pspicture}
\end{document}

enter image description here

Note

Assume that using \reversepath is mandatory. Removing it is a "crime". As I am also interested in TikZ, a solution in TikZ is also welcome as long as it conforms to the following requirements:

  • reverse path technique must be used to construct a closed curve from a single side curve,
  • the region bounded by the outer and inner closed curves can be filled with solid color, gradient color, patterns, and even clipped image.
  • the region enclosed by the inner closed curve must be transparent (don't use opacity=0 please)
4
\documentclass[pstricks,border=1cm]{standalone}
\def\Outer{%
    \psline(2,2)(3,4)(4,1)(4,-3)
    \reversepath % becomes (4,-3)(4,1)(3,4)(2,2)
    \scale{-1 1}
    \psline(2,2)(3,4)(4,1)(4,-3) % becomes (-2,2)(-3,4)(-4,1)(-4,-3)
    \closepath % line from (-4,-3) to (4,-3) CCW
}
\def\Inner{%
    \moveto(1,0)
    \psline(1,0)(2,1)(3,0)(3,-2)
    \reversepath % becomes (3,-2)(3,0)(2,1)(1,0)
    \scale{-1 1}
    \psline(1,0)(2,1)(3,0)(3,-2) % becomes (-1,0)(-2,1)(-3,0)(-3,-2)
    \closepath % line from (-3,-2) to (3,-2) CCW
}

\begin{document}
\psset{fillstyle=solid,fillcolor=red,linewidth=5pt,}    
\begin{pspicture}[showgrid=t](-5,-5)(5,5)
    \pscustom{\Outer}
\end{pspicture}

\begin{pspicture}[showgrid=t](-5,-5)(5,5)
    \pscustom{\Inner}
\end{pspicture}

\begin{pspicture}[showgrid=t](-5,-5)(5,5)
    \pscustom[fillstyle=solid,fillcolor=blue!40]{%
        \gsave \Outer \fill[fillcolor=red] \stroke \grestore  
        \Inner
    }
\end{pspicture}
\end{document}

enter image description here

or for an eofill which makes more sense here:

\documentclass[pstricks,border=1cm]{standalone}
\def\OuterInner{%
    \psline(2,2)(3,4)(4,1)(4,-3)(-4,-3)(-4,1)(-3,4)(-2,2)(2,2)
    \moveto(2,1)
    \psline(1,0)(-1,0)(-2,1)(-3,0)(-3,-2)(3,-2)(3,0)
    \closepath
}
\begin{document}
\psset{linewidth=5pt}   
\begin{pspicture}[showgrid=b](-5,-5)(5,5)
    \pscustom[fillstyle=eofill,fillcolor=red]{\OuterInner}
\end{pspicture}
\end{document}

enter image description here

\begin{pspicture}[showgrid=b](-5,-5)(5,5)   
\pscustom[fillstyle=eofill,fillcolor=red]{%
  \psline(0,0)(-1,0)(-2,1)(-3,0)(-3,-2)(0,-2)
  \moveto(0,-3)
  \psline(-4,-3)(-4,1)(-3,4)(-2,2)(0,2)
  \reversepath
  \scale{-1 1}
  \psline(0,0)(-1,0)(-2,1)(-3,0)(-3,-2)(0,-2)
  \moveto(0,-3)
  \psline(-4,-3)(-4,1)(-3,4)(-2,2)(0,2)}
\end{pspicture}

enter image description here

  • set opacity=0.4 or whatever – user2478 Dec 7 '17 at 14:58
  • ir does help. However, see edited answer – user2478 Dec 7 '17 at 15:22

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.