我试图在三维 tikz 图形中表示一些长度。但结果看起来很奇怪,因为花括号没有正确转换。该transform shape
选项(对标签有用)对括号没有影响。我也尝试用箭头替换括号,但效果并没有好多少,因为箭头尖端也没有转换。
如何在与纸张不平行的平面上绘制花括号或箭头?
\documentclass[border=.2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{3d}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{graphicx}
\newcommand{\mirror}{\scalebox{-1}[1]}
\tikzset{%
% changing the axis to point in the directions that I am used to from school:
% x-axis pointing toward the reader,
% y-axis pointing right and
% z-axis pointing up
% using the same lengthes as TikZ' default settings specified in it's documentation on page 134
3D/.style={
x={(-3.85mm, -3.85mm)},
y={(1cm, 0cm)},
z={(0cm, 1cm)},
},
}
\begin{document}
\begin{tikzpicture}[3D]
\newcommand{\width}{2}
\newcommand{\height}{1}
\newcommand{\axislength}{2}
\draw[gray, ->] (0,0,0) -- (\axislength,0,0) node[below left] {$x$};
\draw[gray, ->] (0,0,0) -- (0,\axislength,0) node[right] {$y$};
\draw[gray, ->] (0,0,0) -- (0,0,\axislength) node[above] {$z$};
\begin{scope}[canvas is xz plane at y=0, transform shape]
\newcommand{\distance}{.5em}
\draw (0,0) rectangle ++(-\width, \height);
\draw[decorate,decoration={brace}] (\distance, 0) -- node[right]{\mirror{$h$}} ++(0, \height);
\draw[decorate,decoration={brace}] (0,0) ++(0, \height) ++(0, \distance) -- node[above]{\mirror{$w$}} ++(-\width, 0);
% \draw[<->] (0,0) ++(.5em, 0) -- node[right]{\mirror{$h$}} ++(0, \height);
% \draw[<->] (0,0) ++(0, \height) ++(0, .5em) -- node[above]{\mirror{$w$}} ++(-\width, 0);
\end{scope}
\end{tikzpicture}
\end{document}
答案1
转换低级 pgf 内容的命令称为\pgflowlevelsynccm
。应谨慎使用。您可以在范围的末尾使用它,以便其效果不会超出此范围。还请注意,您的\mirror
命令可以用 pgf 键替换xscale=-1
(并且无论如何tikz
都会加载graphicx
)。
\documentclass[border=.2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{3d}
\usetikzlibrary{decorations.pathreplacing}
\newcommand{\mirror}{\scalebox{-1}[1]}
\tikzset{%
% changing the axis to point in the directions that I am used to from school:
% x-axis pointing toward the reader,
% y-axis pointing right and
% z-axis pointing up
% using the same lengthes as TikZ' default settings specified in it's documentation on page 134
3D/.style={
x={(-3.85mm, -3.85mm)},
y={(1cm, 0cm)},
z={(0cm, 1cm)},
},
}
\begin{document}
\begin{tikzpicture}[3D]
\newcommand{\width}{2}
\newcommand{\height}{1}
\newcommand{\axislength}{2}
\draw[gray, ->] (0,0,0) -- (\axislength,0,0) node[below left] {$x$};
\draw[gray, ->] (0,0,0) -- (0,\axislength,0) node[right] {$y$};
\draw[gray, ->] (0,0,0) -- (0,0,\axislength) node[above] {$z$};
\begin{scope}[canvas is xz plane at y=0, transform shape]
\newcommand{\distance}{.5em}
\draw (0,0) rectangle ++(-\width, \height);
\pgflowlevelsynccm
\draw[thick,decorate,decoration={brace,mirror}] (\distance, 0) --
node[left,xscale=-1]{$h$} ++(0, \height);
\draw[thick,decorate,decoration={brace,mirror}] (0,0) ++(0, \height)
++(0, \distance) -- node[above,xscale=-1]{$w$} ++(-\width, 0);
\end{scope}
\end{tikzpicture}
\end{document}
我个人会使用正交投影和一些缩写。这样就可以制作出必需的动画。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\foreach \X in {5,15,...,355}
{\tdplotsetmaincoords{70}{\X}
\begin{tikzpicture}[tdplot_main_coords,declare function={w=4;h=2;a=4;}]
\path[tdplot_screen_coords,use as bounding box] (-1.5*a,-0.5*a) rectangle (1.5*a,1.2*a);
\draw[gray, -stealth] (0,0,0) -- (a,0,0) node[below left] {$x$};
\draw[gray, -stealth] (0,0,0) -- (0,a,0) node[right] {$y$};
\draw[gray, -stealth] (0,0,0) -- (0,0,a) node[above] {$z$};
\begin{scope}[canvas is xz plane at y=0, transform shape]
\newcommand{\distance}{.5em}
\draw (0,0) rectangle ++(-w,h);
\pgflowlevelsynccm
\draw[thick,decorate,decoration={brace,mirror}] (\distance, 0) --
node[left,xscale=-1]{$h$} ++(0, h);
\draw[thick,decorate,decoration={brace,mirror}] (0,0) ++(0, h)
++(0, \distance) -- node[above,xscale=-1]{$w$} ++(-w, 0);
\end{scope}
\end{tikzpicture}}
\end{document}