我怎样才能给这个圆锥体增加斜高?

我怎样才能给这个圆锥体增加斜高?

我找到了其他人编写的创建圆锥体的代码,并将其复制粘贴在下面。但是,我还想添加一个箭头 (<-->) 表示倾斜高度并将其标记为“l”。但是,我不确定该怎么做。有人可以帮我吗?

\documentclass[a4paper, 12pt]{article}
\usetikzlibrary{positioning, calc}

\begin{document}

\begin{tikzpicture}

\newcommand{\radiusx}{2}
\newcommand{\radiusy}{.5}
\newcommand{\height}{6}

\coordinate (a) at (-{\radiusx*sqrt(1-(\radiusy/\height)*(\radiusy/\height))},{\radiusy*(\radiusy/\height)});

\coordinate (b) at ({\radiusx*sqrt(1-(\radiusy/\height)*(\radiusy/\height))},{\radiusy*(\radiusy/\height)});

\draw[fill=gray!30] (a)--(0,\height)--(b)--cycle;

\fill[gray!50] circle (\radiusx{} and \radiusy);

\begin{scope}
\clip ([xshift=-2mm]a) rectangle ($(b)+(1mm,-2*\radiusy)$);
\draw circle (\radiusx{} and \radiusy);
\end{scope}

\begin{scope}
\clip ([xshift=-2mm]a) rectangle ($(b)+(1mm,2*\radiusy)$);
\draw[dashed] circle (\radiusx{} and \radiusy);
\end{scope}

\draw[dashed] (0,\height)|-(\radiusx,0) node[right, pos=.25]{$h$} node[above,pos=.75]{$r$};

\draw (0,.15)-|(.15,0);
\end{tikzpicture}
\end{document}

答案1

只需添加另一个\draw,如下所示:

\documentclass[a4paper, 12pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning, calc}
\begin{document}
\begin{tikzpicture}
\newcommand{\radiusx}{2}
\newcommand{\radiusy}{.5}
\newcommand{\height}{6}
\coordinate (a) at (-{\radiusx*sqrt(1-(\radiusy/\height)*(\radiusy/\height))},{\radiusy*(\radiusy/\height)});
\coordinate (b) at ({\radiusx*sqrt(1-(\radiusy/\height)*(\radiusy/\height))},{\radiusy*(\radiusy/\height)});
\draw[fill=gray!30] (a)--(0,\height)--(b)--cycle;
\fill[gray!50] circle (\radiusx{} and \radiusy);
\begin{scope}
\clip ([xshift=-2mm]a) rectangle ($(b)+(1mm,-2*\radiusy)$);
\draw circle (\radiusx{} and \radiusy);
\end{scope}
\begin{scope}
\clip ([xshift=-2mm]a) rectangle ($(b)+(1mm,2*\radiusy)$);
\draw[dashed] circle (\radiusx{} and \radiusy);
\end{scope}
\draw[dashed] (0,\height)|-(\radiusx,0) node[right, pos=.25]{$h$} node[above,pos=.75]{$r$};
\draw (0,.15)-|(.15,0);

\draw [<->] (\radiusx+1,0) -- (1,\height) node[midway,right] {label};%<--

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容