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}
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 letr2
be the vertical radius. Letz
be the distance from the tip of the cone to the midpoint of the ellipse. We have the following situation: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 segmentOS
, and the vectorv
is a normal vector of the ellipse at pointS
.We want the vector
PS
to be perpendicular to the vectorv
. I've used LaTeX for the remainder of the math: (Unfortunately tex.stackexchange.com does not have LaTeX formulas enabled.)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 lengthz
, and whose side opposite to the angle has lengthr2
. 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
andz = 3
. This givesalpha = 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:
A number of example outputs for different values of
rx
,ry
, andz
.