# tikz: curley brace in a non-parallel plane

I am trying to denote some lengthes in a three dimensional tikz figure. But the result looks weird because the curley braces are not properly transformed. The transform shape option (which does the trick for the labels) has no effect on the braces. I have also tried to replace the brces by arrows but that is not much better because the arrow tips are not transformed either.

How can I draw curley braces or arrows in a plane which is not parallel to the paper?

\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}


The command that transforms low level pgf stuff is called \pgflowlevelsynccm. It is to be used with care. You can use it here at the end of the scope, so that its effects won't go beyond this scope. Note also that your \mirror command can be replaced by the pgf key xscale=-1 (and tikz loads graphicx anyway).

\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}


Personally I would use an orthographic projection and a few abbreviations. This allows one to produce the mandatory animation.

\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}