Making a right-angle mark using the calc package in TikZ [duplicate]

I have a right triangle and the altitude from the vertex of its right angle drawn. A=(-4,0), B=(0,3), and C=(0,0) are the vertices of the triangle, and F=(-36/25,48/25) is the foot of the altitude on the hypotenuse AB. I use the following commands to draw a right-angle mark.

\coordinate (U) at ($(F)!3mm!45:(A)$);
\draw ($(A)!(U)!(F)$) -- (U) -- ($(C)!(U)!(F)$);

Why doesn't it look like three sides of a square with edge length 3mm?

\documentclass{amsart}
\usepackage{amsmath}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\begin{document}

\begin{tikzpicture}

\coordinate (circle_1) at (-8/5, 4/5);
\draw[blue, fill=blue=25!] (circle_1) circle (4/5);

\coordinate (circle_1) at (-3/5, 9/5);
\draw[orange, fill=orange=25!] (circle_1) circle (3/5);

\path (-4,0) coordinate (A) (0,3) coordinate (B) (0,0) coordinate (C);
\coordinate (F) at (-36/25,48/25);
\draw (A) -- (B) -- (C) -- cycle;
\draw (F) -- (C);

%A right-angle mark is drawn at F.
\coordinate (U) at ($(F)!3mm!45:(A)$);
\draw ($(A)!(U)!(F)$) -- (U) -- ($(C)!(U)!(F)$);

%A right-angle mark is drawn at C.
\coordinate (U) at ($(C)!3mm!-45:(A)$);
\draw ($(A)!(U)!(C)$) -- (U) -- ($(B)!(U)!(C)$);

\end{tikzpicture}

\end{document}
• Nice figure! I may use it to accompany a problem on a test in Geometry. – user74973 Apr 23 '19 at 21:46

1 Answer

This is a problem related to the inaccuracies of \pgfpintnormalised, as discussed in this nice answer. Your problem is the very same as the one noted here. The issues do not arise when one draws things with arguably more direct methods.

\documentclass{amsart}
\usepackage{amsmath}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}

\coordinate (circle_1) at (-8/5, 4/5);
\draw[blue, fill=blue=25!] (circle_1) circle (4/5);

\coordinate (circle_1) at (-3/5, 9/5);
\draw[orange, fill=orange=25!] (circle_1) circle (3/5);

\path (-4,0) coordinate (A) (0,3) coordinate (B) (0,0) coordinate (C);
\coordinate (F) at ($(A)!(C)!(B)$);
\draw (A) -- (B) -- (C) -- cycle;
\draw (F) -- (C);

%A right-angle mark is drawn at F.
\draw ($(F)!{sqrt(9/2)*1mm}!(A)$) coordinate (aux) --
($(aux)!{sqrt(9/2)*1mm}!90:(A)$) -- ($(F)!{sqrt(9/2)*1mm}!(C)$);
(C);

%A right-angle mark is drawn at C.
\draw ($(C)!{sqrt(9/2)*1mm}!(A)$) coordinate (aux) --
($(aux)!{sqrt(9/2)*1mm}!-90:(A)$) -- ($(C)!{sqrt(9/2)*1mm}!(B)$);
(C);

\end{tikzpicture}
\end{document}

• When I used 3cm instead of 3mm, three sides of a square were drawn. – A gal named Desire Apr 23 '19 at 22:30
• Fine. I will manually encode the coordinates of the vertices for the square. – A gal named Desire Apr 23 '19 at 22:32
• @AgalnamedDesire Seems we have a problem communicating. I do not know what you mean by your first comment, and I also do not know why you do not think that my previous answer does not deserve to be accepted. All I can say is that the above code does not seem to suffer from the inaccuracies, nor does it contain 3mm anywhere such that I can appreciate what you mean by "When I used 3cm instead of 3mm,...". – user121799 Apr 23 '19 at 22:36
• I just accepted it. Yes, that does give a box - right-angle mark - with diagonals of length 3mm. – A gal named Desire Apr 23 '19 at 23:56
• @AgalnamedDesire This is all because of the internal use of \pgfpointnormalised in tikzlibrarycalc.code.tex. Both ways use it but if you do the projections the inaccuracies get amplified by the fact that you subtract something that is proportional to the scalar product with the outcome of \pgfpointnormalised. The perhaps cleanest way would be to use Mark Wibrow's fix. This also explains the discrepancy between 3mm and 3cm, simply the inaccuracy gets amplified less. – user121799 Apr 24 '19 at 0:06