# line passing through a point and extending

What if I only want to extend the line 1cm in one direction but not the other? I found this on another post here from a year ago.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1},
extended line/.style={shorten >=-#1,shorten <=-#1},
extended line/.default=1cm]

\node [dot=A] at (0,0) {};
\node [dot=B] at (3,1) {};
\node [dot=P] at (1.9,-1.6) {};

\draw [extended line=0.5cm] (A) -- (B);
\draw [extended line] ($(A)!(P)!(B)$) -- (P);

\fill [red] ($(A)!(P)!(B)$) circle [radius=2pt];

\end{tikzpicture}
\end{document}

-

Your figure extends on both ends since extended line style has shorten <=-#1. If you remove that, then the line will not be extended on the other end. But I suggest that you add another style.

one end extended/.style={shorten >=-#1},
one end extended/.default=1cm,


Here is the complete code and usage.

%\documentclass{article}
\documentclass[preview,border=5]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,label={#1},name=#1},
extended line/.style={shorten >=-#1,shorten <=-#1},
extended line/.default=1cm,
one end extended/.style={shorten >=-#1},
one end extended/.default=1cm,
]

\node [dot=A] at (0,0) {};
\node [dot=B] at (3,1) {};
\node [dot=P] at (1.9,-1.6) {};

\draw [extended line=0.5cm] (A) -- (B);
\coordinate (P') at ($(A)!(P)!(B)$);
\draw [one end extended] (P') -- (P);

\end{tikzpicture}
\end{document}


## Edit

I added P' as name of the coordinate ($(A)!(P)!(B)$) as suggested in comment to speed up compilation time.

-
Saving the projected point as a named node might speed up the compilation a bit. :-) –  kiss my armpit Mar 9 '13 at 0:33
@GarbageCollector Done. I haven't timed this. But I wasn't able to see a noticeable difference in compilation time. :) –  hpesoj626 Mar 9 '13 at 0:42

In PSTricks, we can use nodesepA (only for A end), nodesepB (only for B end), or nodesep (for both A and B ends) to shorten or extend the line ends.

\documentclass[pstricks]{standalone}
\usepackage{pst-eucl}
\begin{document}
\begin{pspicture}(8,6)
\pstGeonode(2,3){A}(6,5){B}(6,2){P}
\pstProjection[PointName=none]{A}{B}{P}
\psset{nodesep=-1}
\pstLineAB{A}{B}
\pstLineAB[nodesepB=0]{P}{P'}
\end{pspicture}
\end{document}

-

This is possible with tkz-euclide or tkz-base but here a solution with only tikz

\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{calc}

\tikzset{%
($(\tikztostart)!-#1!(\tikztotarget)$)--($(\tikztotarget)!-#2!(\tikztostart)$)%
\tikztonodes}}
}

\begin{document}
\begin{tikzpicture}[dot/.style={circle,inner sep=1pt,fill,name=#1}]

\node [dot=A,label={below:$A$}] at (0,0) {};
\node [dot=B,label={below:$B$}] at (3,1) {};
\node [dot=P,label={right:$P$}] at (1.9,-1.6) {};

\draw [add=.5 and .5] (A) to (B);
\coordinate (P') at ($(A)!(P)!(B)$);
\draw [add=0 and .5] (P') to (P);