如何在给定的图中将圆柱体插入圆锥体中

如何在给定的图中将圆柱体插入圆锥体中

我们如何使用以下代码将圆柱体装入圆锥体中,请帮忙,我无法将这个圆柱体装入圆锥体......将非常有帮助。

\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

你可以尝试这个代码

\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}

在此处输入图片描述

3dtools这里,您可以使用此代码。

\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}  

在此处输入图片描述

相关内容