TikZ PGF – Creating an Inverted Cone Shape

tikz-pgf

How to draw a simple cone with height and radius with TikZ?

In the above thread, a cone was created. However, if I invert the cone, the lines from the origin to the cone edges cuts through the cone. This is not visually pleasing. How can I get the line to only intersect the (\pm 2, 3) without going through ellipse opening?

\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\usetikzlibrary{shadings}

\begin{document}
\begin{tikzpicture}
  \coordinate (h) at (0, 3);
  \coordinate (O) at (0, 0);

  \draw (O) -- +(0, 4);
  \draw (O) -- +(3, 0);
  \draw (O) -- +(-3, 0);

  \fill[
  top color = gray!50,
  bottom color = gray!10,
  shading = axis,
  opacity = 0.25
  ]
  (h) ellipse[x radius = 2, y radius = 0.5];
  \fill[
  left color = gray!50!black,
  right color = gray!50!black,
  middle color = gray!50,
  shading = axis,
  opacity = 0.25
  ]
  (2, 3) -- (O) -- (-2, 3) arc[x radius = 2, y radius = .5, start angle = 180,
  end angle = 360];

  \draw (-2, 3) arc[x radius = 2, y radius = .5, start angle = 180,
  end angle = 360] -- (O) -- cycle;
  \draw[dashed] (-2, 3) arc[x radius = 2, y radius = .5, start angle = 180,
  end angle = 0];
\end{tikzpicture} 
\end{document}

enter image description here

Best Answer

I suppose what you want to do is find a line starting at the tip of the cone that is tangential to the ellipse.

So let's do the math. Let r1 be the horizontal radius of the ellipse, and let r2 be the vertical radius. Let z be the distance from the tip of the cone to the midpoint of the ellipse. We have the following situation:

enter image description here

Here, O is the origin, P is the tip of the cone, S is the point at which the line is tangential to the ellipse, alpha is the angle between the horizontal axis and the line segment OS, and the vector v is a normal vector of the ellipse at point S.

We want the vector PS to be perpendicular to the vector v. I've used LaTeX for the remainder of the math: (Unfortunately tex.stackexchange.com does not have LaTeX formulas enabled.)

enter image description here

Note that, interestingly, the required angle does not depend on r2! Curiously, the required angle is the angle of a triangle whose diagonal side has length z, and whose side opposite to the angle has length r2. There must be a simpler proof for this (using congruent triangles?). But it is already way after bedtime, so I'll leave that as an exercise :)

In your particular case, you have r2 = 0.5 and z = 3. This gives alpha = 9.594 degrees. This means you should draw a line from the tip of the cone to the point (pm 2 * cos(9.594), 3 - 0.5 * sin(9.594)) = (1.972, 2.91666), instead of to (2, 3) as you are doing right now.

This code should get you going:

\documentclass[tikz]{standalone}

\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
  \def\rx{2}    % horizontal radius of the ellipse
  \def\ry{0.5}  % vertical radius of the ellipse
  \def\z{3}     % distance from center of ellipse to origin

  \pgfmathparse{asin(\ry/\z)}
  \let\angle\pgfmathresult

  \coordinate (h) at (0, \z);
  \coordinate (O) at (0, 0);     
  \coordinate (A) at ({-\rx*cos(\angle)}, {\z-\ry*sin(\angle)});
  \coordinate (B) at ({\rx*cos(\angle)}, {\z-\ry*sin(\angle)});

  \draw[fill=gray!50] (A) -- (O) -- (B) -- cycle;
  \draw[fill=gray!30] (h) ellipse ({\rx} and {\ry});
\end{tikzpicture} 
\end{document}

A number of example outputs for different values of rx ,ry, and z.

enter image description here