17

From How to draw a line passing through a point and perpendicular to another? I learned to use shorten to extend lines. But the extended part doesn't seem to "really exist". For example, I would like to connect two predefined dots and extend the line segment by 1cm and then define the new end as "C" for later use. But \draw[shorten >=-1cm] (A) -- (B) coordinate (C) will only give me a C which is actually still B.

What I really need to do is to find the intersection of two extended lines, but I think the tough part is to make the extended lines "real".

22

You're right, the shorten > syntax doesn't "actually" extend the line, but works on a lower level. In your case, I would use \usetikzlibrary{calc}, which gives you access to a lot of nifty coordinate calculations.

Your desired result could be achieved with the syntax

\draw (A) -- ($(B)!-1cm!(A)$) coordinate (C);

where the ($...$) encloses the calc syntax, and the (<first node>)!<distance>!(<second node>) specifies the coordinate that lies at <distance> along the line from <first node> to <second node>.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\begin{document}
\begin{tikzpicture}
\fill (0,0) circle [radius=2pt] node (A) [label=A] {};
\fill (2,1) circle [radius=2pt] node (B) [label=B] {};
\fill (3.2,1) circle [radius=2pt] node (C) [label=C] {};
\fill (4,0.5) circle [radius=2pt] node (D) [label=D] {};
\draw [name path=AB] (A) -- ($(B)!-1cm!(A)$);
\draw [name path=CD] (D) -- ($(C)!-1cm!(D)$);

\fill [red,name intersections={of={AB and CD}}] (intersection-1) circle [radius=2pt];
\end{tikzpicture}
\end{document}
4

If you use tkz-euclide (documentation only in French, though), this is much easier:

\documentclass{article}

\usepackage{tkz-euclide}

\begin{document}
\begin{tikzpicture}

\tkzDefPoint(0,0){A} \tkzDefPoint(2,1){B}
\tkzDefPoint(3.2,1){C} \tkzDefPoint(4,0.5){D}

\tkzInterLL(A,B)(C,D) \tkzGetPoint{I}
\tkzDrawLines(A,I D,I)
\tkzDrawPoints[color=blue](A,B,C,D) \tkzDrawPoint[color=red](I)
\tkzLabelPoints[above](I,A,B,C,D)

\end{tikzpicture}
\end{document}

You could also write a piece of code to check the coordinates and automate the choice points for the \tkzDrawLines command and then use arbitrary coordinates, if you need, but I was too lazy to do it. :)

3

Consider this a side-answer to the original question, since the solution is provided using pstricks.

pstricks-add provides this point of intersection by means of the macro \psIntersectionPoint(<P0>)(<P1>)(<P2>)(<P3>){<node name>} where P0 and P1 define one straight line (say 0-1) and P2 and P3 define another straight line (say 2-3). <node name> is the name of the saved node at the intersection of 0-1 and 2-3. The following example is taken directly from the pstricks-add package documentation:

\documentclass{article}
\usepackage{pstricks-add}% http://ctan.org/pkg/pstricks-add}
\begin{document}
\psset{unit=0.5cm}
\begin{pspicture}(-5,-4)(5,5)
  \psaxes[labelFontSize=\scriptstyle,
    dx=2,Dx=2,dy=2,Dy=2]{->}(0,0)(-5,-4)(5,5)
  \psline[linecolor=red,linewidth=2pt](-5,-1)(5,5)
  \psline[linecolor=blue,linewidth=2pt](-5,3)(5,-4)
  \qdisk(-5,-1){2pt}\uput[-90](-5,-1){A}
  \qdisk(5,5){2pt}\uput[-90](5,5){B}
  \qdisk(-5,3){2pt}\uput[-90](-5,3){C}
  \qdisk(5,-4){2pt}\uput[-90](5,-4){D}
  \psIntersectionPoint(-5,-1)(5,5)(-5,3)(5,-4){IP}
  \qdisk(IP){3pt}\uput{0.3}[90](IP){IP}
  \psline[linestyle=dashed](IP|0,0)(IP)(0,0|IP)
\end{pspicture}
\end{document}

Intersection between two lines in 2D using PStricks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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