2

I have drawn a truncated cone in TikZ and am generally happy with the result. Here is the output and an MWE:

The cone!

\documentclass{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[>=latex]
    \fill[fill=gray!50] (1,0) ellipse (0.166 and 0.5);
    \fill[fill=gray!50] (4,0) ellipse (0.498 and 1.5);

    \fill[fill=gray!50] (1, 0.5) -- (4, 1.5) -- (4, -1.5) -- (1, -0.5) -- (1, 0.5);


    \draw[thick,->] (0,0,0) -- (5,0,0) node[anchor=west]{$z$};
    \draw[thick,->] (0,0,0) -- (0,2,0) node[anchor=south]{$x$};
    \draw[thick,->] (0,0,0) -- (0,0,2) node[anchor=north east]{$y$};

    \draw[semithick] (1,0) ellipse (0.166 and 0.5);
    \draw[semithick] (4,0) ellipse (0.498 and 1.5);

    \draw (1, 0.5) -- (4, 1.5);
    \draw (1, -0.5) -- (4, -1.5);
\end{tikzpicture}

\end{document}

However, I think that there is room for improvement. Here are some things that I could not figure out:

  • How can we (automatically) dash the z-axis where it should be hidden, as well as part of the ellipse of one of the sides, which should not be visible?
  • Would there be a sane way of adding some shading to the drawing, that would add depth?

Can you help me out with these points?

1
  • 1
    To dash the z-axis you could use \draw [thick,gray!50,dashed] (0,0,0) -- (5,0,0); after drawing the axis and then clip it do the shape of the cone.
    – Scz
    Aug 27, 2014 at 19:16

2 Answers 2

5

A quick try could be like this:

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{shapes,shadings}
\begin{document}

\begin{tikzpicture}[>=latex,outer sep=0in,elps/.style={ellipse,minimum width=1cm,minimum height=3cm}]

\draw[thick,->] (0,0,0) -- (5,0,0) node[anchor=west]{$z$};
\draw[thick,->] (0,0,0) -- (0,2,0) node[anchor=south]{$x$};
\draw[thick,->] (0,0,0) -- (0,0,2) node[anchor=north east]{$y$};

\node[elps,scale=.34](n1)at(1,0){};
\node[elps](n2)at(4,0){};

\draw[shading=axis,shading angle=90] (n1.92)--(n2.{92})--(n2.{268})--(n1.268)--cycle; 

\node[scale=.34,draw,shading=axis,shading angle=270,elps] (n1)at(1,0){};
\node[draw,shading=axis,shading angle=90,elps](n2)at(4,0){};

\draw [thick,dashed,shorten >=2pt] (0,0,0) -- (5,0,0);
\end{tikzpicture}

\end{document}

The output now is this:

enter image description here

An improved try is this:

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{shapes,shadings,positioning}
\begin{document}

\begin{tikzpicture}[>=latex,outer sep=0in,elps/.style={ellipse,minimum width=1cm,minimum height=3cm}]

\draw[thick,->] (0,0,0) -- (5,0,0) node[anchor=west]{$z$};
\draw[thick,->] (0,0,0) -- (0,2,0) node[anchor=south]{$x$};
\draw[thick,->] (0,0,0) -- (0,0,2) node[anchor=north east]{$y$};

\node[draw,elps,scale=.34](n1)at(1,0){};
\node[elps](n2)at(4,0){};

\path[shading=axis,shading angle=90] (n1.92)--(n2.{92})--(n2.{268})--(n1.268)arc(268:92:0.16cm and .505cm); 

\begin{scope}
\path[clip] (n1.92)--(n1.268)--(n2.{268})--(n2.92)--cycle;
\node[draw,densely dashed,elps,scale=.34](n1)at(1,0){};
\end{scope}

\begin{scope}
\path[clip] (n1.92)--(n1.268)--([xshift=-2cm]n1.268)--([xshift=-2cm]n1.92)--cycle;
\node[draw,elps,scale=.34](n1)at(1,0){};
\end{scope}

\node[draw,shading=axis,shading angle=90,elps](n2)at(4,0){};

\draw (0,0,0)edge[thick,dashed](n2.west) (n2.west)edge [thick,shorten >=2pt](5,0,0);
\draw(n1.92)--(n2.92)(n1.268)--(n2.268);

\end{tikzpicture}

\end{document}

The output now is:

enter image description here

1
  • Can you explain what something like (n1.92) as opposed to (n1) means?? In other words, what does the .92 do?
    – Prahar
    Oct 19, 2018 at 18:47
5

Another way is to use the intersections library, although the approach of @AboAmmar is more clever and faster to write. Nontheless here is my try.

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}[>=latex]
    \fill[fill=gray!50] (1,0) ellipse (0.166 and 0.5);
    \fill[fill=gray!50] (1, 0.5) -- (4, 1.5) -- (4, -1.5) -- (1, -0.5)
                        -- cycle;
    \fill[fill=gray!30] (4,0) ellipse (0.498 and 1.5);

    \draw[thick,->] (0,0,0) -- (0,2,0) node[anchor=south]{$x$};
    \draw[thick,->] (0,0,0) -- (0,0,2) node[anchor=north east]{$y$};

    \draw[semithick,dashed] (1,0) +(90:0.5)
        arc[x radius=0.166, y radius=0.5, start angle=90, end angle=-90];
    \draw[semithick,name path=first ellipse] (1,0) +(270:0.5)
        arc[x radius=0.166, y radius=0.5, start angle=270, end angle=90];
    \draw[semithick,name path=second ellipse] (4,0) ellipse (0.498 and 1.5);

    % Find intersecions and give them a name
    \path[name path=zaxis] (0,0,0) -- (5,0,0);
    \path[name intersections={of=zaxis and first ellipse}] (intersection-1)
        coordinate (A);
    \path[name intersections={of=zaxis and second ellipse}] (intersection-1)
            coordinate (B) (intersection-2) coordinate (C);
    % Draw the z axis
    \draw[thick,->] (0,0,0) -- (A) (C) -- (5,0,0) node[anchor=west]{$z$};
    \draw[thick, dashed] (A) -- (C);

    \draw (1, 0.5) -- (4, 1.5);
    \draw (1, -0.5) -- (4, -1.5);
\end{tikzpicture}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .