# Draw a Cone with another cone inside with different color

Hi all I have this code,

\def\a{2}   % major
\def\b{.5}  % minor
\def\h{5}   % height of the cone
\def\d{3}   % height of the section
\pgfmathsetmacro{\t}{asin(\b/\h)}  % parameter in the paramater form of the base ellipse x=a cos t ,  y=b sin t

\fill[gray!30,shift={(90:\h-\d)},scale=2.5,xslant=-1,yscale=.3] (-1,1) rectangle (1,-1) node[below,black]{$\alpha$};

\begin{scope}[cyan,thick]
\draw[dashed]
(\t:{\a} and {\b}) arc(\t:180-\t:{\a} and {\b});
\draw
(\t:{\a} and {\b})--(0,\h)--(180-\t:{\a} and {\b})
arc(180-\t:360+\t:{\a} and {\b});

\begin{scope}[shift={(90:\h-\d)},scale={\d/\h}]
\draw[dashed]
(\t:{\a} and {\b}) arc(\t:180-\t:{\a} and {\b});
\draw
(\t:{\a} and {\b})--(0,\h)--(180-\t:{\a} and {\b})
arc(180-\t:360+\t:{\a} and {\b})
(-\a,0) coordinate (L);
\end{scope}
\end{scope}

\begin{scope}[magenta]
\draw[dashed] (-\a,0)--(-2*\a,0) (0,\h)--(-2*\a,\h)
(L)--+(180:1) coordinate (Ld);
\draw[<->] (-2*\a+.5,0)--+(90:\h) node[midway,left]{$12$ cm};
\draw[<->] (Ld)++(0:.3)--+(90:\d) node[midway,left]{$d$};
\end{scope}

but I want to reproduce this image, it is basically just reverting the position upside down, but I do not know how.. Thanks

P.S. Can anyone suggest a good TikZ book for Mathematics area to draw lots kind of mathematics problems?

• Maybe have a look at the tkz-euclide package. Commented Nov 10, 2022 at 9:51

This is a quick fix, no more. I changed the scale=-1 to invert your picture and then fixed the solid/dashed lines for a right visibility.

\documentclass[border=2mm,tikz]{standalone}
\usepackage{siunitx} % SI units

\begin{document}
\begin{tikzpicture}[scale=-1] % <-- inverts the figure
\def\a{2}  % major
\def\b{.5} % minor
\def\h{5}  % height of the cone
\def\d{3}  % height of the section
\pgfmathsetmacro{\t}{asin(\b/\h)} % parameter in the paramater form of the base ellipse x=a cos t, y=b sin t

\begin{scope}[cyan,thick]
\draw (0,0) ellipse ({\a} and {\b});
\draw (\t:{\a} and {\b}) -- (0,\h) -- (180-\t:{\a} and {\b});
\begin{scope}[shift={(90:\h-\d)},scale={\d/\h}]
\fill[blue!20] (\t:{\a} and {\b}) arc(\t:-180-\t:{\a} and {\b}) -- (0,\h) -- cycle;
\draw (\t:{\a} and {\b}) arc(\t:180-\t:{\a} and {\b});
\draw[dashed] (180-\t:{\a} and {\b}) arc(180-\t:360+\t:{\a} and {\b})
(-\a,0) coordinate (L);
\end{scope}
\end{scope}
\begin{scope}[magenta]
\draw[dashed] (-\a,0)--(-2*\a,0) (0,\h)--(-2*\a,\h) (L)--+(180:1) coordinate (Ld);
\draw[<->] (-2*\a+.5,0)--+(90:\h) node[midway,right]{\qty{12}{\centi\meter}};
\draw[<->] (Ld)++(0:.3)--+(90:\d) node[midway,right]{$d$};
\end{scope}
\fill[gray,opacity=0.3,shift={(90:\h-\d)},scale=2.5,xslant=-1,yscale=.3] (-1,1) rectangle (1,-1) node[below,black]{$\alpha$};
\end{tikzpicture}
\end{document}

• Thanks, I think I really need a book to learn Tikz for beginner. Commented Nov 12, 2022 at 18:43
• There are errors occur: Undefined control sequence. ...a+.5,0)--+(90:\h) node[midway,right]{\qty For this line  \draw[<->] (-2*\a+.5,0)--+(90:\h) node[midway,right]{\qty{12}{\centi\meter}}; Commented Nov 12, 2022 at 18:51
• @FreyatheGoddess, it works fine for me. One possible explanation is that you aren't using siunitx package or it's not updated to a recent version. If it's the latter change \qty for \SI Commented Nov 12, 2022 at 19:08
• How to update siunitx to recent version? it works by changing \qty to \SI Commented Nov 13, 2022 at 5:30
• That depends on your LaTeX distribution. Look on this page, surely you will find the steps to follow Commented Nov 13, 2022 at 8:01