# Tikz: cones with a wide base

In every example of cone which I found so far there is an unpleasant mistake at the base since the sides should be tangent to the bottom ellipse but they are never. Drawing a larger base the problem gets bigger.

Here are examples of wrong cones: How to draw a simple cone with height and radius with TikZ?

Is there a fast way to make a good cone? This is my attempt:

\documentclass[border=.5cm]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{scope}
\clip (-3,0) -- (3,0) -- (0,4) -- cycle ;
\draw[dashed] (0,0) circle(3cm and 0.6cm);
\end{scope}
\begin{scope}
\clip (-3,0) rectangle (3,-1cm);
\draw (0,0) circle(3cm and 0.6cm);
\end{scope}
\begin{scope}
\draw (-3,0) --  (3,8);
\draw (3,0) --  (-3,8);
\end{scope}
\begin{scope}
\clip (-3,8) rectangle (3,9cm);
\draw[dashed] (0,8) circle(3cm and 0.6cm);
\end{scope}
\begin{scope}
\clip (-3,8) rectangle (3,7cm);
\draw (0,8) circle(3cm and 0.6cm);
\end{scope}
\end{tikzpicture}
\end{document}


This is a perspective issue. If you would look at a cone up front, without perpesctive you'd see a triangle, so to make it look like a cone we draw an ellipse in the bottom part, the problem is that the more perspective we want the thicker gets the ellipse, then these 2D issues appear.

There are two ways to deal with it: either decrease the ellipse thickness to loose a little perspective or make the ellipse start and end in an "inclined" position (I don't know how to put this to words if someone can improve the language please do). I made an MWE to show what I mean.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\newcommand*{\coneheight}{6}
\newcommand*{\perspective}{0.5}
\pgfmathsetmacro{\startangle}{10*\perspective}
\pgfmathsetmacro{\endangle}{180-\startangle}
\begin{tikzpicture}
\coordinate (r) at (\startangle:\coneradius cm and \perspective cm);
\coordinate (-r) at (\endangle:\coneradius cm and \perspective cm);
\coordinate (h) at (0,\coneheight cm);

% Base circle
\fill[
top color=gray!50,
bottom color=gray!10,
opacity=0.25
] (0,0) circle (\coneradius cm and \perspective cm);

%Hat filling
\fill[
left color=gray!50!black,
right color=gray!50!black,
middle color=gray!50,
opacity=0.25
] (r) -- (h) -- (-r) arc (\endangle:360+\startangle:\coneradius cm and \perspective cm);

%Surrounding lines
\draw[dashed] (r) arc (\startangle:\endangle:\coneradius cm and \perspective cm);
\draw (-r) arc (\endangle:360+\startangle:\coneradius cm and \perspective cm);
\draw (-r) -- (h) --(r);
\draw[dashed] (r) -- node[below] {$r$} (0,0) -- node[left] {h} (h) ;
\draw (0,8pt) -- ++(8pt,0) -- (8pt,0);
\end{tikzpicture}

\end{document}


You define the normal cone parameters (height and radius) plus a perspective parameter, which is the b value for the ellipse. Then a starting angle will make the line look tangent to the ellipse in the bottom part, I used 10 times the perspective value out of try and error but that can be changed.You can play around with the perspective and the multiplier to see how the results come up best to you.

Result:

• I consider it pure sorcery but I appreciate very much! – ThePunisher Sep 29 '16 at 21:06
• @lanzariel Glad you appreciate it. There's actually mathematics behind it to get perfect tangency but I was a little bit lazy and it wasn't that easy math. ;D – Guilherme Zanotelli Sep 30 '16 at 5:34
• @GuilhermeZanotelli I tried \newcommand*{\coneheight}{2}, and I got bad cone. – minhthien_2016 Feb 5 '19 at 7:33
• @minhthien_2016 yeah, this implementation requires that the tip of the cone lie above the circumference of the base. A combination of perspective and cone radius will require a minimum cone height otherwise there will be non intersecting lines which will give you a bad cone. – Guilherme Zanotelli Feb 10 '19 at 12:59

I think this just about does it. Note the annoying use of \rx+0 to get around the required space in angle and arc radius specifications.

\documentclass[border=5]{standalone}
\usepackage{tikz}
\begin{document}
\def\b{2}
\def\h{2}
\begin{tikzpicture}
\foreach \p [count=\i from 0,
evaluate={\rx=\b/2; \ry=\rx*\p; \ta=90-atan2(\h,\ry);}]
in {0.1,0.2,...,0.6}{
\begin{scope}[shift={({mod(\i,3)*\b*1.25},{-floor(\i/3)*\h*1.25})}]
\fill [gray!50]
(0, \h) -- (\ta:\rx+0 and \ry) arc (\ta:180-\ta:\rx+0 and \ry) -- cycle;
\draw [dashed] (\ta:\rx+0 and \ry) arc (\ta:180-\ta:\rx+0 and \ry);
\draw (0, \h) -- (\ta:\rx+0 and \ry) arc (\ta:-180-\ta:\rx+0 and \ry) -- cycle;
\draw  [dotted] (\rx,0) -| (0, \h);
\end{scope}
}
\end{tikzpicture}
\end{document}


Which in close up looks like: