如何在TIKZ中繪製三維圖形

如何在TIKZ中繪製三維圖形

185/5000 我已經在二維中使用 TIKZ,但我從來不需要做任何與三維相關的事情,我想知道是否有人可以幫助我開始下面的繪圖。在此輸入影像描述

答案1

在 3D 中使用 Tikz 與在 2D 中使用幾乎相同 - 只不過您必須使用 3D 座標而不是 2D。

以下是繪製 3D 框的方法(如您所見,您可以混合 2D 和 3D 座標。在這種情況下,2D 表示的 z 座標將自動假定為零):

\beging{tikzpicture}
    \draw (0,0) -- ++(8,0) -- ++(0,-4) -- ++(-8,0) -- ++(0,4) -- ++(0,0,-4) -- ++(8,0) -- ++(0,-4) -- ++(0,0,4) ++(0,4,0) -- ++(0,0,-4);
    \draw[dashed] (0,-4) -- ++(0,0,-4) -- ++(8,0,0) ++(-8,0) -- ++(0,4);
\end{tikzpicture}

這是一個稍微複雜的例子(電磁波):

  \begin{tikzpicture}[x={(-10:1cm)},y={(90:1cm)},z={(210:1cm)}]
    % Axes
    \draw[->] (-1,0,0) node[above] {$x$} -- (5,0,0);
    \draw[->] (0,0,0) -- (0,2,0) node[above] {$y$};
    \draw[->] (0,0,0) -- (0,0,2) node[left] {$z$};
    % Waves
    \draw[red,thick] plot[domain=0:4.5,samples=200] (\x,{cos(deg(pi*\x))},0);
    \draw[blue,thick] plot[domain=0:4.5,samples=200] (\x,0,{cos(deg(pi*\x))});
    % Arrows
    \foreach \x in {0.1,0.3,...,4.4} {
      \draw[red] (\x,0,0) -- (\x,{cos(deg(pi*\x))},0);
      \draw[blue] (\x,0,0) -- (\x,0,{cos(deg(pi*\x))});
    }
    % Labels
    \node[red, above right] at (0,1,0) {$\vec{\bm{E}}$};
    \node[below, blue] at (0,0,1) {$\vec{\bm{H}}$};
  \end{tikzpicture}

這產生 電磁波

相關內容