add tag
Anonymous 1123
Let be given a pyramid `SABCD` with `SA` perpendicular to the plan `ABC`, `SA = h`, base of piramid is a ractangle with `AB=a`, `AD=b`. The point `M` lies on the segment `SA`. Let be `P1` is the plane passing through `M` and parallel to the plane `xy`, The plane `P1` intersects the lines `SB, SC, SD` at `N, P, Q` ,  respectively. Draw the cylinder has height `AM` and a base is circumcicle of `MNPQ.` I tried
```
\documentclass[border=1mm,12pt,tikz]{standalone}
\usetikzlibrary{3dtools,calc}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
	\foreach \Angle in {150}  
	{\begin{tikzpicture}[3d/install view={phi=\Angle,psi=0,theta=70},
			line join = round, line cap = round,same bounding box=A,c/.style={circle,fill,inner sep=1pt},
			declare function={a=4;b=4;h=5;H=3;}]
			\path 
			(0,0,0) coordinate (A) (a,0,0) coordinate (B)
			(a,b,0) coordinate (C) (0,b,0) coordinate (D)
			(0,0,h) coordinate (S)
			(0,0,H)	 coordinate (M)
			;
			
			\path[3d/plane with normal={(0,0,1) through (M) named p},3d/plane with normal={(0,0,1) through (0,0,0) named p1},3d/line through={(S) and (B) named lSB},3d/line through={(S) and (C) named lSC},3d/line through={(S) and (D) named lSD}];
			\path[3d/intersection of={lSB with p}] coordinate (N);	
			\path[3d/intersection of={lSC with p}] coordinate (P);	
			\path[3d/intersection of={lSD with p}] coordinate (Q);	
			\path[3d coordinate ={(O') =0.5*(M) + 0.5*(P)}];
			\path[3d/project={(N) on p1}] coordinate (E);
			\path[3d/project={(P) on p1}] coordinate (F);
			\path[3d/project={(Q) on p1}] coordinate (G);	
			\path[3d/project={(O') on p1}] coordinate (O);
			
			\pgfmathsetmacro{\myr}{tddistance("(O)","(A)")}
			\pgfmathsetmacro{\mybarycenter}{barycenter("(A),(B),(C),(D),(S)")}
			\path (\mybarycenter) coordinate (O''); 
			\tikzset{3d/polyhedron/.cd,O={(O'')},
				fore/.append style={fill=none,/tikz/3d/visible}, 
				back/.append style={fill=none,/tikz/3d/hidden},
				draw face with corners={{(A)},{(B)},{(C)},{(D)}},
				draw face with corners={{(S)},{(A)},{(B)}},
				draw face with corners={{(S)},{(B)},{(C)}},
				draw face with corners={{(S)},{(C)},{(D)}},
				draw face with corners={{(S)},{(A)},{(D)}}
			} 
			
			\path (O)		pic{3d/frustum={R=\myr,r=\myr,h=H}};
			
			
			\path foreach \p/\g in {A/90,B/90,C/200,D/-90,S/0,M/0,N/0,P/0,Q/0,O'/0,E/0,F/0,G/0,O/0}
			{(\p)node[c]{}+(\g:2.5mm) node{$\p$}}; 			
	\end{tikzpicture}}	
\end{document}    
```
I got
![ScreenHunter 180.png](/image?hash=3b53ef40d5d73d0e0098d6466979d6aa938cff82d3619b21cc83820ebbc2ae53)

I tried to draw with GeoSpace 

![ScreenHunter 177.png](/image?hash=625846e84797ee794b1e186fcedbc0f8720853b5864c32585f13b7dcce522b7f)

![ScreenHunter 182.png](/image?hash=71319a7a35f4d6bc425011dc960b04b272cfb7252d05964f5cec535d9217bbbe)

![ScreenHunter 181.png](/image?hash=b97376b4b2aa93a4911d315816b5fd07421b00322979966ba8215e13af6a84e6)

