[Tex/LaTex] How to draw a frustum like this

tikz-3dplot

I am trying to draw a frustum with centers of two bases A, C and two radii SA and CD, height of frustum AC.

enter image description here

I tried

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
    \tdplotsetmaincoords{60}{70}
    \begin{tikzpicture}[tdplot_main_coords,declare function={a=2;
        }]
        \path 
        (0,0,0) coordinate (A)
        (a,0,0) coordinate (B)
        (a,a,0) coordinate (C)
        (0,2*a,0) coordinate (D)
         (0,0,2*a)  coordinate (S)
        ;
\draw (A)--(B)--(C)--(D)--(S) -- cycle (S) -- (B) (S) --(C);
\draw [dashed] (D) -- (A) -- (C);
\path foreach \p/\g in {A/-90,B/-90,C/0,D/0,S/90}{(\p)node{}+(\g:2.5mm) node{$\p$}}; 

\end{tikzpicture}
\end{document}  

I got

enter image description here

How can I draw it?

Best Answer

You can use 3dtools

\documentclass[border=3mm,tikz]{standalone}
\usetikzlibrary{3dtools,calc}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
\begin{tikzpicture}[3d/install view={phi=55,psi=0,theta=70},
        line join = round, line cap = round,
        c/.style={circle,fill,inner sep=1pt},
        declare function={a=2;r=a*sqrt(2);R=2*a;}]
        \path 
        (0,0,0) coordinate (A) 
        (a,0,0) coordinate (B)
        (a,a,0) coordinate (C) 
        (0,2*a,0) coordinate (D)
        (0,0,2*a) coordinate (S)
        [3d coordinate={(S')=(C)-(D) +(A)}];
            \tikzset{3d/define orthonormal dreibein={A={(A)},B={(S)},C={(S')}}} 
        \path[x={(ex)},y={(ey)},z={(ez)}](A) pic{3d/frustum={r=r,R=R,h=r}};
        \draw[3d/visible](C) -- (D);
    \draw[3d/hidden](S) --(A) -- (B) -- (C) (S) -- (C) (S) -- (D) (A) -- (C) (A) -- (D) (S) -- (B);             
        \path foreach \p/\g in {A/180,B/-90,C/-90,D/0,S/90}
        {(\p)node[c]{}+(\g:2.5mm) node{$\p$}}; 
    \end{tikzpicture}
\end{document}  

enter image description here

Or

\documentclass[border=3mm,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=2;r=a*sqrt(2);R=2*a;}]
        \path 
        (0,0,0) coordinate (A) 
        (a,0,0) coordinate (B)
        (a,a,0) coordinate (C) 
        (0,2*a,0) coordinate (D)
        (0,0,2*a) coordinate (S)
        [3d coordinate={(S')=(C)-(D) +(A)}];
        \pgfmathsetmacro{\myB}{TD("(C)")}   
        \pgfmathtruncatemacro{\itest}{screendepth(\myB)>0?1:0}
        \ifnum\itest=1
        \draw[3d/visible] (C) -- (D);
        \draw[3d/hidden] (S) -- (A);
        \else
        \draw[3d/hidden] (D) -- (C);
        \draw[3d/visible] (S) -- (A);
        \fi   
        \draw[3d/hidden] (A) -- (C)  (A) -- (D) -- (S)
        (A) -- (B) -- (C) (S) -- (B)  -- (C) -- cycle
        ;
        \tikzset{3d/define orthonormal dreibein={A={(A)},B={(S)},C={(S')}}} 
        \path[x={(ex)},y={(ey)},z={(ez)}](A) pic{3d/frustum={r=r,R=R,h=r}};     
        \path foreach \p/\g in {A/180,B/-90,C/-90,D/0,S/90}
        {(\p)node[c]{}+(\g:2.5mm) node{$\p$}}; 
    \end{tikzpicture}}
\end{document}  

enter image description here

Related Question