tikz-pgf – How to Draw a Perpendicular Line with the Package tkz-euclide

tikz-pgftkz-euclide

How to draw a perpendicular line from "P" to segment "AB"?

Picture

Here is the code:

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz,tkz-euclide,xcolor,graphicx}
\usetkzobj{all}

\begin{document}
\tikz{
\coordinate(A)at(0,0);
\coordinate(B)at(5,0);
\coordinate(P)at(3.7896542,3);

\draw[thick](A)--(B);

\tkzDrawPoint[color=red](A)
 \tkzLabelPoint[below=2pt](A){$A$}
\tkzDrawPoint[color=red](B)
 \tkzLabelPoint[below=2pt](B){$B$}


\tkzDrawPoint[fill=yellow](P)
 \tkzLabelPoint[above=2pt](P){$P$}
}

\end{document}

Best Answer

You could use \tkzDrawAltitude(A,B)(P) and get p from there.

Output

example image

Code

\documentclass[margin=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz,tkz-euclide,xcolor,graphicx}
\usetkzobj{all}

\begin{document}
\begin{tikzpicture}

\tkzDefPoints{0/0/A, 5/0/B, 3.7896542/3/P}

\draw[thick](A)--(B);

\tkzDrawPoints[color=red](A,B)
\tkzLabelPoint[below=2pt](A){$A$}
\tkzLabelPoint[below=2pt](B){$B$}

\tkzDrawPoint[fill=yellow](P)
\tkzLabelPoint[above=2pt](P){$P$}

\tkzDrawAltitude(A,B)(P) \tkzGetPoint{p}
\tkzDrawSegment(P,p)

\tkzLabelPoint[below=2pt](p){$p$}

\end{tikzpicture}
\end{document}