Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
3  
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? –  Loop Space Sep 18 '12 at 15:37

3 Answers 3

up vote 10 down vote accepted

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.

enter image description here

share|improve this answer

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}

enter image description here

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}

enter image description here

share|improve this answer
    
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

A PSTricks solution just for comparison purpose.

enter image description here

\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.

share|improve this answer
    
Why did you answer as cw? –  Marco Daniel Sep 18 '12 at 17:16
    
@MarcoDaniel: To avoid getting reputation points. –  Please don't touch Sep 18 '12 at 17:20
2  
I am confused! I think your answer is legitimate to show an alternative. –  Marco Daniel Sep 18 '12 at 17:23
    
@MarcoDaniel: :-) –  Please don't touch Sep 18 '12 at 17:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.