\begin{tikzpicture}
\pgfmathsetmacro{\cubex}{1}
\pgfmathsetmacro{\cubey}{6}
\pgfmathsetmacro{\cubez}{2}
\draw[black, ultra thick,fill=yellow] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
\draw[black, ultra thick,fill=yellow] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
\draw[black, ultra thick, fill=yellow] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;
\end{tikzpicture}
我需要为平行六面体的每条边添加引号(像这张图片一样)。你能帮我吗?非常感谢!
答案1
@Alenanno 的方法效果很好。但我想提供一种不利用 TikZ 的 3D 坐标系的解决方案。我还说明了几种标记边的不同方法。
\documentclass[border=6pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{arrows.meta}
\begin{document}
\def\aes{cm*0.25}%%
\def\aeb{\aes*0.6}%%
\def\aepang{30}%% angle for projecting the back of box
\begin{tikzpicture}
%% Coordinates for the Front
\coordinate (F1) at (0,0);
\coordinate (F2) at ($(F1)+(10\aes,0)$);
\coordinate (F3) at ($(F1)+(0,30\aes)$);
\coordinate (F4) at (F2|-F3);
%% Coordinates for the back
\coordinate (B2) at ($(F2)+(\aepang:15\aeb)$);
\coordinate (B4) at ($(F4)+($(B2)-(F2)$)$);
\coordinate (B3) at ($(F3)+($(B2)-(F2)$)$);
%% Front
\draw[fill=red!30] (F3) rectangle (F2);
%% Side
\draw[fill=red!30] (F2) -- (B2) -- (B4) -- (F4) -- cycle;
%% Top
\draw[fill=red!30] (F3) -- (B3) -- (B4) -- (F4) -- cycle;
\draw[arrows=|-|] ([shift={(\aepang-90:6pt)}]F2) -- node[midway,anchor=north west] {15cm} ([shift={(\aepang-90:6pt)}]B2);
\draw[arrows=|-|] ([yshift=-6pt]F1) -- node[midway,below] {10cm} ([yshift=-6pt]F2);
\draw[arrows=|-|] ([xshift=-6pt]F1) -- node[midway,left] {30cm} ([xshift=-6pt]F3);
\end{tikzpicture}
\end{document}
这是应用移位坐标的一种方法transform canvas
。事实上,我编写了更多模板,可以轻松更改以创建您想要的每个矩形框。
\documentclass[border=6pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{arrows.meta}
\begin{document}
\def\aesW{10}%% width
\def\aesD{15}%% depth
\def\aesH{30}%% height
\def\aes{cm*0.15}%%
\def\aeb{\aes*0.6}%%
\def\aepang{30}%% angle for projecting the back of box
\begin{tikzpicture}[my face color/.style={fill=red!30}]
%% Coordinates for the Front
\coordinate (F1) at (0,0);
\coordinate (F2) at ($(F1)+(\aesW\aes,0)$);
\coordinate (F3) at ($(F1)+(0,\aesH\aes)$);
\coordinate (F4) at (F2|-F3);
%% Coordinates for the back
\coordinate (B2) at ($(F2)+(\aepang:\aesD\aeb)$);
\coordinate (B4) at ($(F4)+($(B2)-(F2)$)$);
\coordinate (B3) at ($(F3)+($(B2)-(F2)$)$);
\coordinate (B1) at (B2-|B3);
%% Front
\draw[my face color] (F3) rectangle (F2);
%% Side
\draw[my face color] (F2) -- (B2) -- (B4) -- (F4) -- cycle;
%% Top
\draw[my face color] (F3) -- (B3) -- (B4) -- (F4) -- cycle;
\draw[arrows=|-|,transform canvas={shift={(\aepang-90:6pt)}}] (F2) -- node[midway,anchor=north west] {\aesD cm} (B2);
\draw[arrows=|-|,transform canvas={yshift=-6pt}] (F1) -- node[midway,below] {\aesW cm} (F2);
\draw[arrows=|-|,transform canvas={xshift=-6pt}] (F1) -- node[midway,left] {\aesH cm} (F3);
\end{tikzpicture}
\end{document}
设置my face color={}
,设置高度、宽度和深度:
\def\aesW{30}%% width
\def\aesD{5}%% depth
\def\aesH{10}%% height
并将以下几行添加到上述模板中
\foreach \myn in {F1,B2,B3}
{
\draw[dashed] (B1) -- (\myn);
}
让你画
然后,您可以在主文档(或另一个独立文档)中写入以下内容:
\documentclass[border=6pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[on grid]
\node (A) {\includegraphics{example_02}};
\node (B) [right=2.5cm of A.east] {\includegraphics{example_03}};
\node (C) [below=2.5cm of A.south] {\includegraphics{example_03}};
\node (D) [right=2.5cm of C.east] {\includegraphics{example_02}};
\node (D/label) at (D.north west-|B.north west) {(d)};
\node (C/label) at (C.north west|-D/label) {(c)};
\node (A/label) at (C/label|-A.north west) {(a)};
\node (B/label) at (B.north west|-A/label) {(b)};
\end{tikzpicture}
\end{document}
创造
答案2
这是您提供的代码的一个示例,只需重用用于制作 3D 形状的部分路径。
顺便说一句,考虑为角落添加一个新功能,这样形状看起来会更好一些。要查看使用常规角度与将其更改为的区别round
,请参阅在 TikZ 中,何时“line join=miter”比“line join=round”更可取?
输出
代码
\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\tikzset{
every path/.style={line join=round}
}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\cubex}{1}
\pgfmathsetmacro{\cubey}{6}
\pgfmathsetmacro{\cubez}{2}
\draw[black, ultra thick,fill=yellow] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
\draw[black, ultra thick,fill=yellow] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
\draw[black, ultra thick, fill=yellow] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;
\draw[ultra thick, |-|] (-2,0,0) -- ++(0,-\cubey,0) node[midway, left] {30cm};
\draw[ultra thick, |-|] (-\cubex,-7,0) -- ++(\cubex,0,0) node[midway, below] {10cm};
\draw[ultra thick, |-|] ++(1.5,-\cubey,0) -- ++(0,0,\cubez) node[midway, below right] {15cm};
\end{tikzpicture}
\end{document}