Graphics, Figures & TablesFill a plane in TikZ

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
mas
Posts: 226
Joined: Thu Dec 04, 2008 4:39 am

Fill a plane in TikZ

Post by mas »

Using TikZ 3d coordinate system, I can easily create a cube. I would like to drawa plane and fill the same with a certain color and opacity. In the code below, I would like to fill the plane DHFB with a color. I could not get the desired result. Any help/pointers would be helpful.

Code: Select all

\documentclass[svgnames,serif]{beamer}
%
\usepackage{tikz}
  \usetikzlibrary{calc}

\mode<presentation>
\setbeamertemplate{navigation symbols}{}

\begin{document}

\begin{frame}
\frametitle{Cube}
  \begin{center}
 
   \begin{tikzpicture}[scale=4]
     \node (a) at (0,0,0) [label=left:{$A$}] {} ;
     \node (b) at (1,0,0) [label=right:{$B$}] {} ;
     \node (c) at (1,0,1) [label=right:{$C$}] {} ;
     \node (d) at (0,0,1) [label=left:{$D$}] {} ;
     \node (e) at (0,1,0) [label=left:{$E$}] {} ;
     \node (f) at (1,1,0) [label=right:{$F$}] {} ;
     \node (g) at (1,1,1) [label=right:{$G$}] {} ;
     \node (h) at (0,1,1) [label=left:{$H$}] {} ;

     \draw (a) -- (b) (b) -- (c) (c) -- (d) (d) -- (a) 
           (e) -- (f) (f) -- (g) (g) -- (h) (h) -- (e)
           (a) -- (e) (b) -- (f) (c) -- (g) (d) -- (h)
           ;

     \filldraw [draw=black,fill=blue,opacity=0.3] 
        (d) -- (h) -- (f) -- (b) -- (d) -- cycle ;

     \foreach \x in {a,b,...,h} 
       \node[inner sep=2pt,draw=black,fill=lightgray,shape=circle]
           at (\x) {} ;

   \end{tikzpicture}

  \end{center}
\end{frame}

\end{document}
Regards.

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

Fill a plane in TikZ

Post by CrazyHorse »

mas wrote: In the code below, I would like to fill the plane DHFB with a color. I could not get the desired result. Any help/pointers would be helpful.

Code: Select all

     \filldraw [draw=black,fill=blue,opacity=0.3] 
        (d) -- (h) -- (f) -- (b) -- (d) -- cycle ;
it does not like node names here. This works:

Code: Select all

     \filldraw [draw=black,fill=blue,opacity=0.5] 
       
         (0,0,1)--(0,1,1)--(1,1,0)--(1,0,0)--(0,0,1)--cycle ;

mas
Posts: 226
Joined: Thu Dec 04, 2008 4:39 am

Re: Fill a plane in TikZ

Post by mas »

Thanks for the answer. But, it defeats the purpose of using labelled coordinates/nodes. Are there any workarounds? It becomes tedious to write coordinates all the time.

Regards.

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim
User avatar
shadgrind
Posts: 140
Joined: Thu Jul 16, 2009 12:39 am

Fill a plane in TikZ

Post by shadgrind »

Define (a),...,(h) as coordinates, not as nodes:

Code: Select all

  \coordinate[label=left:{$A$}] (a) at (0,0,0);
  \coordinate[label=right:{$B$}] (b) at (1,0,0);
  \coordinate[label=right:{$C$}] (c) at (1,0,1);
  \coordinate[label=left:{$D$}] (d) at (0,0,1);
  \coordinate[label=left:{$E$}] (e) at (0,1,0);
  \coordinate[label=right:{$F$}] (f) at (1,1,0);
  \coordinate[label=right:{$G$}] (g) at (1,1,1);
  \coordinate[label=left:{$H$}] (h) at (0,1,1);
Your \filldraw command will then work, and everything else in your code will still work the same.
System: TeX Live 2012, Fedora 18 x86_64, GNU Emacs 24.2
mas
Posts: 226
Joined: Thu Dec 04, 2008 4:39 am

Re: Fill a plane in TikZ

Post by mas »

That solved my problem. Thanks for the help.

Regards.

OS: Debian/GNU Linux; LaTeX System : TeXLive; Editor : Vim
Post Reply