8

Is it possible to draw a line upto a curve. Something like extend...

I do not know to get the pont on the curve to stop the line.

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
%
\begin{tikzpicture}
%grid
\draw [step=1.0,thin,gray!40]  
      (0,0) grid (6,5);
\coordinate (C) at (1.5,1.5);
\coordinate (D) at (1.2,3);
\fill[blue] (C) circle (2pt);
\fill[blue] (D) circle (2pt);
\draw (C)--(D);
\draw [red,thick](C)--++(3,0);
\draw [blue,thick](D)--++(3,0);
%
\coordinate (A2) at (5,1);
\coordinate (B2) at (3.0,4);
%
\draw (A2) to [bend left=20] (B2);
%
\end{tikzpicture}
%
\end{document} 

enter image description here

Red and blue lines must stop exactly on the curve.

sandu
  • 7,950

1 Answers1

11

You can use the intersections library for this, as Dylan suggested.

First, you'll need to name the paths you want to find the intersections for, using name path=<name>. Then you can find the intersections within a draw command using name intersections={of=<first path> and <second path>}. By default, they'll be named intersection-<number>.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
%
\begin{tikzpicture}
%grid
\draw [step=1.0,thin,gray!40]  
      (0,0) grid (6,5);
\coordinate (C) at (1.5,1.5);
\coordinate (D) at (1.2,3);
\fill[blue] (C) circle (2pt);
\fill[blue] (D) circle (2pt);
\draw (C)--(D);
%
\coordinate (A2) at (5,1);
\coordinate (B2) at (3.0,4);
%
\draw [name path=curve] (A2) to [bend left=20] (B2);
\path [name path=lineA](C)--++(3,0);
\path [name path=lineB](D)--++(3,0);
\draw [name intersections={of=curve and lineA}, red, thick] (C) -- (intersection-1);
\draw [name intersections={of=curve and lineB}, blue, thick] (D) -- (intersection-1);
%
\end{tikzpicture}
%
\end{document} 
Jake
  • 232,450
  • Is it possible to name the intersection point as A or B etc... so that this point can be used in another places. – sandu Jun 02 '12 at 08:01
  • Yes. Just add a node afterwards, such as ... (intersection-1) node (E) {};. Then try \draw (C) -- (E);. – GregH Jun 02 '12 at 10:53
  • @sandu: It's better to use coordinate instead of node, because even empty nodes take up some space, which will cause trouble when you try to use them later on. – Jake Jun 02 '12 at 20:19