How to correct my code?
Top Answer
user 3.14159
I added a number of comments in the code. I also added a new key to the [3dtools library](https://github.com/marmotghost/tikz-3dtools), so you will need the latest version. You can use `draw ordered paths` as well as the new key `draw open face with corners` here.
```
\documentclass[border=1mm,12pt,tikz]{standalone}
\usetikzlibrary{3dtools,calc}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
\foreach \Angle in {5,15,...,355}  
{\begin{tikzpicture}[3d/install view={phi=\Angle,psi=0,theta=70},
		line join = round, line cap = round,same bounding box=A,
		c/.style={circle,fill,inner sep=1pt},
		declare function={a=4;b=4;h=5;H=3;}]
  \path 
	(0,0,0) coordinate (A) (a,0,0) coordinate (B)
	(a,b,0) coordinate (C) (0,b,0) coordinate (D)
	(0,0,h) coordinate (S) (0,0,H)	 coordinate (M);

  \path[3d/plane with normal={(0,0,1) through (M) named p},3d/plane with normal={(0,0,1) through (0,0,0) named p1},3d/line through={(S) and (B) named lSB},3d/line through={(S) and (C) named lSC},3d/line through={(S) and (D) named lSD}];
  \path[3d/intersection of={lSB with p}] coordinate (N);	
  \path[3d/intersection of={lSC with p}] coordinate (P);	
  \path[3d/intersection of={lSD with p}] coordinate (Q);	
  \path[3d coordinate ={(O') =0.5*(M) + 0.5*(P)}];
  \path[3d/project={(N) on p1}] coordinate (E);
  \path[3d/project={(P) on p1}] coordinate (F);
  \path[3d/project={(Q) on p1}] coordinate (G);	
  \path[3d/project={(O') on p1}] coordinate (O);

  \pgfmathsetmacro{\myr}{tddistance("(O)","(A)")}
  \pgfmathsetmacro{\mybarycenter}{barycenter("(A),(B),(C),(D),(S)")}
  \path (\mybarycenter) coordinate (O''); 
  \tikzset{3d/polyhedron/.cd,O={(O'')},
	  fore/.append style={fill=none,/tikz/3d/visible}, 
	  back/.append style={fill=none,/tikz/3d/hidden},
	  draw open face with corners={{(M)},{(S)},{(Q)}},
	  draw open face with corners={{(M)},{(S)},{(N)}},
	  draw open face with corners={{(P)},{(S)},{(N)}},
	  draw open face with corners={{(P)},{(S)},{(Q)}},
	  draw open face with corners={{(N)},{(B)},{(C)},{(P)}},
	  draw open face with corners={{(P)},{(C)},{(D)},{(Q)}},
	  draw open face with corners={{(G)},{(D)},{(Q)}}
  } 
   \path[every edge/.append style={3d/polyhedron/face edges,3d/hidden}]
    (A) edge (G) edge (E);
  % compute a 3d coordinate that points to the right
  \pgfmathsetmacro{\myx}{TDunit("(0,0,1)x(nscreenx,nscreeny,nscreenz)")}
  \pgfmathsetmacro{\myX}{TD("\myr*(\myx)")} 
  % compute the phi angle (we know it but if you install the projection differently you may not)
  \pgfmathsetmacro{\myc}{atan2(TD("(0,1,0)o(\myx)"),TD("(1,0,0)o(\myx)"))} 
  % find the coordinates of the vertical boundaries of the cylinder
  \path[3d coordinate/.list={{(L_1)=(O)-(\myX)},
 	{(L_2)=(O')-(\myX)},{(R_1)=(O)+(\myX)},
 	{(R_2)=(O')+(\myX)}}];	
  % bottom part of the cylinder	
  \draw[3d/hidden] (R_1) 
  	arc[start angle=\myc,end angle=\myc+180,radius=\myr];
  \path[save named path=bot] 
    (R_1) arc[start angle=\myc,end angle=\myc-180,radius=\myr] 
  	(L_1) -- (L_2) (R_1) -- (R_2);	
  % upper cicrle of the cylinder	
  \path[save named path=circ] (O') circle[radius=\myr];
  % cylinder halo
  \path[save named path=cyl] 
    (R_1) arc[start angle=\myc,end angle=\myc-180,radius=\myr] 
  	 -- (L_2) arc[start angle=\myc-180,end angle=\myc,radius=\myr] 
	 -- cycle;  
  % hull of polyhedron
  \path[save named path=Block,convex hull of={A,B,C,D,S}];
  % hull of upper part of the polyhedron
  \path[save named path=block,convex hull of={M,N,P,Q,S}];
  % other paths
  \path[save named path=AM] (A) -- (M);
  \path[save named path=BE] (B) -- (E);
  \path[save named path=BN] (B) -- (N);
  \tikzset{3d/ordered paths/.cd,block/.style={draw=none},
  	Block/.style={draw=none}}
  % common	
  \tikzset{3d/draw ordered paths={circ,block}}
  \tikzset{3d/draw ordered paths={bot,Block}}
  \pgfmathtruncatemacro{\iQ}{Mod(\myc/90,4)}% quadrant
  %\typeout{\Angle: \myc, \iQ}
  % draw ordered objects	  
  \ifcase\iQ	
   \tikzset{3d/draw ordered paths={circ,block}}
   \tikzset{3d/draw ordered paths={bot,Block}}
   \draw[3d/visible,use named path=BE];
   \pgfmathsetmacro{\ntest}{TDunit("(A)-(O)")}
   \pgfmathtruncatemacro{\itest}{screendepth(\ntest)>0?1:0}
   \ifnum\itest=1
	\draw[3d/visible,use named path=AM];
   \else
	\draw[3d/hidden,use named path=AM];
   \fi   
  \or
   \draw[3d/hidden,use named path=AM];
   \draw[3d/hidden,use named path=BE];
  \or
   \draw[3d/hidden,use named path=AM];
   \draw[3d/hidden,use named path=BE];
  \or
   \tikzset{3d/draw ordered paths={BE,BN,cyl}}
   \draw[3d/hidden,use named path=BE];
   \draw[3d/visible,use named path=AM];
  \fi
  \path foreach \p/\g in {A/90,B/90,C/200,D/-90,S/0,M/0,N/0,P/0,Q/0,O'/0,E/0,F/0,G/0,O/0}
	{(\p)node[c]{}+(\g:2.5mm) node{$\p$}}; 			
\end{tikzpicture}}	
\end{document}    
```
![ani.gif](/image?hash=77f558e97b0f51b0a139a14f40471f3423df9fa04d9b03783c8b3639fbefed90)

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.