Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}{
\draw[dashed, cyan] (.619,\y+.3) arc[x radius=.619cm, y radius=.154cm, start angle=0, end angle=-180];}
\end{tikzpicture}
\end{document}

resulting in

enter image description here

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}

enter image description here

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?

share|improve this question
    
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? –  I am who I say I am Nov 26 '13 at 22:04
add comment

3 Answers

up vote 7 down vote accepted

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}

enter image description here

share|improve this answer
add comment

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

screenshot

% arara: pdflatex
\documentclass{standalone}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
 \begin{axis}[view={60}{30}]
  \addplot3[surf,shader=flat,blue!20!white,
  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});
    \addplot3[surf,shader=flat,blue,
  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.

share|improve this answer
add comment

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

Code

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shadings,calc}

\begin{document}
    \begin{tikzpicture}
        %Cone data
        \pgfmathsetmacro{\radiush}{2};%Cone base radius
        \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);
        \pgfmathsetmacro{\radiusv}{.2 * \radiush};
        \pgfmathsetmacro{\sradiush}{\radiush * (1 - \cheightp)};%only for right circular cone
        \pgfmathsetmacro{\sradiusv}{.2 * \sradiush};
        \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    
        \fill[left color=red!70,right color=red!70,middle color=red!40,shading=axis] (svert1) -- (peak) -- (svert2) arc (180:360:\sradiush cm and \sradiusv cm);
        \fill[left color=gray!70,right color=gray!70,middle color=gray!30,shading=axis] (vert1) -- (svert1) arc (0:-180:\sradiush cm and \sradiusv cm) -- (vert2) arc (180:360:\radiush cm and \radiusv cm);
        %Uncomment this for an inverted cone
        %\fill[inner color=gray!30,outer color=gray!50,shading=radial] (0,0) circle (\radiush cm and \radiusv cm);

        %Lines, \h in percent of cone height
        \foreach \h in {.38,.34,.30}{
            \pgfmathsetmacro{\rh}{\radiush * (1 - \h)}
            \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

enter image description here

Or if the height is a negative number:

enter image description here

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.