# problem at drawing 3D square for right angle with tikz, pgfplots

I'm drawing a 3D square for right angle following https://tex.stackexchange.com/a/163384/14423. That works fine, but I try filling that square and the results isn't the spected:

\documentclass{memoir}
\usepackage{tikz,pgfplots}
\usetikzlibrary{calc}

\pgfplotsset{ /pgfplots/area style/.style={%
area cycle list,
area legend,
axis on top,
}}

\newcommand{\RightAngle}[4][5pt]{%
\draw[fill] ($#3!#1!#2$)
--($#3!2!($($#3!#1!#2$)!.5!($#3!#1!#4$)$)$)
--($#3!#1!#4$) ;
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[scale=0.65,view={130}{30},axis equal,axis on top,axis lines=center,xlabel=$x(t)$,ylabel=$y(t)$,zlabel=$z(t)$,xtick=\empty,ytick=\empty,ztick=\empty]
\addlegendentryexpanded{$T(t)$}
\addlegendentryexpanded{$T'(t)$}
\addlegendentryexpanded{$N(t)$}
%\addlegendentryexpanded{$\Ce$}
\coordinate (P) at (0.261,1.047,1);
\coordinate (T) at (0.511,2.047,1);
\coordinate (N) at (0.261,1.047,-0.125);
\RightAngle{(T)}{(P)}{(N)};
\end{axis}
\end{tikzpicture}

\end{document}


As you can see there is a dotted node and the square for right angle is not filled completely. What am I doing wrong? and how get square filled with dashed lines?

• Where is the dotted node? – cfr Dec 25 '15 at 2:09
• I don't get the output you posted from the code you posted. My output looks rather different. – cfr Dec 25 '15 at 2:11
• How different is? I obtain that picture (maybe I miss some command). Can you show me your output please? – juanuni Dec 25 '15 at 2:26
• The dotted node is below z(t) – juanuni Dec 25 '15 at 2:27
• Oh, OK. It is a dot and not a dotted node. I was looking for dotted somewhere. You need to specify a suitable compatibility option to get the output you posted. If you run the code you posted, you will probably not get the output you posted unless you've configured defaults somewhere where are not the standard ones. – cfr Dec 25 '15 at 2:51

Because you are using something optimised for an older version of pgfplots which gave wrong output, you need to specify a version to get the correct output. At least, that is how I roughly understood the console warnings. Adding the compatibility option newest gave me the output posted in the question. So, with advice from Alenanno, this could be set to e.g. 1.12 which seems to be the version I get if I ask for newest.

When you specify the right angle, you specify from left to right of the bottom and then up to the top right and nothing else. TikZ completes the path using the shortest possible route i.e. from top right to bottom left of the square and fills the result i.e. half of the square. You need to specify that the path goes through P before returning to the start point in order to fill the square.

\newcommand{\RightAngle}[4][5pt]{%
\draw[fill] ($#3!#1!#2$) -- ($#3!2!($($#3!#1!#2$)!.5!($#3!#1!#4$)$)$) -- ($#3!#1!#4$) -- #3  -- cycle;
}


I also moved the legend a bit so I could see what I was doing.

To fill the square with lines, try the patterns library and use pattern rather than fill for the path. For example:

\newcommand{\RightAngle}[4][5pt]{%
\draw[pattern=north east lines] ($#3!#1!#2$) -- ($#3!2!($($#3!#1!#2$)!.5!($#3!#1!#4$)$)$) -- ($#3!#1!#4$) -- #3  -- cycle;
}


Complete code:

\documentclass[tikz,border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usetikzlibrary{calc,patterns}

\pgfplotsset{ /pgfplots/area style/.style={%
area cycle list,
area legend,
axis on top,
}}

\newcommand{\RightAngle}[4][5pt]{%
\draw[pattern=north east lines] ($#3!#1!#2$) -- ($#3!2!($($#3!#1!#2$)!.5!($#3!#1!#4$)$)$) -- ($#3!#1!#4$) -- #3  -- cycle;
}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
scale=0.65,
view={130}{30},
axis equal,
axis on top,
axis lines=center,
xlabel=$x(t)$,
ylabel=$y(t)$,
zlabel=$z(t)$,
xtick=\empty,
ytick=\empty,
ztick=\empty,
legend style={anchor=east}
]
\addlegendentryexpanded{$T(t)$}
\addlegendentryexpanded{$T'(t)$}
\addlegendentryexpanded{$N(t)$}
%\addlegendentryexpanded{$\Ce$}

• I have to admit I didn't understand the question very well, but using newest isn't advisable, because compiling the same code with a newer version that is released later might break the output. I think even the author advised against it somewhere. Better choose a version that gives the desired output and stick with it. – Alenanno Dec 25 '15 at 3:08
• @Alenanno I just used it because I am not, frankly, familiar with the package and didn't know what version to use. Should I put 1.12? Is that the current version? – cfr Dec 25 '15 at 3:14
• I think so, but it's not mandatory to use the latest in every case. If 1.10 worked better, then I'd go for it. :D you can try and test. newest is not even a problem but it might not be reliable as time goes on. – Alenanno Dec 25 '15 at 3:17
• @Alenanno I've put 1.12.1 which is what I seem to have. I was really just trying to reproduce the problem in the question. Since this reproduced the problem, for my purposes, no other version could work better ;). – cfr Dec 25 '15 at 3:19