问题

问题

我对 的行为有点困惑\reversepath。根据我的调查,它似乎\reversepath会反转所有前面的路径。例如,

\pathA
\pathB
\reversepath

路径 A 和 B 都将被逆转,

\pathA
\pathB
\reversepath
\pathC
\reversepath

仅路径 C 会被反转,并且路径 A 和 B 上的反转将被中和。

为了说明目的,让我举一个简单的例子,其中我想绘制类似房屋的闭合曲线\Outer\Inner如下所示。

\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

在此处输入图片描述

\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

在此处输入图片描述

组合

\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

在此处输入图片描述

问题

在组合中,我希望得到这样的结果:外部和内部都正确绘制,并且两条曲线所包围的区域都用红色填充。更准确地说,内部曲线所包围的区域必须是透明的。

造成缺陷的原因是什么以及如何解决?

平均能量损失

\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}

gradient eofill另一种情况\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}

在此处输入图片描述

笔记

假设使用\reversepath是强制性的。删除它是一种“犯罪”。由于我也对 TikZ 感兴趣,因此只要符合以下要求,TikZ 中的解决方案也受到欢迎:

  • 必须使用反向路径技术从单侧曲线构造闭合曲线,
  • 外部和内部闭合曲线所包围的区域可以用纯色、渐变色、图案甚至剪切的图像来填充。
  • 内部闭合曲线所包围的区域必须是透明的(请不要使用 opacity=0

答案1

\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}

在此处输入图片描述

或者对于eofill这里更有意义的:

\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}

在此处输入图片描述

\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}

在此处输入图片描述

相关内容