# Tikz: Perpendicular FROM a line

With tikz-pgf, I can draw a perpendicular from a point to a line. Is there a robust method to draw a perpendicular from a point? For example, in the following code, say I want to raise a perpendicular, from a specific point on line BC outwards.

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (A) at (0,0);
\coordinate (B) at (2,4);
\coordinate (C) at (8,0);

\draw(A)--(B)--(C)--cycle;
\draw[red] (B) -- ($(A)!(B)!(C)$);

\node[label={below left:$A$}] at (A) {};
\node[label={above:$B$}] at (B) {};
\node[label={below right:$C$}] at (C) {};
\end{tikzpicture}
\end{document}


• You changed the position of the starting point in your question : so to draw from a point P on BC you can use (P) -- ++({2/sqrt(13)},{3/sqrt(13)}) (or to for faster compile (P) -- ++(0.5547001962252291,0.8320502943378437)), or you can use as I said calc to draw (P) -- ($(P)!1cm!90:(C)$). – Kpym Feb 23 at 10:02
• @Kpym I edited it because in the given form the suggested approach was obvious. I am looking for a general solution. – blackened Feb 23 at 10:03
• Hmm! I was being a fool, again. Say the point on BC is the midpoint. I can simply define that coordinate as, say, \coordinate (P) at ($(B)!0.5!(C)$). Then I can do, \draw (P)--($(P)!0.5!90:(C)$). – blackened Feb 23 at 10:18
• @blackened or \draw[red, thick] (P) -- ($(A)!(P)!(C)$); as you already did for your line from B. – CarLaTeX Feb 23 at 10:29

I just wrote such a style in this answer. I slightly changed the syntax, so you need to say

\draw[blue,vert={of {(B)--(C)} at (3,0)}];


to draw a vertical line at (3,0) that goes all the way until it hits BC. And I added vert outwards which is just a wrapper of the distance modifiers (see section 13.5.4 The Syntax of Distance Modifiers of the pgfmanual), and can be used as

    \draw[blue,vert outwards={from {($(B)!0.3!(C)$)} by 3cm on line to {(C)}}];


MWE

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[vert/.style args={of #1 at #2}{insert path={%
#2 -- (intersection cs:first
line={#1}, second line={#2--($#2+(0,10)$)}) }},
vert outwards/.style args={from #1 by #2 on line to #3}{insert path={
#1 -- ($#1!#2!90:#3$)
}}]
\coordinate (A) at (0,0);
\coordinate (B) at (2,4);
\coordinate (C) at (8,0);

\draw(A)--(B)--(C)--cycle;
\draw[red] (B) -- ($(A)!(B)!(C)$);

\node[label={below left:$A$}] at (A) {};
\node[label={above:$B$}] at (B) {};
\node[label={below right:$C$}] at (C) {};
\draw[blue,vert={of {(B)--(C)} at (3,0)}];
\draw[blue,vert outwards={from {($(B)!0.3!(C)$)} by 3cm on line to {(C)}}];
\end{tikzpicture}
\end{document}


if you willing to define specific point on line (B)--(C) with its relative position, than you can write your mwe as following simple solution:

\documentclass[tikz,border=10pt]{standalone}

\begin{document}
\begin{tikzpicture}
\coordinate[label=below left:$A$]   (A) at (0,0);
\coordinate[label=above:$B$]        (B) at (2,4);
\coordinate[label=below right:$C$]  (C) at (8,0);

\draw(A)--(B)-- coordinate[pos=0.3] (aux) % <--- coordinate of the point
(C)--cycle;
\draw[red] (aux) -- (aux |- A);
\end{tikzpicture}
\end{document}


Answer to the first version of the question

With intersections you can give a name to your triangle path, then build a "fake path" from (4,0) to a point after the intersection with the triangle (you don't need to calculate it exactly, see name path=riga and draw it to understand what I'm saying) and name it, then you can draw a line between the intersections with your triangle and your "fake path".

Answer to the second version of the question

If you want to start from a point on BC, you can use \coordinate (P) at ($(B)!.5!(C)$); with any value you want instead of .5 and do like you did for the line from B (see the thick red line in my MWE).

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{calc, intersections}
\begin{document}
\begin{tikzpicture}
\coordinate[label={below left:$A$}] (A) at (0,0);
\coordinate[label={above:$B$}] (B) at (2,4);
\coordinate[label={below right:$C$}] (C) at (8,0);

\draw[name path=trian](A)  --(B)--(C)--cycle;
\draw[red] (B) -- ($(A)!(B)!(C)$);
\path [name path=riga] (4,0) -- ++(0,3);
\path [name intersections={of=trian and riga}];
\draw (intersection-1) -- (intersection-2);
\coordinate (P) at ($(B)!.5!(C)$);
\draw[red, thick] (P) -- ($(A)!(P)!(C)$);
\end{tikzpicture}
\end{document}


• I understood the question as OP want a line starting from som point on BC and going perpendicular to BC outward some distance. (ok now I see that the question has been edited). – hpekristiansen Feb 23 at 10:02

Sorry, not tikz. I understand @hpekris's idea.

\documentclass[pstricks,border=10pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\foreach \i in {.3,.5,.7}{
\begin{pspicture}[PointSymbol=none,linejoin=1](0,-1)(8,4)
\pnodes(0,0){A}(2,4){B}(8,0){C}(4,0){I}
\psline(A)(B)(C)(A)
\pstHomO[HomCoef=\i,PosAngle=75]{B}{C}[M]
\pstProjection[PosAngle=-90]{A}{C}{B}[H]
\pstProjection[PosAngle=-90]{A}{C}{M}[M']
\pcline(M)(M')
\pcline(B)(H)
\end{pspicture}}
\end{document}


• Good, please could you decrease the velocity of the animation :-)? – Sebastiano Feb 23 at 10:34

Another PSTricks solution just for comparison purposes.

I provide some possible tricks but you can remove the parts that you don't want.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl}
\begin{document}
\foreach \i in {1,2,3}{%
\begin{pspicture}(8,5)
\pstTriangle(1,1){A}(7,1){B}(3,4){C}
\psline(C)(C|A)
\pnode([nodesep=\i]{B}C){P}
\psline(P)(P|A)
\pnode([nodesep=\i,offset=\i]{B}C){Q}
\psline[linecolor=red](P)(Q)
\end{pspicture}}
\end{document}