# draw a cone with two regions

I have the following code for generating a cylinder

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc,decorations.pathmorphing,shapes,arrows,snakes,patterns}
\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}[scale = 4, every node/.style={scale = 4}, mycyl/.style={cylinder, shape border rotate=90, draw, minimum width=1cm, aspect=0.25,anchor=south, text width=1cm, text height=.1cm}]
\node [mycyl , fill=blue, minimum height=1.6cm] (bl) at (0,0) {};
\node [mycyl , minimum height=.3cm, fill = cyan] (yell) at (0,1) { };
\foreach \y in {.6, .7, .8}{
\end{tikzpicture}
\end{document}


resulting in

I would now like to repeat this but for a conical shape. I have seen many examples of drawing conical shapes and have used one here:

\documentclass[border=2cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\shade[top color=blue!40!white,opacity=0.75] (-1,0) arc (180:0:2cm and 0.5cm) -- (1,-4) -- cycle;
\draw [](-1,0) arc (180:360:2cm and 0.5cm) -- (1,-4) -- cycle;
\draw [](-1,0) arc (180:0:2cm and 0.5cm);
\end{tikzpicture}
\end{document}


However, I'm unsure of how to repeat what I've done above but for the conical shape. Specifically, I'm unsure how to draw the dashed lines and how to separate the cone into two regions. Can anyone suggest how this can be done?

-
I think you need to use intersection here to get a better result. Do you notice the lines touching the ellipses don't properly get glued? –  cyanide-based food Nov 26 '13 at 22:04

Here is a poor (man's) solution that is very manual.

\documentclass[border=.5cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw [fill=blue!40!white,opacity=1] (-1.99,3.98) -- (1.99,3.98) -- (0,0) -- cycle;
\draw [fill=blue!20!white,opacity=1,] (0,4) circle (1.99cm and 0.4cm);
\draw [fill=yellow!40!white,opacity=1] (-1.49,2.98) -- (1.49,2.98) -- (0,0) -- cycle;
\draw [fill=yellow!20!white,opacity=1,] (0,3) circle (1.49cm and 0.3cm);
\end{tikzpicture}
\end{document}


-

Parametrization and pgfplots are your friend here. I've used

x = r cos(theta)
y = r sin(theta)
z = r


and plotted the cone twice- once for 0\leq z \leq 1 and once for 1\leq z \leq 2

% arara: pdflatex
\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[view={60}{30}]
samples=20,opacity=0.5,
domain=1:2,y domain=0:2*pi,
z buffer=sort]
({x * cos(deg(y))}, {x * sin(deg(y))}, {x});
samples=20,opacity=0.5,
domain=0:1,y domain=0:2*pi,
z buffer=sort]
({x * cos(deg(y))}, {x * sin(deg(y))}, {x});
\end{axis}
\end{tikzpicture}
\end{document}


You can play with the colours and keys to suit your needs.

-

Other solution also using Tikz, but is automatic, you just need to define the cone dimensions.

# Code

\documentclass[border=10pt]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
%Cone data
\pgfmathsetmacro{\theight}{5}%Cone height (negative if you want a inverse cone)
\pgfmathsetmacro{\cheightp}{.4}%Cut height in percent of cone height

%Calculating coordinates
\coordinate (center) at (0,0);
\coordinate (peak) at ($(center) + (0,\theight)$);
\coordinate (vert1) at ($(center)+(\radiush,0)$);
\coordinate (vert2) at ($(center)-(\radiush,0)$);
\coordinate (svert1) at ($(vert1)!\cheightp!(peak)$);
\coordinate (svert2) at ($(vert2)!\cheightp!(peak)$);

%Drawing
%Uncomment this for an inverted cone

%Lines, \h in percent of cone height
\foreach \h in {.38,.34,.30}{
\pgfmathsetmacro{\rv}{.2 * \rh}
\draw[black!70,densely dashed] ($(vert2)!\h!(peak)$) arc (180:360:\rh cm and \rv cm);
}
\end{tikzpicture}
\end{document}


# Result

Or if the height is a negative number:

You can use \shadedraw instead of \fill if you want draw the borders.

Someone can probably improve the code, I just thought it was interesting and fun.

-