I'm trying to draw the area under a cone (sqrt(x^2+y^2)
), insider a cylinder (x^2+y^2 = 2x
) using tikz.
My problem is that the area is not being well defined. My code produces this weird shapes:
View: {130}{30}
View: {30}{30}
I'm trying to get something like this:
\documentclass[10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shadings}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}[bullet/.style={circle,fill,inner sep=0.5pt}, declare function={f(\x,\y)=(\x^2+\y^2)^0.5;}]
\begin{axis}[view={30}{30},colormap/blackwhite,axis lines=middle,%
zmax=2.5,zmin=0,xmin=-2.5,xmax=3.5,ymin=-2.5,ymax=2.5,%
xlabel=$x$,ylabel=$y$,zlabel=$z$,
xtick=\empty,ytick=\empty,ztick=\empty]
\addplot3[surf,shader=interp,domain=0:2,domain y=-2:2,opacity=0.4] {f(x,y)};
%\draw [fill=white!50!blue, opacity=0.3, smooth, samples=100, domain=0:2] plot(\x, {sqrt(2*\x-\x*\x)}) -- plot[domain=2:0] (\x,{-sqrt(2*\x-\x*\x)}) -- cycle;
\draw [blue, domain=0:2, smooth, variable=\x] plot (\x, {sqrt(2*\x-\x*\x)});
\draw [blue, domain=0:2, smooth, variable=\x] plot (\x, {-sqrt(2*\x-\x*\x)});
\draw [fill=white!50!blue, opacity=0.3, smooth, samples=100, domain=0:2] plot(\x, {sqrt(2*\x-\x*\x)},0) -- plot[domain=2:0] (\x,{sqrt(2*\x-\x*\x)},{f(\x,{sqrt(2*\x-\x*\x)})}) -- cycle;
\draw [red] (1,2) node[]{$D$};
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer