在 tikz 中调整平行六面体

在 tikz 中调整平行六面体

我有以下代码(窃自有没有简单的方法可以在 tikz 中绘制平行六面体?并调整)

\documentclass[border=2mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
 \tdplotsetmaincoords{70}{60}
   \begin{tikzpicture}[scale=1,line cap=butt,line join=round,tdplot_main_coords,declare function={a=3;b=4;h=3;k=2;
   }] 
    \begin{scope}[canvas is xy plane at z=0]
    \path
    (0,0) coordinate (A) 
     (a,0) coordinate (B)
      (a,b) coordinate (C)
      (0,b) coordinate (D);
    \end{scope}
    \begin{scope}[canvas is xy plane at z=h]
 \path
 (0,k) coordinate (A') 
 (a,k) coordinate (B')
 (a,b+k) coordinate (C')
 (0,b+k) coordinate (D');
 \end{scope}  
 \begin{scope}[opacity=0.3,thick]
\draw[fill=orange] (A) --(B)  -- (C) -- (D) -- cycle;
\draw[fill=orange] (A) --(B)  -- (B') -- (A') -- cycle;
\draw[fill=orange] (B) --(C)  -- (C') -- (B') -- cycle;
\draw[fill=orange] (C) --(D)  -- (D') -- (C') -- cycle;
\draw[fill=orange] (A) --(D)  -- (D') -- (A') --cycle;
\draw[fill=orange] (A') --(B')  -- (C') -- (D') --cycle;
\end{scope}
\end{tikzpicture}
\end{document} 

渲染结果为

帕拉

我只想添加这样的箭头,所以很明显平行六面体是由这三个向量创建的。

第2段

谢谢大家!

答案1

与@Raffaele Santoro 的回答非常相似_

\documentclass[border=2mm,12pt,tikz]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{arrows.meta}

\begin{document}
 \tdplotsetmaincoords{70}{60}
   \begin{tikzpicture}[
line cap=butt,  line join=round,
tdplot_main_coords,
declare function={a=3;b=4;h=3;k=2;}
   ]
    \begin{scope}[canvas is xy plane at z=0]
    \path
    (0,0) coordinate    (A)
    (a,0) coordinate    (B)
    (a,b) coordinate    (C)
    (0,b) coordinate    (D);
    \end{scope}
    \begin{scope}[canvas is xy plane at z=h]
 \path
 (0,k) coordinate (A')
 (a,k) coordinate (B')
 (a,b+k) coordinate (C')
 (0,b+k) coordinate (D');
 \end{scope}
 \begin{scope}[opacity=0.3,thick]
\draw[fill=orange] (A) --(B)  -- (C) -- (D) -- cycle;
\draw[fill=orange] (A) --(B)  -- (B') -- (A') -- cycle;
\draw[fill=orange] (B) --(C)  -- (C') -- (B') -- cycle;
\draw[fill=orange] (C) --(D)  -- (D') -- (C') -- cycle;
\draw[fill=orange] (A) --(D)  -- (D') -- (A') --cycle;
\draw[fill=orange] (A') --(B')  -- (C') -- (D') --cycle;
\end{scope}
% new
    \begin{scope}[every edge/.style={draw, thick, -{Straight Barb[scale=0.8]}}]
\draw (B) edge (A)  (B) edge (C)    (B) edge (B');
    \end{scope}
\end{tikzpicture}
\end{document} 

在此处输入图片描述

答案2

您的代码已完成:

\documentclass[border=2mm,12pt,tikz]{standalone}
    \usepackage{tikz-3dplot}
    \begin{document}
        \tdplotsetmaincoords{70}{60}
        \begin{tikzpicture}[scale=1,line cap=butt,line join=round,tdplot_main_coords,declare function={a=3;b=4;h=3;k=2;
            }] 
            \begin{scope}[canvas is xy plane at z=0]
                \path
                (0,0) coordinate (A) 
                (a,0) coordinate (B)
                (a,b) coordinate (C)
                (0,b) coordinate (D);
            \end{scope}
            \begin{scope}[canvas is xy plane at z=h]
                \path
                (0,k) coordinate (A') 
                (a,k) coordinate (B')
                (a,b+k) coordinate (C')
                (0,b+k) coordinate (D');
            \end{scope}  
            \begin{scope}[opacity=0.3,thick]
                \draw[fill=orange] (A) --(B)  -- (C) -- (D) -- cycle;
                \draw[fill=orange] (A) --(B)  -- (B') -- (A') -- cycle;
                \draw[fill=orange] (B) --(C)  -- (C') -- (B') -- cycle;
                \draw[fill=orange] (C) --(D)  -- (D') -- (C') -- cycle;
                \draw[fill=orange] (A) --(D)  -- (D') -- (A') --cycle;
                \draw[fill=orange] (A') --(B')  -- (C') -- (D') --cycle;
                \draw[-latex,line width=2pt] (B)--(A); % <<< added
                \draw[-latex,line width=2pt] (B)--(C); % <<< added
                \draw[-latex,line width=2pt] (B)--(B');% <<< added
            \end{scope}
        \end{tikzpicture}
    \end{document}

输出:

在此处输入图片描述

编辑:但是,也许这样更好:

在此处输入图片描述

更改代码:

\begin{scope}[opacity=0.3,thick]
            \draw[fill=orange] (A) --(B)  -- (C) -- (D) -- cycle;
            \draw[fill=orange] (A) --(B)  -- (B') -- (A') -- cycle;
            \draw[fill=orange] (B) --(C)  -- (C') -- (B') -- cycle;
            \draw[fill=orange] (C) --(D)  -- (D') -- (C') -- cycle;
            \draw[fill=orange] (A) --(D)  -- (D') -- (A') --cycle;
            \draw[fill=orange] (A') --(B')  -- (C') -- (D') --cycle;
        \end{scope}
        \draw[-latex,line width=3pt] (D)--(A) node[left]() {$\vec{i}$}; % <<< added
        \draw[-latex,line width=3pt] (D)--(C) node[pos=1.1] () {$\vec{j}$};% <<< added
        \draw[-latex,line width=3pt] (D)--(D') node[pos=1.1] () {$\vec{k}$}; % <<< added
    \end{tikzpicture}

相关内容