0

I found code by someone else on creating a cone which I copy pasted below. However, I want to also add an arrow (<-->) for the slant height and label it "l". However, I am unsure of how to do it. May someone please help me?

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

\begin{document}

\begin{tikzpicture}

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

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

\coordinate (b) at ({\radiusxsqrt(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 Answers1

1

Simply add another \draw as follows:

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

enter image description here

Dan
  • 3,699