Q:

How to draw with TikZ a line perpendicular to a line from a point?

Given a point and line, how to draw a perpendicular line?
For instance, how do I draw the line segment AP following graph with TikZ, without hand-mathing the location of point P? Math gives me 3/8 and 13/16 in this case, but calculating it by hand is inelegant IMO and not always possible.

\begin{tikzpicture}
    \coordinate[label=below left:\(A\)] (A) at (0,0);
    \coordinate[label=below right:\(B\)] (B) at (2,0);
    \coordinate[label=above left:\(C\)] (C) at (0,1);
    \coordinate[label=above right:\(P\)] (P) at (0.375,0.8125);
        % ^^ there must be a way better than this ^^
    \draw (A) -- (B) -- (C) -- (A) -- (P);
\end{tikzpicture}

I tried googling and reading the PGF manual, but I wasn't intelligent enough to find any related content :( I think I missed some libraries or so.

A:

With calc library (see section 13.5 Coordinate Calculations) is easy:
\documentclass[tikz,border=2mm]{standalone} 
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}
    \coordinate[label=below left:\(A\)] (A) at (0,0);
    \coordinate[label=below right:\(B\)] (B) at (2,0);
    \coordinate[label=above left:\(C\)] (C) at (0,1);
%    \coordinate[label=above right:\(P\)] (P) at (0.375,0.8125);
        % ^^ there must be a way better than this ^^
    \draw (A) -- (B) -- (C) -- cycle;
    \draw (A) -- ($(C)!(A)!(B)$) node[above right] {\(P\)};
\end{tikzpicture}
\end{document}

