0

How can we fit the cylinder using the following code into the cone, please help, I am unable to fit this cylinder in the cone... will be very helpful.

\documentclass{article}
\usepackage{amsmath}
\usepackage{lmodern}
\usepackage[x11names]{xcolor}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{mathptmx}
\usepackage{geometry}
\usetikzlibrary{intersections}
\geometry{
    top=0.5in,            % <-- you want to adjust this
    inner=0.5in,
    outer=0.5in,
    bottom=0.5in,
    headheight=3ex,       % <-- and this
    headsep=2ex,          % <-- and this
}
\usepackage{verbatim}
\everymath{\displaystyle}
\usepackage{amsmath}

\usetikzlibrary{calc}
\usepackage{mathptmx}
\usepackage{gnuplottex}
\everymath{\displaystyle}
\usepackage{amsmath}
\usepackage{amssymb}
\begin{document}



\begin{tikzpicture}
\draw[dashed] (0,0) arc (170:10:2cm and 0.4cm)coordinate[pos=0] (a);
\draw (0,0) arc (-170:-10:2cm and 0.4cm)coordinate (b);
\draw[densely dashed] ([yshift=4cm]$(a)!0.5!(b)$) -- node[right,font=\footnotesize] {$h$}coordinate[pos=0.95] (aa)($(a)!0.5!(b)$)
-- node[above,font=\footnotesize] {$r$}coordinate[pos=0.1] (bb) (b);
\draw (aa) -| (bb);
\draw (a) -- ([yshift=4cm]$(a)!0.5!(b)$) -- (b);

\draw (0,0) ellipse (1.25 and 0.5);
\draw (-1.25,0) -- (-1.25,-3.5);
\draw (-1.25,-3.5) arc (180:360:1.25 and 0.5);
\draw [dashed] (-1.25,-3.5) arc (180:360:1.25 and -0.5);
\draw (1.25,-3.5) -- (1.25,0);  
\fill [gray,opacity=0.5] (-1.25,0) -- (-1.25,-3.5) arc (180:360:1.25 and 0.5) -- (1.25,0) arc (0:180:1.25 and -0.5);


\end{tikzpicture}

1 Answer 1

6

You can try this code

\documentclass[border=1mm,tikz,12pt]{standalone} 
    \usepackage{tikz-3dplot} 
\usetikzlibrary{calc,backgrounds} 
\begin{document} 
    \pgfmathsetmacro\th{75} 
    \pgfmathsetmacro\az{120} 
    \tdplotsetmaincoords{\th}{\az} 
    \pgfmathsetmacro\a{1} 
    \pgfmathsetmacro\R{5*\a} %radius of base 
    \pgfmathsetmacro\v{5*\a} %hight of cone 
    \pgfmathsetmacro\d{2*\R} %side AB 
            \pgfmathsetmacro\h{\v/2}
    \pgfmathsetmacro\myr{(\v-\h)*\R/\v} 
        \pgfmathsetmacro\cott{{cot(\th)}} 
    \pgfmathsetmacro\fraction{\R*\cott/\v} 
    \pgfmathsetmacro\fraction{\fraction<1 ? \fraction : 1} 
    \pgfmathsetmacro\angle{{acos(\fraction)}} 
    
    \pgfmathsetmacro\PhiOne{180+(\az-90)+\angle} 
    \pgfmathsetmacro\PhiTwo{180+(\az-90)-\angle} 
    \pgfmathsetmacro\sinPhiOne{{sin(\PhiOne)}} 
    \pgfmathsetmacro\cosPhiOne{{cos(\PhiOne)}} 
    \pgfmathsetmacro\sinPhiTwo{{sin(\PhiTwo)}} 
    \pgfmathsetmacro\cosPhiTwo{{cos(\PhiTwo)}} 
    \pgfmathsetmacro\sinazp{{sin(\az-90)}} 
    \pgfmathsetmacro\cosazp{{cos(\az-90)}} 
    \pgfmathsetmacro\sinazm{{sin(90-\az)}} 
    \pgfmathsetmacro\cosazm{{cos(90-\az)}} 
    \begin{tikzpicture} [tdplot_main_coords,line join = round, line cap = round] 
    \coordinate (O) at (0,0,0) ; 
    \coordinate (S) at (0,0,\v); 
    \draw[dashed]  (S)--(O) ; 
    \begin{scope}[canvas is xy plane at z=0]
    
    \draw[dashed] (\tdplotmainphi:\myr) arc(\tdplotmainphi:\tdplotmainphi+180:\myr);
    
    \draw[dashed] (\tdplotmainphi:\myr) coordinate(BR) arc(\tdplotmainphi:\tdplotmainphi-180:\myr) coordinate(BL);
    \coordinate (O) at (0,0);
    \draw[dashed] (BL) -- (BR); 
    \end{scope}
    %
    \begin{scope}[canvas is xy plane at z=\h]
    \coordinate (O') at (0,0);
    
    \draw [dashed](BR) -- (\tdplotmainphi:\myr) (BL) -- (\tdplotmainphi-180:\myr); 
    
    \draw[dashed] (\tdplotmainphi:\myr) arc(\tdplotmainphi:\tdplotmainphi+180:\myr);
    
    \draw[thick] (\tdplotmainphi:\myr) coordinate(BR) arc(\tdplotmainphi:\tdplotmainphi-180:\myr) coordinate(BL);
\draw[dashed]  (\tdplotmainphi:\myr)  -- (\tdplotmainphi-180:\myr); 
    \end{scope}
\tdplotdrawarc[tdplot_main_coords,thick]{(O)}{\R}{\PhiOne}{360+\PhiTwo}{anchor=north}{} 
    \tdplotdrawarc[tdplot_main_coords,dashed]{(O)}{\R}{\PhiTwo}{\PhiOne}{anchor=north}{} 
    \draw[thick] (0,0,\v) -- (\R*\cosPhiOne,\R*\sinPhiOne,0); 
    \draw[thick] (0,0,\v) -- (\R*\cosPhiTwo,\R*\sinPhiTwo,0); 
\end{tikzpicture} 
    \end{document}

enter image description here

With 3dtools at here, you can use this code.

\documentclass[border=1mm,tikz]{standalone} 
\usetikzlibrary{calc,3dtools}% https://github.com/marmotghost/tikz-3dtools

    \begin{document} 
        \begin{tikzpicture}[3d/install view={phi=110,theta=70},line join = round, line cap = round,
            declare function={R=2;v=R;% base radius and height of the cone 
                r=R/2;% radius of the cylinder
                h=(R-r)*v/R;%  height of the base of the upper circle
            }] 
            \draw[3d/hidden] (0,0,0) coordinate (O) circle[radius=r]
            --  (0,0,v) coordinate (S) (0,0,h) coordinate (H)
            [3d/screen coords] (-r,0) -- (-r,0|-H) (r,0) -- (r,0|-H); 
            \path pic{3d/cone={r=R,h=v}} (0,0,h) pic{3d/cone={r=r,h/.evaluated=v-h}};   
        \end{tikzpicture} 
    
    \begin{tikzpicture}[3d/install view={phi=110,theta=70},line join = round, line cap = round,
        declare function={R=2;v=R;% base radius and height of the cone 
            r=R/2;% radius of the cylinder
            h=(R-r)*v/R;%  height of the base of the upper circle
        }] 
        \draw[3d/hidden] (0,0,0) coordinate (O) circle[radius=r]
        --  (0,0,v) coordinate (S) (0,0,h) coordinate (H)
     ([xshift=-r*1cm]O) -- ([xshift=-r*1cm]H)
        ([xshift=r*1cm]O) -- ([xshift=r*1cm]H); 
        \path pic{3d/cone={r=R,h=v}} (0,0,h) pic{3d/cone={r=r,h/.evaluated=v-h}};   
    \end{tikzpicture} 
    \end{document}  

enter image description here

1
  • 1
    Really amazing.. I am very greatful for your help.... thanks a lot.. God bless you....
    – Sachin
    Mar 29, 2020 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .