Another, much simpler, solution for drawing right angles is to use the angle library:
\documentclass[tikz, border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{3d}
\usetikzlibrary{calc}
\usetikzlibrary{angles}
\tikzset{
axis/.style = {color = blue,very thin,->,},
% Set the axonometric 3d view that you prefer setting x, y, z unit vectors
x={(-135:0.8cm)},
y={(0:1cm)},
z={(90:1cm)},
}
\begin{document}
\begin{tikzpicture}
% -- add these 3 lines if axis is preferred
%\draw[axis] (0, 0, 0) -- (5, 0, 0) node [right] {$X$};
%\draw[axis] (0, 0, 0) -- (0, 5, 0) node [above] {$Y$};
%\draw[axis] (0, 0, 0) -- (0, 0, 5) node [above] {$Z$};
% define points
\path
(0,0,0) coordinate (d1)
(4,0,0) coordinate (d2)
(4,4,0) coordinate (d3)
(0,4,0) coordinate (d4)
(3,2,0) coordinate[label=left:$A$] (d5) node [circle, fill=black, inner sep=1.5pt] {}
(1,3,0) coordinate[label=right:$B$] (d6) node [circle, fill=black, inner sep=1.5pt] {}
(1,1,0) coordinate[label=below:$K$] (d8)
(1,1,2) coordinate[label=$M$] (d9) node [circle, fill=black, inner sep=1.5pt] {}
($(d5)!0.7!(d6)$) coordinate[label=below:$H$] (d7)
;
\draw (d1) -- (d2) -- (d3) -- (d4) -- cycle;
\draw (d5) -- (d6);
\draw (d8) -- (d7) -- (d9) -- cycle;
% common angle
\pic [draw=blue, pic text={$\beta$} ] {angle = d3--d2--d1};
% Right angle
\pic [draw=red, angle radius=0.33cm ] {right angle = d5--d7--d8};
\pic [draw=red, angle radius=0.33cm ] {right angle = d6--d7--d9};
\pic [draw=red, angle radius=0.33cm ] {right angle = d7--d8--d9};
\end{tikzpicture}
\end{document}

The syntax is easy:
\pic[draw, *other_options*] {right angle= *point1* -- *point2* -- *point3*}
where point1, point2 and point3 are coordinates defining the angle, point2 being the vertex. If right angle is replaced by angle, the usual arc is drawn.
EDIT: Adding calculation of H and M points using coordinate systems defined at arbitrary planes (see section 40.2 of pgf manual v3.1) and intersection of perpendicular lines (see section 13.3.1):
EDIT 2: fix a bug in rotated XY plane
\documentclass[tikz, border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{3d}
\usetikzlibrary{calc}
\usetikzlibrary{angles}
\tikzset{
axis/.style = {color = blue,very thin,->,},
% Set the axonometric 3d view that you prefer setting x, y, z unit vectors
x={(-135:0.8cm)},
y={(0:1cm)},
z={(90:1cm)},
}
\begin{document}
\begin{tikzpicture}
% -- add these 3 lines if axis is preferred
%\draw[axis] (0, 0, 0) -- (5, 0, 0) node [right] {$X$};
%\draw[axis] (0, 0, 0) -- (0, 5, 0) node [above] {$Y$};
%\draw[axis] (0, 0, 0) -- (0, 0, 5) node [above] {$Z$};
% define points
\path
(0,0,0) coordinate (d1)
(4,0,0) coordinate (d2)
(4,4,0) coordinate (d3)
(0,4,0) coordinate (d4)
(3,2,0) coordinate[label=left:$A$] (A) node [circle, fill=black, inner sep=1.5pt] {}
(1,3,0) coordinate[label=right:$B$] (B) node [circle, fill=black, inner sep=1.5pt] {}
(1,1,0) coordinate[label=below:$K$] (K) node [circle, fill=black, inner sep=1.5pt] {}
;
\draw (d1) -- (d2) -- (d3) -- (d4) -- cycle;
\draw (A) -- (B);
% common angle
\pic [draw=blue, pic text={$\beta$} ] {angle = d3--d2--d1};
% Finding H.
% The XY plane is rotated to adjust the X-axis to the A-B line.
\draw[canvas is xy plane at z=0] ($ (A)!1!90:(B) $) coordinate (Bp);
\draw[
plane origin = { (A) },
plane x = { (B) },
plane y = { (Bp) },
canvas is plane,
red
]
(A -| K) coordinate[label=below:$H$] (H) node [circle, fill, inner sep=1.5pt] {}
;
% Finding M.
% Now the coordinate system has the unit vector X fixed on the line K-H, and the
% unit vector Y is the original unit vector Z.
\draw[
plane origin = { (K) },
plane x = { (H) },
plane y = { ($ (K) + (0,0,1) $) },
canvas is plane,
red
]
(0,0) -- (0,2) coordinate[label=above:$M$] (M) node [circle, fill, inner sep=1.5pt] {}
;
\draw[red] (K) -- (H);
\draw[red] (K) -- (M);
\draw[red] (M) -- (H);
% Right angle
\pic [draw=red, angle radius=0.33cm ] {right angle = A--H--K};
\pic [draw=red, angle radius=0.33cm ] {right angle = B--H--M};
\pic [draw=red, angle radius=0.33cm ] {right angle = H--K--M};
\end{tikzpicture}
\end{document}

EDIT 3: Check calculation at differet view points.
\documentclass[tikz, border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{3d}
\usetikzlibrary{calc}
\usetikzlibrary{angles}
\usetikzlibrary{perspective}
\tikzset{
axis/.style = {color = blue,very thin,->,},
% Set the axonometric 3d view that you prefer.
3d view={120}{20},
% Caution about perspective library: Vanishing points will not work in this example
}
\begin{document}
\foreach \angle in {5,15,...,355}
{
\begin{tikzpicture}[3d view={\angle}{20}]
% -- add these 3 lines if axis is preferred
\draw[axis] (0, 0, 0) -- (5, 0, 0) node [right] {$x$};
\draw[axis] (0, 0, 0) -- (0, 5, 0) node [above] {$y$};
\draw[axis] (0, 0, 0) -- (0, 0, 3) node [above] {$z$};
% define points
\path
(0,0,0) coordinate (d1)
(4,0,0) coordinate (d2)
(4,4,0) coordinate (d3)
(0,4,0) coordinate (d4)
(3,2,0) coordinate (A) node [circle, fill=black, inner sep=1pt] {}
(1,3,0) coordinate (B) node [circle, fill=black, inner sep=1pt] {}
(1,1,0) coordinate (K) node [circle, fill=black, inner sep=1pt] {}
;
\draw (d1) -- (d2) -- (d3) -- (d4) -- cycle;
\draw (A) -- (B);
\draw[canvas is xy plane at z=0, help lines] (d1) grid (d3);
% Finding H.
% % The XY plane is rotated to adjust the X-axis to the A-B line.
\path[canvas is xy plane at z=0] ($ (A)!1!90:(B) $) coordinate (Bp);
\draw[
plane origin = { (A) },
plane x = { (B) },
plane y = { (Bp) },
canvas is plane,
red
]
(A -| K) coordinate (H) node [circle, fill, inner sep=1pt] {}
;
% Finding M.
% Now the coordinate system has the unit vector X fixed on the line K-H, and the
% unit vector Y is the original unit vector Z.
\draw[
plane origin = { (K) },
plane x = { (H) },
plane y = { ($ (K) + (0,0,1) $) },
canvas is plane,
red
]
(0,0) -- (0,2) coordinate (M) node [circle, fill, inner sep=1pt] {}
;
\draw[red] (K) -- (H);
\draw[red] (K) -- (M);
\draw[red] (M) -- (H);
% Right angle
\pic [draw=red, angle radius=0.2cm ] {right angle = A--H--K};
\pic [draw=red, angle radius=0.2cm ] {right angle = B--H--M};
\pic [draw=red, angle radius=0.2cm ] {right angle = H--K--M};
\tikzset{x={(1cm,0)}, y={(0,1cm)}}
\path (-6,-2.5) rectangle (6,4);
\end{tikzpicture}
}
\end{document}

Animation done using this solution.
tikz-pgf? – cfr Nov 25 '14 at 01:20