# Rotating rectangle node in tikz without getting the right angle [duplicate]

I'm new to tikz and I am trying to make a perpendicular angle mark on a triangle by

\path[clip](C)--($(B)!(A)!(C)$)--(A);


and

\node[draw=black, rectangle,inner sep=0pt, outer sep=0pt, minimum size=4mm] at ($(B)!(A)!(C)$){};


But I am only getting a bottom of the square on the angle.

I am trying to save the hassle of finding the right angle to rotate for the square. So is there any easier way to draw the right angle mark with rotation?

Below is the code for my shape.

\begin{tikzpicture}
\coordinate[label=-90:$A$] (A) at (0,0);
\coordinate[label=-90:$C$] (C) at (4,0);
\coordinate[label=45:$B$] (B) at (1.25,3);
\draw (A)--(B)--(C)--(A);
\draw ($(A)!(B)!(C)$)--(B);
\draw ($(B)!(A)!(C)$)--(A);
\draw ($(A)!(C)!(B)$)--(C);
\begin{scope}
\path[clip](B)--($(A)!(B)!(C)$)--(C);
\node [draw=black, rectangle,minimum size=4mm,inner sep=0pt,outer sep=0pt] at ($(A)!(B)!(C)$) {};
\end{scope}
\path[clip](C)--($(B)!(A)!(C)$)--(A);
\node[draw=black, rectangle,inner sep=0pt, outer sep=0pt, minimum size=4mm] at ($(B)!(A)!(C)$){};
\begin{scope}
\end{scope}
\begin{scope}
\end{scope}
\end{tikzpicture}


• Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
– user31729
Aug 9, 2015 at 8:41

If the questions is "Why my code is not working" :

The problem is that you have to rotate your node in the direction of the angle.

If the questions is "How to draw right angle" :

You can define to path style named for example square and use it like this

\draw[red] (A') to[square] (C);


to draw right angle in (A') with direction (C).

Here is a full example:

\documentclass[tikz,border=1cm]{standalone}
\usetikzlibrary{calc}
\tikzset{square/.default={2mm},
square/.style= { to path={($(\tikztostart)!#1!(\tikztotarget)$)
-- ($(\tikztostart)!#1!(\tikztotarget)!#1!-90:(\tikztotarget)$)
-- ($(\tikztostart)!#1!-90:(\tikztotarget)$)
(\tikztotarget)}}
}

\begin{document}
\begin{tikzpicture}
\coordinate[label=-90:$A$] (A) at (0,0);
\coordinate[label=-90:$C$] (C) at (4,0);
\coordinate[label=45:$B$] (B) at (1.25,3);
\draw (A)--(B)--(C)--(A);
\draw (B) -- ($(A)!(B)!(C)$) coordinate (B');
\draw (A) -- ($(B)!(A)!(C)$) coordinate (A');
\draw (C) -- ($(A)!(C)!(B)$) coordinate (C');
\draw[red] (A') to[square] (C);
\draw[green] (B') to[square] (A);
\draw[blue] (C') to[square] (B);
\end{tikzpicture}
\end{document}


Note: There are other questions out there of how to draw right angle.

Here's a rotate along key which shifts the origin to the first specified point and then rotates the transformation matrix along the line from the first point to the second point.

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{calc}
\makeatletter
\tikzset{rotate along/.code args={(#1)#2--#3(#4)}{%
\pgfmathanglebetweenpoints{\tikz@scan@one@point\pgf@process(#1)}%
{\tikz@scan@one@point\pgf@process(#4)}%
\let\tikz@tmp=\pgfmathresult
\tikzset{shift={(#1)}, rotate=\tikz@tmp}%
}}
\begin{document}
\begin{tikzpicture}
\coordinate[label=-90:$A$] (A) at (0,0);
\coordinate[label=-90:$C$] (C) at (4,0);
\coordinate[label=45:$B$] (B) at (1.25,3);
\draw (A)--(B)--(C)--(A);
\draw (B) -- ($(A)!(B)!(C)$) coordinate (B');
\draw (A) -- ($(B)!(A)!(C)$) coordinate (A');
\draw (C) -- ($(A)!(C)!(B)$) coordinate (C');

\draw [red,   rotate along=(C') -- (A)] ( 0.25,0) |- (0,0.25);
\draw [green, rotate along=(A') -- (B)] (-0.25,0) |- (0,0.25);
\draw [blue,  rotate along=(B') -- (C)] ( 0.25,0) |- (0,0.25);

\end{tikzpicture}
\end{document}