tikz pgf

如何用TikZ绘制以X轴为方向的3D圆柱体

如何在X轴上绘制圆柱体?

\documentclass[tikz]{standalone}
\usetikzlibrary{3d}

\begin{document}

\begin{tikzpicture}[x={(1cm,0.4cm)}, y={(8mm, -3mm)}, z={(0cm,1cm)}, line cap=round, line join=round]

%   % Main Axes
    \draw[->] (0,0,0) -- (2,0,0) node[below] {$x$};
    \draw[->] (0,0,0) -- (0,2,0) node[below left] {$y$};
    \draw[->] (0,0,0) -- (0,0,2) node[above] {$z$};

    % Big Axis
    \draw[line cap=round, -latex, very thick] (-0.5,0,0) -- (10,0,0);

    \begin{scope}[canvas is yz plane at x=5.5]
    \draw[] (0,0)  circle (1);
    \end{scope}
    
    \begin{scope}[canvas is yz plane at x=8.5]
    \draw[] (0,0)  circle (1);
    \end{scope}

\end{tikzpicture}

在未来,它应该看起来像下面的图片。但现在我有一个问题,就是在3D中沿着所需的轴线画一个透明的圆柱体。

这里是那个圆柱体的一个开始。前景中的东西需要最后画出来。

猜测圆上切线点的角度 125 。我确信有一种方法可以从给定的坐标系向量 xyz 中计算出来。

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{3d}
\begin{document}
\begin{tikzpicture}[
  x={(1cm,0.4cm)},
  y={(8mm, -3mm)},
  z={(0cm,1cm)},
  line cap=round,
  line join=round,
  radius=1,
  delta angle=-180,
  front/.style={canvas is yz plane at x=5.5},
  back/.style={canvas is yz plane at x=8.5},
]

% Main Axes
\draw[->] (0,0,0) -- (2,0,0) 节点[下] {$x$};
\draw[->] (0,0,0) -- (0,2,0) 节点[左下] {$y$};
\draw[->] (0,0,0) -- (0,0,2) 节点[以上] {$z$};

% back gray arc
\draw[back, gray] (125:1) arc[start angle=125, delta angle=180];
% bix axis (through and behind cylinder)
\draw[line cap=round, -latex, very thick] {
  [front] (0,0)} -- (10,0,0);

% cylinder
\draw[fill=pink,fill opacity=.5] {
    [back]
      (125:1) arc[start angle=125]
  }{
    [front]
      -- (125+180:1) 弧[结束角度=125]
  } --cycle;
% front arc
\draw[front]      (125:1) arc[start angle=125];
% foreground axis
\draw[very thick, line cap=rect] (-0.5,0,0) -- (5.5,0,0);
\end{tikzpicture}
\end{document}

Output




您可以使用3dtools制作圆柱体。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc,3dtools}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
\begin{tikzpicture}[3d/install view={phi=130,theta=70,psi=0},declare function={r=2;h=8;}] 
    \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) ;
    \draw[3d/hidden] (0,0,0) -- (0,r,0);
    \node[above left] (O) at  (0,0,0) {$ O $};
    \fill  (0,0,0) circle[radius = 1.5pt];
    \draw[3d/visible, - latex] (h,0,0) -- (h+ 3,0,0) node[above]{$x$};
    \draw[3d/visible, - latex] (0,0,r) -- (0,0,r+1) node[above]{$z$};
    \draw[3d/visible, - latex] (0,r,0) -- (0,r+1,0) node[above]{$y$};    
\end{tikzpicture}   
\end{document}