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


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

\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];

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




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


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. :)


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:

\usepackage{pstricks-add}% http://ctan.org/pkg/pstricks-add}

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.