如何编写圆柱体的 3D 图形。我尝试了之前建议的代码,但它没有按预期工作

如何编写圆柱体的 3D 图形。我尝试了之前建议的代码,但它没有按预期工作

我正在尝试编写一个圆柱体,形式为 x^2+y^2=r^2,其中 h 是圆柱体的未知高度(我希望它在轴上标记为 r),因为在问题中圆柱体的半径没有给出,而且也不相关。我试图将它放在页面的右上角,然后如果可能的话在旁边写字。关于我该怎么做,有什么想法吗?这是我正在寻找的粗略草图: 在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

答案1

您可以使用3d工具

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3dtools}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
\begin{tikzpicture}[3d/install view={phi=110,theta=70},line join = round, line cap = round,c/.style={circle,fill,inner sep=1pt},
    declare function={R=3;h=3;}]
    \path (0,0,0) coordinate (O)
    (0,0,h) coordinate (O');
    \path[save named path=ox] (-R-1,0,0) -- (R+ 3,0,0) node[anchor=north east]{$x$};
    \path [save named path=oy] (0,-R-2,0) -- (0,R+2,0) node[anchor=north west]{$y$};
    \path [save named path=oz] (0,0,0) -- (0,0,h+2) node[anchor=south]{$z$};
    \path [save named path=oz'] (0,0,0) -- (0,0,-h);
    \path [3d/visible/.style={save named path=cyc,draw={none}}] pic{3d/frustum={R=R,r=R,h=h}};
    \draw[3d/hidden,blue] (O) -- (O');
    \draw[3d/visible, - latex,blue] (O') -- (0,0,h+2);
    \tikzset{3d/ordered paths/.cd,ox/.style={blue,- latex},oy/.style={blue,- latex},oz'/.style={blue}}
    \tikzset{3d/draw ordered paths={ox,oy,oz',cyc}}
    %\path foreach \p/\g in {O/-90}{(\p)node[c]{}+(\g:2.5mm) node{$\p$}};
\end{tikzpicture}
\end{document}

在此处输入图片描述

我添加了一些节点

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3dtools}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
    \begin{tikzpicture}[3d/install view={phi=110,theta=70},line join = round, line cap = round,c/.style={circle,fill,inner sep=1pt},
        declare function={R=3;h=3;}]
        \path (0,0,0) coordinate (O)
        (0,0,h) coordinate (O');
        \path[save named path=ox] (-R-1,0,0) -- (R+ 3,0,0) node[anchor=north east]{$x$};
        \path [save named path=oy] (0,-R-2,0) -- (0,R+2,0) node[anchor=north west]{$y$};
        \path [save named path=oz] (0,0,0) -- (0,0,h+2) node[anchor=south]{$z$};
        \path [save named path=oz'] (0,0,0) -- (0,0,-h);
        \path [3d/visible/.style={save named path=cyc,draw={none}}] pic{3d/frustum={R=R,r=R,h=h}};
        \draw[3d/hidden,blue] (O) -- (O');
\node[below] at (0,R,0) {$ r $};
\node[below] at (0,-R,0) {$ -r $};
\node[right] at (0,0,h) {$ h $};
        \draw[3d/visible, - latex,blue] (O') -- (0,0,h+2);
        \tikzset{3d/ordered paths/.cd,ox/.style={blue,- latex},oy/.style={blue,- latex},oz'/.style={blue}}
        \tikzset{3d/draw ordered paths={ox,oy,oz',cyc}}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

这可能有助于开始:使用 pgfplot 圆柱作为 tikz 节点的坐标系

\documentclass[border=0.5cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,calc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
  view={25}{15},
  axis lines=center,
  width=20cm,height=20cm,
  xmin=-5,xmax=5,ymin=-5,ymax=5,zmin=-5,zmax=5,
  xlabel={$x$},ylabel={$y$},zlabel={$z$},
]

\node[cylinder,draw=black,thick,aspect=0.9,minimum height=1.2cm,minimum width=1cm,shape border rotate=90,fill=white] at (axis cs:0,0,0.25) {};

\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容