Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to draw a plane with a hole in its middle. So far, I've only gone around this problem by plotting a white ellipse in the middle of my plane. However, I would like the hole to be actually a transparent field, not white. Here's my 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}

what I've got so far

I would like the white ellipse to be actually transparent. Is this possible ?

share|improve this question

3 Answers 3

up vote 9 down vote accepted

the blue square must also be transparent, because the circle is on the blue not the red:

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

enter image description here

if you want the circle part to be totally clipped you have to use \pscustom for the blue fill area:

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

enter image description here

share|improve this answer
1  
Thank you very much, writing opacity=1 in your code produces exactly the output I want. Accepted ! –  Mathusalem Oct 18 '13 at 20:58
2  
opacity=1 is the default. You do not need that setting –  Herbert Oct 18 '13 at 21:06
    
Why didn't you use eofill here? –  In PSTricks we trust Oct 21 '13 at 9:44

Layman's solution with 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}

enter image description here

share|improve this answer
    
You can use the even odd rule for this: \begin{tikzpicture}[x={(30:1cm)},y={(150:1cm)},z={(90:1cm)}] \filldraw[red,draw=black,thick] (0,0,0) -- (3,0,0) -- (3,3,0) -- (0,3,0) -- cycle; \filldraw[blue,draw=black,thick,even odd rule] (0,0,1) -- (3,0,1) -- (3,3,1) -- (0,3,1) -- cycle (1.5,1.5,1) circle (1); \end{tikzpicture} –  Tom Bombadil Oct 21 '13 at 6:01
    
@TomBombadil You are right. But I didn't want to use z co-ordinate :-) –  Harish Kumar Oct 21 '13 at 6:09

Just for typing practice with 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}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.