圆柱体在 z 域中被裁剪

圆柱体在 z 域中被裁剪

我正在尝试渲染一个圆柱体,数学定义为 $y^2+z^2=r^2, x\in [0,5]$。

这里是 MWE:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xlabel=$x$,ylabel=$y$, zlabel={$z$},
xmin = 0, xmax=5,
ymin=-2, ymax=2,
zmin=-2, zmax=2]
 \addplot3[surf,shader=flat,gray,samples=2,samples y=10,
    domain=0:5,z buffer=sort,
    opacity=0.5] (x, {sin(deg(y))}, {cos(deg(y))});
\end{axis}
\end{tikzpicture}

\end{document}

但是圆柱体的形状在某处被剪掉了: 圆柱

答案1

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
xlabel=$x$,ylabel=$y$, zlabel={$z$},
xmin = 0, xmax=5,
ymin=-2, ymax=2,
zmin=-2, zmax=2]
 \addplot3[
 surf,
 shader=flat,
 gray,
 samples=2,
 samples y=10,
 domain=0:4,
 y domain=0:2*pi,
 z buffer=sort,
 opacity=0.5,
 ] (x, {sin(deg(y))}, {cos(deg(y))});
\end{axis}
\end{tikzpicture}
\end{document}

圆柱图

答案2

您可以使用3d工具

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc,3dtools}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
\begin{tikzpicture}[3d/install view={phi=30,theta=70,psi=0},declare function={r=2;h=5;}] 
\path[3d/record physical components] 
(1,0,0) coordinate (ez') 
(0,1,0) coordinate (ex') 
(0,0,1) coordinate (ey');
\begin{scope}[x={(ex')},y={(ey')},z={(ez')}]
\pic{3d/frustum={r=r,R=r,h=h}};
\end{scope}
\draw[3d/hidden] (0,0,-r) -- (0,0,r) (0,0,0) -- (h,0,0) ;
\node[left] (O) at  (0,0,0) {$ O $};
\fill  (0,0,0) circle[radius = 1.5pt];
\draw[3d/visible, - latex] (h,0,0) -- (h+ 2,0,0) node[right]{$x$};
\draw[3d/visible, - latex] (0,0,r) -- (0,0,r+1) node[above]{$z$};
\draw[3d/hidden, - latex] (0,0,0) -- (0,r+1,0) node[above]{$y$};    
\end{tikzpicture}
\end{document}   

在此处输入图片描述

答案3

我使用几何变换。

在此处输入图片描述

// copy to http://asymptote.ualberta.ca/ and click Run
unitsize(1cm);
import three;
currentprojection=orthographic(2,2,1,zoom=.8);
real r=1.5, h=5;
transform3 t=rotate(90,Y)*scale(r,r,h);
surface c=t*unitcylinder;
draw(c,yellow+opacity(.7));

draw(Label("$x$",EndPoint),O--(h+3)*X,Arrow3);
draw(Label("$y$",EndPoint),O--(r+1)*Y,Arrow3);
draw(Label("$z$",EndPoint),O--(r+1)*Z,Arrow3);

相关内容