2

This is my first question, I apologize for any inconvenient.
I have two coaxial circumferences that are the basis of a cone. I would like to fill the area between them, as the lateral surface of a cone. How can I do it? Here is what I have.

\documentclass[tikz,multi,border=10pt]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows.meta,angles,quotes,calc}
\begin{document}
\begin{tikzpicture}

\begin{scope}[canvas is yz plane at x=1] \draw NavyBlue,line width=.2mm,dashed circle (1cm); \end{scope} \begin{scope}[canvas is yz plane at x=1.4] \draw NavyBlue,line width=.2mm,dashed circle (1.8cm){};

\end{scope}
\end{tikzpicture} \end{document}

enter image description here

Qrrbrbirlbel
  • 119,821

1 Answers1

4

You can calculate the tangent points and fill the area. You can also use a surf plot from PGFPlots like this

\documentclass[tikz, border=1cm]{standalone}
\usepackage{tikz-3dplot}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}[declare function={radius(\h)=-1+2*\h;}]
\begin{axis}[
hide axis,
x=1cm, y=1cm, z={(-3.85mm,-3.85mm)},
anchor=origin, at={(0,0,0)},
xmin=-2, xmax=2,
ymin=-2, ymax=2,
zmin=-2, zmax=2,
]
\addplot3[
surf,
shader=interp,
samples=50, domain=0:360, variable=a,
samples y=2, domain y=1:1.4, variable y=h,
colormap/violet,
]( {h} , {radius(h)*cos(a)} , {radius(h)*sin(a)} );
\end{axis}
\draw[cyan, thick, dashed, canvas is yz plane at x=1] (0,0) circle[radius=1];
\draw[cyan, thick, dashed, canvas is yz plane at x=1.4] (0,0) circle[radius=1.8];
\end{tikzpicture}
\end{document}

truncated violet cone

I do not know what you need the figure for, so I made the coordinate system match inside and outside the axis. If there is no need to align the cone with anything else, then everything could be drawn inside axis and no consideration of unit vectors and origin would be needed.

Edit: With rotation. Method taken from: https://tex.stackexchange.com/a/199715/8650

\documentclass[tikz, border=1cm]{standalone}
\usepackage{tikz-3dplot}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\newcommand{\ViewAzimuth}{20}
\newcommand{\ViewElevation}{20}
\tikzset{viewport/.style 2 args={
x={({cos(-#1)*1cm},{sin(-#1)*sin(#2)*1cm})},
y={({-sin(-#1)*1cm},{cos(-#1)*sin(#2)*1cm})},
z={(0,{cos(#2)*1cm})}
}}
\begin{document}
\begin{tikzpicture}[viewport={\ViewAzimuth}{\ViewElevation}]
\begin{axis}[
hide axis,
view={\ViewAzimuth}{\ViewElevation},
every axis plot/.style={very thin},
disabledatascaling,
anchor=origin,
viewport={\ViewAzimuth}{\ViewElevation},
xmin=-2, xmax=2,
ymin=-2, ymax=2,
zmin=-2, zmax=2,
]
\addplot3[
surf,
shader=interp,
samples=50, domain=0:360, variable=a,
samples y=2, domain y=1:1.4, variable y=h,
colormap/violet,
]( {h} , {(-1+2*\h)*cos(a)} , {(-1+2*\h)*sin(a)} );
\end{axis}
\draw[cyan, thick, dashed, canvas is yz plane at x=1] (0,0) circle[radius=1];
\draw[cyan, thick, dashed, canvas is yz plane at x=1.4] (0,0) circle[radius=1.8];
\end{tikzpicture}
\end{document}

Truncated cone rotated Truncated cone rotated

  • Thank you very much. But if I use this in my tikzpicture I don't see the drawn area matching the circumferences. Is this what you were talking about with unit vector and origin's consideration? – Giulio Binosi Dec 02 '22 at 15:21
  • I use this in your tikzpicture and the circumferences do match. -so you must have changed something!? – hpekristiansen Dec 02 '22 at 19:32
  • This is what I have: \tdplotsetmaincoords{20}{20} \begin{tikzpicture}[declare function={radius(\h)=-1+2*\h;},tdplot_main_coords,scale=1.8,cone back/.style={draw=brown,left color=gray!50,right color=brown}, cone front/.style={draw=brown,left color=brown}] \coordinate (O) at (0,0,0); \begin{scope}[canvas is yz plane at x=1] \draw NavyBlue,line width=.2mm,dashed circle (1cm); \end{scope} \begin{scope}[canvas is yz plane at x=1.4] \draw NavyBlue,line width=.2mm,dashed circle (1.8cm); \end{scope} \begin{tikzpicture} – Giulio Binosi Dec 03 '22 at 10:53
  • You rotate and you scale your tikzpicture! – hpekristiansen Dec 03 '22 at 11:29
  • Yeah, I see. If I remove [tdplot_main_coords] it works. But that is a little disappointed, since I would like to draw all the figures and then choose the best view, without having those problems. Is it possible to change the view without changing the picture? – Giulio Binosi Dec 06 '22 at 14:17
  • Very strange and specific starting point, if you anyway want to rotate the result. -see edit. – hpekristiansen Dec 06 '22 at 15:07
  • That is what I was looking for, thank you. However it keeps telling the same error: "Illegal parameter number in definition of \iterate." Do you know why? – Giulio Binosi Dec 06 '22 at 15:44
  • 1
    No need to write thank you - just remember to accept the answer. The code as is compiles perfectly. Maybe you again change something? - I can only guess. Does this help? https://tex.stackexchange.com/questions/420448/error-illegal-parameter-number-in-definition-of-iterate – hpekristiansen Dec 06 '22 at 19:26
  • Yes, perfect. I was in a beamer, indeed. Thank you again, I'll accept the answer. – Giulio Binosi Dec 07 '22 at 10:02