使用 pst-3dplot 绘制挤压物体

使用 pst-3dplot 绘制挤压物体

我想画一个中间有一个洞的平面。到目前为止,我只通过在平面中间绘制一个白色椭圆来解决这个问题。然而,我希望这个洞实际上是一个透明的区域,而不是白色的。这是我的 mwe

\documentclass[11pt]{article}
\usepackage{pstricks-add}
\usepackage{auto-pst-pdf}
\usepackage{pst-3dplot}

\begin{document}
\begin{pspicture}(-5,-5)(5,5)

\pstThreeDSquare[fillcolor=red,fillstyle=solid](0,0,0)(0,2,0)(2,0,0)
\pstThreeDSquare[fillcolor=blue,fillstyle=solid](0,0,0.8)(0,2,0)(2,0,0)
\pstThreeDEllipse[fillcolor=white,fillstyle=solid](1,1,0.8)(0,0.5,0)(0.5,0,0)

\end{pspicture}

\end{document}

我目前得到的东西

我希望白色椭圆实际上是透明的。这可能吗?

答案1

蓝色正方形也必须是透明的,因为圆圈在蓝色上而不是红色上:

\documentclass[11pt]{article}
\usepackage{auto-pst-pdf}
\usepackage{pst-3dplot}

\begin{document}
\begin{pspicture}(-5,-5)(5,5)
\pstThreeDSquare[fillcolor=red,fillstyle=solid](0,0,0)(0,2,0)(2,0,0)
\pstThreeDSquare[fillcolor=blue,fillstyle=solid,opacity=0.5](0,0,0.8)(0,2,0)(2,0,0)
\pstThreeDEllipse[fillcolor=white,fillstyle=solid,opacity=0.5](1,1,0.8)(0,0.5,0)(0.5,0,0)
\end{pspicture}

\end{document}

在此处输入图片描述

如果您希望圆形部分被完全剪掉,则必须使用\pscustom蓝色填充区域:

\documentclass[pstricks]{standalone}
\usepackage{pst-3dplot}

\begin{document}
\begin{pspicture}(-2,-2)(2,1)
\pstThreeDSquare[fillcolor=red,fillstyle=solid](0,0,0)(0,2,0)(2,0,0)
\pscustom[fillcolor=blue,fillstyle=solid,opacity=0.5,linestyle=none]{%
  \pstThreeDLine(0,2,0.8)(0,0,0.8)(2,0,0.8)(2,2,0.8)(1,2,0.8)(1,1.5,0.8)%3 1/2 lines and a line to the circle
  \pstThreeDEllipse(1,1,0.8)(0,0.5,0)(0.5,0,0)
  \pstThreeDLine(1,1.5,0.8)(1,2,0.8)(0,2,0.8)% Back to the square 
}
\pstThreeDSquare(0,0,0.8)(0,2,0)(2,0,0)
\pstThreeDEllipse(1,1,0.8)(0,0.5,0)(0.5,0,0)
\end{pspicture}

\end{document}

在此处输入图片描述

答案2

外行人可以用 来解答tikz

\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikzset{
    invclip/.style={
        clip,
        insert path={{[reset cm](-16383.99999pt,-16383.99999pt) rectangle (16383.99999pt,16383.99999pt)}}
    }
}
%
\begin{tikzpicture}
\draw[fill = red, opacity = 0.5] (-4,0) -- (0,-2) -- (4,0) -- (0,2) -- cycle;
\begin{scope}[yshift=2cm]
    \begin{pgfinterruptboundingbox}
        \path [invclip] (0,2) circle (1.5cm and .75cm);
    \end{pgfinterruptboundingbox}
    \draw[fill = blue, opacity = 0.5] (-4,0) -- (0,-2) -- (4,0) -- (0,2) -- cycle;
\end{scope}
\end{tikzpicture}
%
\end{document}

在此处输入图片描述

答案3

仅用于使用 PSTricks 进行打字练习。

\documentclass[pstricks,border=12pt]{standalone}

\begin{document}
\begin{pspicture}(6,6)
    \pspolygon[fillstyle=solid,fillcolor=red](0,2)(3,0)(6,2)(3,4)
    \pscustom[fillcolor=blue,opacity=.5,fillstyle=eofill]
    {
        \translate(0,2)
        \pspolygon(0,2)(3,0)(6,2)(3,4)
        \moveto(4.5,2)
        \psellipse(3,2)(1.5,.5)
    }
\end{pspicture}
\end{document}

在此处输入图片描述

相关内容