tikz add tag
Anonymous 1123
I want to draw and make animate solid when  I rotate this figure around the line `CD`. 
![ScreenHunter 853.png](/image?hash=6636c455fd6612ff991fb82cdbcceb3a896998d6b7be6dfd61cc3c69702cf70e) 

I do not how to start. Hot to get it?
Top Answer
marmot
This question is conceptually almost the same as your previous [question on the tetrahedron](https://topanswers.xyz/tex?q=1349), so we can recycle a lot of things from there. Basically you can use routines like `draw face with corners` for an arbitrary polyhedron as long as it is sufficiently convex. In the case at hand, there is however one plane which needs to be treated separately. Please note that if you have updated your pgf installation to 3.1.6, you need to get the [newest version of `3dtools`](https://github.com/marmotghost/tikz-3dtools).

```
\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3dtools}% https://github.com/marmotghost/tikz-3dtools
\makeatletter
% something like this may go into the 3dtools library
\tikzset{3d/.cd,polyhedron/.cd,
draw face with corners/.code={\begingroup\c@pgf@counta0\relax
\pgfutil@for\pgfutil@tmpa:={#1}\do{%
\pgfmathsetmacro\pgfutil@tmpT{TD("\pgfutil@tmpa")}%
\ifcase\c@pgf@counta 
\pgfmathsetmacro\pgfutil@tmpA{TD("\pgfutil@tmpa")}%
\or
\pgfmathsetmacro\pgfutil@tmpB{TD("\pgfutil@tmpa")}%
\or
\pgfmathsetmacro\pgfutil@tmpC{TD("\pgfutil@tmpa")}%
\fi
\advance\c@pgf@counta by1\relax
\ifnum\c@pgf@counta=1\relax
\edef\pgfutil@tmpl{(\pgfutil@tmpT)}%
\else
\edef\pgfutil@tmpl{\pgfutil@tmpl -- (\pgfutil@tmpT)}%
\fi
}%
\ifnum\c@pgf@counta<3\relax
\typeout{A face needs at least three vertices. However, only \the\c@pgf@counta\space vertices were specified.}%
\else
\edef\pgfutil@tmpO{\pgfkeysvalueof{/tikz/3d/polyhedron/O}}%
\pgfmathsetmacro\pgfutil@tmpO{TD("\pgfutil@tmpO")}%
\edef\pgfutil@tmpL{\pgfkeysvalueof{/tikz/3d/polyhedron/L}}%
\pgfmathsetmacro\pgfutil@tmpL{TD("\pgfutil@tmpL")}%
\pgfmathsetmacro{\pgfutil@tmpb}{TD("(\pgfutil@tmpB)-(\pgfutil@tmpA)x(\pgfutil@tmpC)-(\pgfutil@tmpA)")}% 
\pgfmathsetmacro{\pgfutil@tmpc}{TD("(\pgfutil@tmpA)-(\pgfutil@tmpO)")}% 
\pgfmathtruncatemacro{\pgfutil@tmpd}{sign(TD("(\pgfutil@tmpb)o(\pgfutil@tmpc)"))}%
\ifnum\pgfutil@tmpd=-1\relax
\pgfmathsetmacro{\pgfutil@tmpb}{TD("(\pgfutil@tmpB)-(\pgfutil@tmpA)x(\pgfutil@tmpA)-(\pgfutil@tmpC)")}% 
\fi
\pgfmathsetmacro{\pgfutil@tmpe}{screendepth(\pgfutil@tmpb)}%
\pgfmathsetmacro{\pgfutil@tmpf}{sqrt(TD("(\pgfutil@tmpb)o(\pgfutil@tmpb)"))}%
\pgfmathsetmacro{\pgfutil@tmpg}{sqrt(TD("(\pgfutil@tmpL)o(\pgfutil@tmpL)"))}%
\pgfmathsetmacro{\pgfutil@tmph}{TD("(\pgfutil@tmpL)o(\pgfutil@tmpb)")/\pgfutil@tmpf/\pgfutil@tmpg}%
\pgfmathtruncatemacro{\pgfutil@tmpi}{70+30*\pgfutil@tmph}%
\pgfmathtruncatemacro{\pgfutil@tmpi}{\pgfkeysvalueof{/tikz/3d/polyhedron/shading function}(\pgfutil@tmph)}%
\ifdim\pgfutil@tmpe pt<0pt\relax
\begin{pgfonlayer}{\pgfkeysvalueof{/tikz/3d/polyhedron/back layer}}
\tikzset{3d/polyhedron/before hidden}%
\draw[fill=tikz@td@face@color!\pgfutil@tmpi!black,3d/polyhedron/back] \pgfutil@tmpl -- cycle;
\tikzset{3d/polyhedron/before hidden}%
\end{pgfonlayer}
\else
\begin{pgfonlayer}{\pgfkeysvalueof{/tikz/3d/polyhedron/fore layer}}
\tikzset{3d/polyhedron/before visible}%
\draw[fill=tikz@td@face@color!\pgfutil@tmpi!black,3d/polyhedron/fore] \pgfutil@tmpl -- cycle;
\tikzset{3d/polyhedron/after visible}%
\end{pgfonlayer}
\fi
\fi
\endgroup
},
color/.code={\colorlet{tikz@td@face@color}{#1}},color=yellow,
O/.initial={(0,0,0)},% point inside the polyhedron
L/.initial={(1,1,1)},% "light source",
fore/.style={draw,solid},fore layer/.initial=foreground,
back/.style={draw,dashed,fill opacity=0},back layer/.initial=background,
shading function/.initial={tikztdpolyhedronshade},
/tikz/declare function={tikztdpolyhedronshade(\x)=70+30*\x;},
before visible/.code={},after visible/.code={},
before hidden/.code={},after hidden/.code={},
}%
\makeatother
\pgfdeclarelayer{background} 
\pgfdeclarelayer{foreground}
\pgfdeclarelayer{behind}  
\pgfsetlayers{behind,background,main,foreground}
\tikzset{% https://tex.stackexchange.com/a/76216
even odd clip/.code={\pgfseteorule}}
\begin{document}
\tdplotsetmaincoords{80}{20}
\foreach \Angle in {5,15,...,355}
{\begin{tikzpicture}[tdplot_main_coords,line join=round,line cap=round,
	declare function={L=2;l=1;d=1;}]
 \path[tdplot_screen_coords,use as bounding box]	
 	(-0.75*L,-1.75*L) rectangle (1.75*L,1.75*L);
 \path (1,0,0) coordinate (ex) 
    (0,1,0) coordinate (ey)
 	(0,{cos(\Angle)},{sin(\Angle)}) coordinate (ey') 
	 (0,{-sin(\Angle)},{cos(\Angle)}) coordinate (ez') ;	 
 \begin{scope}[x={(ex)},y={(ey')},z={(ez')}]	
 \path (0,0,0) coordinate (D)
 	  (L,0,0) coordinate (C)
	  (L,-L,0) coordinate (B)
	  (0,-L,0) coordinate (A)
	  (0,-L,L) coordinate (A2)
	  (l,-L,L) coordinate (B2)
	  (l,0,L) coordinate (C2)
	  (0,0,L) coordinate (D2)
	  (l,-L,L-l) coordinate (A1)
	  (l,0,L-l) coordinate (D1)
	  (L,-L,L-l) coordinate (B1)
	  (L,0,L-l) coordinate (C1)
	  (l/2,-l,l) coordinate (O');
 \begin{scope}[canvas is yz plane at x=0]
  \draw[thick,blue]  let \p1=($(D)-(A)$),\n1={veclen(\y1,\x1)} in
  (A) arc[start angle=180,end angle=180-1*\Angle,radius=\n1]
   let \p2=($(D)-(A2)$),\n2={veclen(\y2,\x2)} in 
  (A2) arc[start angle=180-45,end angle=180-45-1*\Angle,radius=\n2];
 \end{scope}
 \tikzset{3d/polyhedron/.cd,O={(O')},
 	fore/.append style={fill opacity=0.6,thick,solid},
 	back/.append style={fill opacity=0.6,dashed,thin},
 	draw face with corners={{(A)},{(B)},{(B1)},{(A1)},{(B2)},{(A2)}},
	draw face with corners={{(D)},{(C)},{(C1)},{(D1)},{(C2)},{(D2)}},	
	draw face with corners={{(A)},{(B)},{(C)},{(D)}},
	draw face with corners={{(A2)},{(B2)},{(C2)},{(D2)}},
	draw face with corners={{(A)},{(A2)},{(D2)},{(D)}},
	draw face with corners={{(B)},{(B1)},{(C1)},{(C)}},
	draw face with corners={{(A1)},{(B1)},{(C1)},{(D1)}}}	
  \pgfmathtruncatemacro{\itest}{(screendepth(0,1,0)>0)}	  
  \ifnum\itest=1
   \tikzset{my path/.style={insert path={
   	(D) -- (A) -- (B) -- (C) -- (C1) -- (D1) -- (C2) -- (D2) -- cycle}}}
  \else
   \tikzset{my path/.style={insert path={
	(A) -- (D) -- (C) -- (B) -- (B1) -- (A1) -- (B2) -- (A2) -- cycle}}}
  \fi	
  \begin{scope}	
   \begin{scope}% clip on the covered area and use fake O
   \tikzset{3d/polyhedron/.cd,O={(L,-l,l)},
   	before hidden/.code={\clip [my path];},
    draw face with corners={{(A1)},{(B2)},{(C2)},{(D1)}}}	
   \end{scope}	
   % clip on the uncovered area
   \tikzset{3d/polyhedron/.cd,before visible/.code={
   \clip[even odd clip] 
	(current bounding box.south west) -- (current bounding box.south east)
	-- (current bounding box.north east) -- (current bounding box.north west)
	-- cycle [my path];},
    draw face with corners={{(A1)},{(B2)},{(C2)},{(D1)}}}	
  \end{scope}
 \end{scope}	  
\end{tikzpicture}}
\end{document}
```
![ani.gif](/image?hash=640b426ed36e6796f9f17421acae7812110249cda02ab6f7dd6de48cf02985be)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.