# drawing a line without coordinates

I want to draw a line that goes through a point A en B but does not stop at A nor at B. Can anybody help. I want to use it for constructions in optics.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\draw[very thin, dotted, color=gray,step= 0.5 cm] (-12.1,-5.1) grid (12.1,5.1);
\draw (-12.1,0) -- (12.1,0) ;
\draw [<->, ultra thick] (0,-3.2) -- (0,3.2) ;
\coordinate (L1) at (0,3);
\coordinate (L2) at (0,-3);
\coordinate (L3) at (0,1.5); %evenwijdig met hoofdas
\coordinate (V1) at (9,0);
\coordinate (V2) at (9,1.5);
\coordinate (F1) at (4,0);
\coordinate (F2) at (-4,0);
\draw [->, thick] (V1) -- (V2) node[right] {voorwerp};
\fill (F1) circle (2pt) node[below] {$f_1$};
\fill (F2) circle (2pt) node[below] {$f_2$};
\draw [name path=A--B] (V2) -- (L3);
\draw [name path=C--D] (L1) -- (L2);
\path [name intersections={of=A--B and C--D,by=E}];
\node [fill=red,inner sep=1pt,label=-90:$E$] at (E) {};
\draw [name path=K--L] (E) -- (F2);
\line(4,2){6};
\end{tikzpicture}
\end{document}

-
I don't see where A or B are defined in your code. Which line is it that you are trying to draw? How far beyond the points do you want it to extend - is it a known distance or some proportion of the distance between them? –  Andrew Stacey Sep 18 '12 at 15:37
add comment

## 3 Answers

an alternative that I like to use

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\path (1,0) node[label=above:a,circle,fill=green,](a){} --
(3,2)node[label=above:b,circle,fill=green,](b){}
coordinate[pos=1.5](ff)
coordinate[pos=-0.5](dd);
\draw (dd) -- (ff);
\end{tikzpicture}
\end{document}


Using [pos = xx] to place a point ( node or coordinates) as well as between the two points at the segment beyond. Negative values ​​are used to place the point before the first.

-
add comment

Here's one possibility using the <coord>!<number>!<coord> syntax; the line will extend past both coordinates by 1cm:

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

\begin{document}

\begin{tikzpicture}
\node[circle,fill=green,label=left:a] (a) at (1,0) {};
\node[circle,fill=green,label=left:b] (b) at (3,2) {};
\draw[blue] ($(a)!-1cm!(b)$) -- ($(b)!-1cm!(a)$);
\end{tikzpicture}

\end{document}


Sections 13.5.3 The Syntax of Partway Modifiers and 13.5.4 The Syntax of Distance Modifiers of the pgfmanual contain the description of useful operations involving coordinates.

The shorten option gives another simpler alternative:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\node[circle,fill=green,label=left:a] (a) at (1,0) {};
\node[circle,fill=green,label=left:b] (b) at (3,2) {};
\node[circle,fill=green,label=left:c] (c) at (5,2) {};
\node[circle,fill=green,label=left:d] (d) at (7,0) {};
\draw[blue,shorten >=-1cm,shorten <=-1cm] (a) -- (b);
\draw[red,shorten >=-2cm,shorten <=-1cm] (c) -- (d);
\end{tikzpicture}

\end{document}


-
First possibility can be simpler: \draw[blue] ($(a)!-1cm!(b)$) -- ($(b)!-1cm!(a)$); –  Paul Gaborit Sep 18 '12 at 17:30
@PaulGaborit yes, of course. I updated my answer. Thank you. –  Gonzalo Medina Sep 18 '12 at 17:38
Ok... But you forgot to remove the call to let! ;-) I corrected myself. –  Paul Gaborit Sep 18 '12 at 17:54
add comment

A PSTricks solution just for comparison purpose.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pst-eucl}

\begin{document}
\begin{pspicture}[showgrid](5,5)
\pstGeonode[PosAngle={90}]
(2,2){A}
(3,3){B}
\pstLineAB[nodesep=-1,linecolor=red]{A}{B}
\end{pspicture}
\end{document}


We can use nodesepA and nodesepB instead of nodesep if we want to have asymmetric line extension.

-
Why did you answer as cw? –  Marco Daniel Sep 18 '12 at 17:16
@MarcoDaniel: To avoid getting reputation points. –  I am who I say I am Sep 18 '12 at 17:20
I am confused! I think your answer is legitimate to show an alternative. –  Marco Daniel Sep 18 '12 at 17:23
@MarcoDaniel: :-) –  I am who I say I am Sep 18 '12 at 17:24
add comment